Browse Source

[IMP] make posible to call the onchange on an existing record and avoid returning computed value

pull/1253/head
Sébastien BEAU 7 years ago
parent
commit
9ceecee4f1
  1. 9
      onchange_helper/README.rst
  2. 8
      onchange_helper/models/ir_rule.py

9
onchange_helper/README.rst

@ -24,6 +24,15 @@ Example if you want to create a sale order and you want to get the values relati
Then, `vals` will be updated with partner_invoice_id, partner_shipping_id, pricelist_id, etc...
You can also use it on existing record for example:
`vals = {'partner_shipping_id: 1'}`
`vals = sale.play_onchanges(vals, ['partner_shipping_id'])`
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...
Bug Tracker
===========

8
onchange_helper/models/ir_rule.py

@ -17,7 +17,6 @@ def get_new_values(model, record, on_change_result):
new_values[fieldname] = value
return new_values
@api.model
def play_onchanges(self, values, onchange_fields):
onchange_specs = self._onchange_spec()
@ -26,7 +25,10 @@ def play_onchanges(self, values, onchange_fields):
all_values = values.copy()
for field in self._fields:
if field not in all_values:
all_values[field] = False
# If self is a record (play onchange on existing record)
# we take the value of the field
# If self is an empty record we will have an empty value
all_values[field] = self[field]
# we work on a temporary record
new_record = self.new(all_values)
@ -39,7 +41,7 @@ def play_onchanges(self, values, onchange_fields):
all_values.update(new_values)
res = {f: v for f, v in all_values.iteritems()
if f in values or f in new_values}
if not self._fields[f].compute and (f in values or f in new_values)}
return res

Loading…
Cancel
Save