One2many field on_change function can't change its own value?

会有一股神秘感。 提交于 2019-12-03 22:28:05

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

In other words, just comment the lines 5900 to 5902 of the openerp/models.py file.

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.

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...

I created a Pull Request to odoo version 8

https://github.com/odoo/odoo/issues/2693

with the changes mentioned in the issues and here

    if field_name and not isinstance(field_name, list) and \
-                self._fields[field_name].type in ('one2many', 'many2many'):
+        if field_name and not isinstance(field_name, list):
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!