微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

类型错误:函数缺少 1 个必需的位置参数:'p_str'Python3

如何解决类型错误:函数缺少 1 个必需的位置参数:'p_str'Python3

我试图修改别人写的代码
原本是用python2写的,但我想改成python3
我无法克服错误。我在这里做错了什么?

错误信息:

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,**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,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],kwargs)
  File "/vagrant/odoo/odoo/api.py",line 396,in call_kw
    result = _call_kw_multi(method,model,line 383,in _call_kw_multi
    result = method(recs,**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,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,'L1','L2','N','G',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,end_date)

            self._hrs8010_b(trn_ym,end_date)

            self.env.cr.commit()

            self.env.invalidate_all()

    _logger.info("=== trn_hrs_instransitf end ===")

我为此苦苦挣扎了一段时间。任何形式的帮助将不胜感激!
如何修复该功能?请给我一些建议。谢谢!

解决方法

您似乎没有为参数声明任何默认类型。

更改自

定义 trn_hrs_instransitf(self,p_str):

def trn_hrs_instransitf(self,p_str=None):

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。