Onchange is the most important function for Odoo. The "onchange" mechanism provides a method for the client interface to update a form at the time when the user filled a value in a field, without saving anything to the database.
For example you can see below code.
content of form view
<field name="amount">
<field name="unit_price">
<field name="price" readonly="1">
# onchange handler
@api.onchange('amount', 'unit_price')
def _onchange_price(self):
# set auto-changing field
self.price = self.amount * self.unit_price
# Can optionally return a warning and domains
return {
'warning': {
'title': "Something bad happened",
'message': "It was very bad indeed",
}
}</field></field></field>
Note-An explicit onchange warn about invalid values, like a negative number of seats, or more participants than seats.
0 Comment(s)