2017-04-06 34 views
1

在老版本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 }, 
      } 

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

如何更改該字段的值?

回答

2

在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