Browse Source

[IMP] use convert to write to pass clean/formated value, add test to check that record have been not modify

pull/1253/head
Sébastien BEAU 7 years ago
parent
commit
9ee929674f
  1. 4
      onchange_helper/README.rst
  2. 2
      onchange_helper/models/models.py
  3. 4
      onchange_helper/tests/test_onchange.py

4
onchange_helper/README.rst

@ -18,7 +18,7 @@ To use this module, you need to:
Example if you want to create a sale order and you want to get the values relative to partner_id field (as if you fill the field from UI)
`vals = {'partner_id: 1'}`
`vals = {'partner_id': 1}`
`vals = self.env['sale.order'].play_onchanges(vals, ['partner_id'])`
@ -26,7 +26,7 @@ Then, `vals` will be updated with partner_invoice_id, partner_shipping_id, price
You can also use it on existing record for example:
`vals = {'partner_shipping_id: 1'}`
`vals = {'partner_shipping_id': 1}`
`vals = sale.play_onchanges(vals, ['partner_shipping_id'])`

2
onchange_helper/models/models.py

@ -32,7 +32,7 @@ class Base(models.AbstractModel):
# If self is an empty record we will have an empty value
if self:
self.ensure_one()
record_values = self.read()[0]
record_values = self._convert_to_write(self.read()[0])
else:
record_values = {}
for field in self._fields:

4
onchange_helper/tests/test_onchange.py

@ -15,10 +15,12 @@ class TestOnchange(common.TransactionCase):
self.assertEqual(result['is_company'], True)
def test_playing_onchange_on_record(self):
result = self.env.ref('base.main_company').play_onchanges({
company = self.env.ref('base.main_company')
result = company.play_onchanges({
'email': 'contact@akretion.com'},
['email'])
self.assertEqual(
result['rml_footer'],
u'Phone: +1 555 123 8069 | Email: contact@akretion.com | '
u'Website: http://www.example.com')
self.assertEqual(company.email, u'info@yourcompany.example.com')
Loading…
Cancel
Save