编辑销售订单并保存时,贷方和借方字段出现非类型错误。我怎样才能解决它
@api.model
def create(self,vals):
logging.info("create Mehtod+++++++++++++++++++++")
logging.info(type(vals.get('credit')))
if vals.get('credit') < vals.get('debit'):
vals['check'] = True
logging.info("Create fisrt++++++++++++++++")
else:
vals['check'] = False
logging.info("Create second++++++++++++++")
return super(sale_credit, self).create(vals)
def write(self,vals):
logging.info("Write Mehtod+++++++++++++++++++++++")
# logging.info(vals['debit'])
logging.info(type(vals.get('credit')))
logging.info(vals)
if vals['credit'] >= vals['debit']:
logging.info("FIrst write+++++++++++++")
vals['check'] = False
else:
vals['check'] = True
return super(sale_credit, self).write(vals)
我得到了以下错误日志:
File "/home/akkl/odoo13_ENTERPRISE/odoo13_5555/odoo13_5555-server/addons/web/controllers/main.py", line 1314, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/akkl/odoo13_ENTERPRISE/odoo13_5555/odoo13_5555-server/odoo/api.py", line 387, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/akkl/odoo13_ENTERPRISE/odoo13_5555/odoo13_5555-server/odoo/api.py", line 374, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/akkl/UMG/customer_credit_limit/models/models.py", line 115, in write
if vals['credit'] >= vals['debit']:
KeyError: 'credit'
如果vals是一个字典,当没有键为'credit'的元素时,vals.get('credit')返回None
您应该检查vals.get('credit')在“如果vals['credit']>;=vals['debit']:之前是否不是None”
相关问题 更多 >
编程相关推荐