Update domain in view without using onchange

18. Mai 2024 durch
Update domain in view without using onchange
Ivan Sokolov

We've been engaging in numerous code reviews so we decided to share some useful tip which can be useful for other Odoo developers.

As many of you are aware @api.onchange functions that return a domain have been deprecated since Odoo 14. Although these functions continue to operate with a deprecation warning in Odoo 16 it is advisable to use computed fields with readonly=False whenever possible.
However there are scenarios where updating the domain directly in a view remains necessary because alternative methods simply will not do the job.
In such cases you can store domain in a computed binary field. And reference this field in the "domain" attribute within your view.

Below is some example from Odoo 17 source code:

Model:

https://github.com/odoo/odoo/blob/41ccb102c1653a1e49438962b1739b6226789d53/addons/account/models/account_tax.py#L1615

View:

https://github.com/odoo/odoo/blob/41ccb102c1653a1e49438962b1739b6226789d53/addons/account/views/account_tax_views.xml#L47


Diesen Beitrag teilen
Stichwörter