如何在onchange方法中组合警告消息并更新字段值?在odoo 9

问题描述:

在老版本odoo的(OpenERP的7),我用来做这样的事情:如何在onchange方法中组合警告消息并更新字段值?在odoo 9

@api.multi 
@api.onchange('my_field') 
def my_field_change(self, cr, uid, partner_ids, context=None): 
    if condition is True: 
    return { 
      'warning': {'title': _('Error'), 'message': _('Error message'),}, 
      'value': { 'my_field': new_value }, 
      } 

如果我想这样做,在odoo 9,我有这样的代码:

@api.multi 
@api.onchange('my_field') 
def my_field_change(self): 
    if condition is True: 
    return { 
      'warning': {'title': _('Error'), 'message': _('Error message'),}, 
      'value': { 'my_field': new_value }, 
      } 

显示警告窗口,但值字段被忽略。

如何更改该字段的值?

在odoo Onchange方法中,您不能返回与旧版odoo相同的值。

Onchange方法将只返回警告和域。

@api.multi 
@api.onchange('my_field') 
def my_field_change(self): 
    self.field=value 
    return { 
     'warning': {'title': _('Error'), 'message': _('Error message'),}, 
     } 

在Odoo new api中,不需要在字典中返回值只是在相关字段中赋值。

例:sale.field =值

这可能会帮助你。

+0

就是这样!非常感谢 :) – MouTio