写入方法中的Get字段名称在odoo中出错



当我编辑销售订单并保存它时,贷方和借方字段得到一个none类型的错误。我该如何解决?

Python代码:

@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'

首先,这不是NoneType错误,而是KeyError,这意味着使用的密钥'credit'不在字典vals中。在奥多奥的写作方法中,这意味着这个领域没有改变。

计算check不是更容易吗?

# store=True if you want to let users search on the field
check = fields.Boolean(compute="_compute_check")  
@api.depends('debit', 'credit')
def _compute_check(self):
for record in self:
if record.credit >= record.debit:
record.check = False
else:
record.check = True

相关内容

  • 没有找到相关文章

最新更新