[UPD] - Update documentation

pull/2479/head
sbejaoui 2018-12-19 16:03:13 +01:00 committed by Kevin Khao
parent afbb98f5af
commit 59aa3e02bb
2 changed files with 14 additions and 0 deletions

View File

@ -22,6 +22,14 @@ class Base(models.AbstractModel):
@api.model
def play_onchanges(self, values, onchange_fields):
"""
:param values: dict of input value that
:param onchange_fields: fields for which onchange methods will be
played
Order in onchange_fields is very important as onchanges methods will
be played in that order.
:return: changed values
"""
# _onchange_spec() will return onchange fields from the default view
# we need all fields in the dict even the empty ones
# otherwise 'onchange()' will not apply changes to them

View File

@ -31,3 +31,9 @@ You can also use it on existing record for example:
Then the onchange will be played with the vals passed and the existing vals of the sale. `vals` will be updated with partner_invoice_id, pricelist_id, etc..
Behind the scene, `play_onchanges` will execute **all the methods** registered for the list of changed fields, so you do not have to call manually each onchange. To avoid performance issue when the method is called on a record, the record will be transformed into a memory record before calling the registered methods to avoid to trigger SQL updates command when values are assigned to the record by the onchange
Notes:
- Order in onchange_fields is very important as onchanges methods will be played in that order.
- If you use memory object in `vals`, be award that onchange method in base model call `self.invalidate_cache()` that reset it.