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

时间:2017-04-06 16:04:20

标签: openerp warnings odoo-9

在旧版本的odoo(openerp 7)中,我曾经做过这样的事情:

@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 },
             }

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

如何更改字段的值?

1 个答案:

答案 0 :(得分:2)

In odoo Onchange method, you can't return value same as older version of odoo.

Onchange method will only return Warning and Domain.

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

In Odoo new api no need to return value in dict just assign value in relevant field.

Ex: sale.field=value

This may help you.