Browse Source

[UPD] - Update documentation

pull/1461/head
sbejaoui 6 years ago
parent
commit
cf21042954
  1. 8
      onchange_helper/models/base.py
  2. 6
      onchange_helper/readme/USAGE.rst

8
onchange_helper/models/base.py

@ -22,6 +22,14 @@ class Base(models.AbstractModel):
@api.model @api.model
def play_onchanges(self, values, onchange_fields): 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 # _onchange_spec() will return onchange fields from the default view
# we need all fields in the dict even the empty ones # we need all fields in the dict even the empty ones
# otherwise 'onchange()' will not apply changes to them # otherwise 'onchange()' will not apply changes to them

6
onchange_helper/readme/USAGE.rst

@ -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.. 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 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.
Loading…
Cancel
Save