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:
View:
Update domain in view without using onchange