TypeError: function missing 1 required positional argument: 'p_str' (Python3)
TypeError: function missing 1 required positional argument: 'p_str' (Python3)
我正在尝试修改别人写的代码。
本来写在python2,但我想把它改成python3。
我无法通过 error.What 我在这里做错了吗?
错误信息:
Odoo Server Error
Traceback (most recent call last):
File "/vagrant/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/vagrant/odoo/odoo/http.py", line 682, in dispatch
result = self._call_function(**self.params)
File "/vagrant/odoo/odoo/http.py", line 358, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/vagrant/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/vagrant/odoo/odoo/http.py", line 346, in checked_call
result = self.endpoint(*a, **kw)
File "/vagrant/odoo/odoo/http.py", line 911, in __call__
return self.method(*args, **kw)
File "/vagrant/odoo/odoo/http.py", line 530, in response_wrap
response = f(*args, **kw)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1363, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1351, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 396, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 383, in _call_kw_multi
result = method(recs, *args, **kwargs)
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/vagrant/odoo/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/vagrant/odoo/odoo/http.py", line 314, in _handle_exception
raise exception.with_traceback(None) from new_cause
TypeError: trn_hrs_instransitf() missing 1 required positional argument: 'p_str'
代码:
class hrs_instransitf_wizard(models.Model):
_name = 'hrs.instransitf.wizard'
@api.model
def _selection_emp_id(self):
list = [(x['emp_id'], x['id_name']) for x in self.env['hrs.idenset'].sudo().search_read([], ['emp_id', 'id_name'])]
return list
trn_ym = fields.Char(string='month', required=True)
emp_id = fields.Selection(selection=_selection_emp_id, string='id')
def trn_hrs_instransitf_Jobtrn_func(self):
_logger.info('trn_hrs_instransitf_Jobtrn_func start...')
p_str = 'JOB'
self.trn_hrs_instransitf(p_str)
_logger.info('trn_hrs_instransitf_Jobtrn_func end...')
def trn_hrs_instransitf(self, p_str):
_logger.info("=== trn_hrs_instransitf start ===")
if p_str == 'JOB':
trn_ym = (date_utils.today() - relativedelta(months=1)).strftime('%Y-%m')
today = datetime.datetime.strptime(trn_ym, '%Y-%m')
print('today', today)
_, last_day_num = calendar.monthrange(today.year, today.month)
print('last_day_num', last_day_num)
start_date = (date_utils.today() - relativedelta(months=1)).strftime('%Y-%m') + '-01'
end_date = (date_utils.today() - relativedelta(months=1)).strftime('%Y-%m') + '-' + str(last_day_num)
else:
trn_ym = self.trn_ym
today = datetime.datetime.strptime(self.trn_ym, '%Y-%m')
print('today', today)
_, last_day_num = calendar.monthrange(today.year, today.month)
print('last_day_num', last_day_num)
start_date = datetime.datetime.strftime(today, '%Y-%m-%d')
end_date = str(datetime.datetime.strftime(today, '%Y-%m')) + '-' + str(last_day_num)
print('start_date', start_date)
print('end_date', end_date)
if self.emp_id:
sqlstr1 = "delete from hrs_othersal where sys_code='HRS_INS' and sal_ym='%s' and emp_id = '%s'" % (self.trn_ym, self.emp_id)
self.env.cr.execute(sqlstr1)
sqlstr2 = "delete from hrs_payins where sal_ym='%s' and emp_id = '%s'" % (self.trn_ym, self.emp_id)
self.env.cr.execute(sqlstr2)
self._hrs8010_b(self.trn_ym, self.emp_id, 'L', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'L1', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'L2', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'N', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'G', start_date, end_date)
else:
idenset_recs = self.env['hrs.idenset'].search([('active', '=', True), ('emp_id', '!=', '05')])
print('idenset_recs:', idenset_recs)
for idenset in idenset_recs:
sqlstr1 = "delete from hrs_othersal where sys_code='HRS_INS' and sal_ym='%s' and emp_id = '%s'" % (trn_ym, idenset.emp_id)
self.env.cr.execute(sqlstr1)
sqlstr2 = "delete from hrs_payins where sal_ym='%s' and emp_id = '%s'" % (trn_ym, idenset.emp_id)
self.env.cr.execute(sqlstr2)
self._hrs8010_b(trn_ym, idenset.emp_id, 'L', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'L1', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'L2', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'N', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'G', start_date, end_date)
self.env.cr.commit()
self.env.invalidate_all()
_logger.info("=== trn_hrs_instransitf end ===")
我为此苦苦挣扎了一段时间。任何形式的帮助将不胜感激!
我该如何修复该功能?请给我一些建议。谢谢!
您似乎还没有为参数声明任何默认类型。
变化自
def trn_hrs_instransitf(self, p_str):
至
def trn_hrs_instransitf(self, p_str=None):
我正在尝试修改别人写的代码。
本来写在python2,但我想把它改成python3。
我无法通过 error.What 我在这里做错了吗?
错误信息:
Odoo Server Error
Traceback (most recent call last):
File "/vagrant/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/vagrant/odoo/odoo/http.py", line 682, in dispatch
result = self._call_function(**self.params)
File "/vagrant/odoo/odoo/http.py", line 358, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/vagrant/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/vagrant/odoo/odoo/http.py", line 346, in checked_call
result = self.endpoint(*a, **kw)
File "/vagrant/odoo/odoo/http.py", line 911, in __call__
return self.method(*args, **kw)
File "/vagrant/odoo/odoo/http.py", line 530, in response_wrap
response = f(*args, **kw)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1363, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/vagrant/odoo/addons/web/controllers/main.py", line 1351, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 396, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/vagrant/odoo/odoo/api.py", line 383, in _call_kw_multi
result = method(recs, *args, **kwargs)
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/vagrant/odoo/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/vagrant/odoo/odoo/http.py", line 314, in _handle_exception
raise exception.with_traceback(None) from new_cause
TypeError: trn_hrs_instransitf() missing 1 required positional argument: 'p_str'
代码:
class hrs_instransitf_wizard(models.Model):
_name = 'hrs.instransitf.wizard'
@api.model
def _selection_emp_id(self):
list = [(x['emp_id'], x['id_name']) for x in self.env['hrs.idenset'].sudo().search_read([], ['emp_id', 'id_name'])]
return list
trn_ym = fields.Char(string='month', required=True)
emp_id = fields.Selection(selection=_selection_emp_id, string='id')
def trn_hrs_instransitf_Jobtrn_func(self):
_logger.info('trn_hrs_instransitf_Jobtrn_func start...')
p_str = 'JOB'
self.trn_hrs_instransitf(p_str)
_logger.info('trn_hrs_instransitf_Jobtrn_func end...')
def trn_hrs_instransitf(self, p_str):
_logger.info("=== trn_hrs_instransitf start ===")
if p_str == 'JOB':
trn_ym = (date_utils.today() - relativedelta(months=1)).strftime('%Y-%m')
today = datetime.datetime.strptime(trn_ym, '%Y-%m')
print('today', today)
_, last_day_num = calendar.monthrange(today.year, today.month)
print('last_day_num', last_day_num)
start_date = (date_utils.today() - relativedelta(months=1)).strftime('%Y-%m') + '-01'
end_date = (date_utils.today() - relativedelta(months=1)).strftime('%Y-%m') + '-' + str(last_day_num)
else:
trn_ym = self.trn_ym
today = datetime.datetime.strptime(self.trn_ym, '%Y-%m')
print('today', today)
_, last_day_num = calendar.monthrange(today.year, today.month)
print('last_day_num', last_day_num)
start_date = datetime.datetime.strftime(today, '%Y-%m-%d')
end_date = str(datetime.datetime.strftime(today, '%Y-%m')) + '-' + str(last_day_num)
print('start_date', start_date)
print('end_date', end_date)
if self.emp_id:
sqlstr1 = "delete from hrs_othersal where sys_code='HRS_INS' and sal_ym='%s' and emp_id = '%s'" % (self.trn_ym, self.emp_id)
self.env.cr.execute(sqlstr1)
sqlstr2 = "delete from hrs_payins where sal_ym='%s' and emp_id = '%s'" % (self.trn_ym, self.emp_id)
self.env.cr.execute(sqlstr2)
self._hrs8010_b(self.trn_ym, self.emp_id, 'L', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'L1', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'L2', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'N', start_date, end_date)
self._hrs8010_b(self.trn_ym, self.emp_id, 'G', start_date, end_date)
else:
idenset_recs = self.env['hrs.idenset'].search([('active', '=', True), ('emp_id', '!=', '05')])
print('idenset_recs:', idenset_recs)
for idenset in idenset_recs:
sqlstr1 = "delete from hrs_othersal where sys_code='HRS_INS' and sal_ym='%s' and emp_id = '%s'" % (trn_ym, idenset.emp_id)
self.env.cr.execute(sqlstr1)
sqlstr2 = "delete from hrs_payins where sal_ym='%s' and emp_id = '%s'" % (trn_ym, idenset.emp_id)
self.env.cr.execute(sqlstr2)
self._hrs8010_b(trn_ym, idenset.emp_id, 'L', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'L1', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'L2', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'N', start_date, end_date)
self._hrs8010_b(trn_ym, idenset.emp_id, 'G', start_date, end_date)
self.env.cr.commit()
self.env.invalidate_all()
_logger.info("=== trn_hrs_instransitf end ===")
我为此苦苦挣扎了一段时间。任何形式的帮助将不胜感激!
我该如何修复该功能?请给我一些建议。谢谢!
您似乎还没有为参数声明任何默认类型。
变化自
def trn_hrs_instransitf(self, p_str):
至
def trn_hrs_instransitf(self, p_str=None):