Defining onchange with the compute method
In the last two recipes, we have seen how to define and call the onchange method. We have also seen its limitation, which is that it can be invoked automatically only from the user interface. As a solution to this problem, Odoo v13 introduced a new way to define onchange
behavior. In this recipe, we will see how you can use the compute
method to produce behavior like the onchange
method's.
Getting ready
For this recipe, we will use the my_library
module from the previous recipe. We will replace the onchange
method of library.return.wizard
with the compute method.
How to do it...
Follow these steps to modify the onchange
method with the compute
method:
- Replace
api.onchange
in theonchange_member()
method withcompute
like this:Â Â Â Â @api.depends('borrower_id') Â Â Â Â def onchange_member(self): Â Â Â Â Â Â Â Â ...
- Add the
compute
parameter...