【发布时间】:2021-01-08 20:27:23
【问题描述】:
我继承了一些模型。我还需要重写它的 write 方法。
我试过了:
@api.multi
def write(self, vals, context=None):
res = super(WebSiteSupportTicket, self).write(vals)
date = datetime.datetime.now()
if vals['state_id']:
if vals['state_id'] == 7 or vals['state_id'] == 8:
vals['closing_date'] = date
print(vals)
return res
其中 closure_date 是一个日期时间字段。
当我将 state_id 更改为 id 7 或 8 的状态时,closing_date 仍然为空。但我知道代码正在通过 if 语句,因为我可以在 vals
的打印上看到 closure_date我第一次遇到 write 方法的问题。为什么会发生,我该如何解决?
【问题讨论】: