odoo / odoo

Odoo. Open Source Apps To Grow Your Business.
https://www.odoo.com
Other
37.54k stars 24.42k forks source link

Computed-writable fields as onchange replacement not working on many2many fields within one2many fields #45325

Open fdegrave opened 4 years ago

fdegrave commented 4 years ago

Impacted versions: 13.0

Steps to reproduce: 1) Choose any Many2many field used within a One2many list with an onchange on it (e.g. tax_ids on account move lines -- probably more simple examples exist); 2) Transform it such that you don't use "onchange" anymore, but the new "computed-writable" field (computed field with store=True and readonly=False) ; 3) Break the execution within the computation method to inspect the instance.

Current behavior: The "onchange" event is triggered, but the Many2many field of the instance under concern is empty when executing the computation method. In fact a quick inspection from the browser shows that the JS client does not include the value of this field within the JSON data sent to the backend (the key is there, but no value). Note that the data is saved when saving the record, however.

Expected behavior: Same as the good ol' "onchange": many2many data is sent to the backend and can be used in the method.

pedrobaeza commented 4 years ago

Please exercise the problem with a piece of code of what you are doing and what do you expect, as this treated as generic problem is not easy to be handled.

fdegrave commented 4 years ago

foo.zip

You will find attached a module with a minimal example to show to issue (no ir_model_access btw, you need to become superuser to test it). The "foo" object has two one2many fields: line_ids and line_bis_ids. The first one uses "new style" onchange (computed writable fields) and the second uses a good old onchange. In both cases, the "onchange" method does not do anything but printing in the console the value of "tag_ids".

As you can see, if you add tags to a line of the first field, the computed method is not even triggered (I have a more complex example in which it is triggered but with empty values, that I can't reproduce here). In the second field, if you do the same thing the onchange is triggered and the data is complete.

pedrobaeza commented 4 years ago

Thanks for the file. Tagged for Odoo's analysis.