Python 为什么Odoo中的write()方法没有设置值?

Python 为什么Odoo中的write()方法没有设置值?,python,odoo,odoo-12,Python,Odoo,Odoo 12,我继承了一些模式。我还需要重写它的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_i

我继承了一些模式。我还需要重写它的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
其中,closing_date是一个日期时间字段

当我将state_id更改为id为7或8的状态时,closing_date仍然为null。但我知道代码正在通过if语句传递,因为我可以在VAL的打印上看到截止日期


我第一次遇到写方法的问题。为什么会发生这种情况以及如何获得解决方案?

在调用
super
后,您将
结束日期添加到dict值中,将不会写入
结束日期

从函数定义中删除
上下文
参数(不需要)。您可以在account模块中找到一个覆盖invoice方法的示例

示例

@api.multi
def write(self, values):
    # Define the closing_date in values before calling super
     if 'state_id' in values and values['state_id'] in (7, 8) :
         values['closing_date'] = datetime.datetime.now()
    return super(WebSiteSupportTicket, self).write(values)