One2many字段的on_change函数不能更改其自身的值吗? [英] One2many field on_change function can't change its own value?
问题描述
我有这两个字段.
'name' : fields.char('Name'),
'addresses' : fields.one2many('res.partner.address', 'partner','Addresses'),
此功能:
def addresses_change(self, cr, uid, ids, name, addresses, context=None):
value = {}
new_addresses = []
address_pool = self.pool.get('res.partner.address')
for address in address_pool.browse(cr, uid, addresses[0][2], context=context):
new_addresses.append((1,address.id,{'street':'wall street','zip':'7777','partner': ids[0],'active':True}))
value.update(name='whatever')
value.update(addresses=new_addresses)
return {'value':value}
这些视图字段:
<field name="name" on_change="addresses_change(name,addresses)"/>
<field name="addresses" on_change="addresses_change(name,addresses)"/>
现在,当我更改name
时,name
和addresses
均被更新.但是,当我更改addresses
时,它自己的值不会更新,而name
会更新.因此,这种奇怪的行为仅影响one2many
字段.为什么会这样?
Now when I change name
, both name
and addresses
are updated. But when I change addresses
its own value isn't updated but the name
is updated. So this bizarre behavior affects only one2many
fields. Why is this?
如何将on_change
事件添加到可以更新其自身值的one2many
字段?
And how do I add on_change
event to one2many
fields that can update its own value?
我发现这可能是odoo的局限性,他们是否已解决此问题? 链接到该问题
I found out that this is might be a limitation in odoo, have they fixed this issue? Link to the issue
推荐答案
在models.py的最新版本上应用以下补丁(该版本于2015年8月4日星期二15:22:33 +0200提交):
Apply the following patch on the lastest version of models.py (the version commited on Tue Aug 4 15:22:33 2015 +0200):
--- a/openerp/models.py
+++ b/openerp/models.py
@@ -5897,9 +5897,9 @@ class BaseModel(object):
# At the moment, the client does not support updates on a *2many field
# while this one is modified by the user.
- if field_name and not isinstance(field_name, list) and \
- self._fields[field_name].type in ('one2many', 'many2many'):
- result['value'].pop(field_name, None)
+ ## if field_name and not isinstance(field_name, list) and \
+ ## self._fields[field_name].type in ('one2many', 'many2many'):
+ ## result['value'].pop(field_name, None)
return result
换句话说,只需注释openerp/models.py
文件的5900到5902行.
In other words, just comment the lines 5900 to 5902 of the openerp/models.py
file.
当然,此解决方案有一个很大的缺点-每次在您使用的Odoo发行版中更新models.py
文件时,都需要应用补丁.
Of course, there is a big disadvantage with this solution - you need to apply the patch every time the models.py
file is updated in the Odoo distribution you use.
也存在相当大的风险-他们说Web客户端不能很好地处理onchange事件中更新的one2many和many2many字段.我现在没有发现任何问题,但是我将继续测试我的Odoo开发安装...
There is a considerable risk too - they say that the Web client is not dealing well with one2many and many2many fields updated in onchange event. I did not discover any problem with that right now but I'll continue to test my development installation of Odoo...
这篇关于One2many字段的on_change函数不能更改其自身的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!