diff --git a/onchange_helper/models/base.py b/onchange_helper/models/base.py index 8386567f6..f137355ee 100644 --- a/onchange_helper/models/base.py +++ b/onchange_helper/models/base.py @@ -12,7 +12,7 @@ class Base(models.AbstractModel): def _get_new_values(self, record, on_change_result): vals = on_change_result.get('value', {}) new_values = {} - for fieldname, value in vals.iteritems(): + for fieldname, value in vals.items(): if fieldname not in record: column = self._fields[fieldname] if value and column.type == 'many2one': @@ -25,10 +25,6 @@ class Base(models.AbstractModel): # we need all fields in the dict even the empty ones # otherwise 'onchange()' will not apply changes to them 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 @@ -48,6 +44,8 @@ class Base(models.AbstractModel): all_values.update(new_values) return { - f: v for f, v in all_values.iteritems() + f: v for f, v in all_values.items() if not self._fields[f].compute - and (f in values or f in new_values)} + and (f in values or f in new_values)} + + diff --git a/onchange_helper/tests/__init__.py b/onchange_helper/tests/__init__.py index 806c1a0d6..6bcec9ff9 100644 --- a/onchange_helper/tests/__init__.py +++ b/onchange_helper/tests/__init__.py @@ -1,3 +1,2 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - from . import test_onchange_helper diff --git a/onchange_helper/tests/test_onchange_helper.py b/onchange_helper/tests/test_onchange_helper.py index adcff2c1a..86c6fdb88 100644 --- a/onchange_helper/tests/test_onchange_helper.py +++ b/onchange_helper/tests/test_onchange_helper.py @@ -1,28 +1,13 @@ # Copyright 2017 Onestein () # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo.tests.common import TransactionCase +#from odoo.tests.common import TransactionCase +import odoo.tests.common as common +class TestOnchangeHelper(common.TransactionCase): -class TestOnchangeHelper(TransactionCase): - - def test01_partner_parent(self): - main_partner = self.env.ref('base.main_partner') - input_vals = dict(partner_id=main_partner.id) - updated_vals = self.env['res.partner'].play_onchanges( - input_vals, - ['parent_id'] - ) - self.assertIn('commercial_partner_id', updated_vals) - self.assertIn('display_name', updated_vals) - self.assertIn('partner_id', updated_vals) - - def test02_partner_country(self): - partner_demo = self.env.ref('base.partner_demo') - input_vals = {'partner_id': partner_demo.id} - updated_vals = self.env['res.partner'].play_onchanges( - input_vals, - ['country_id'] - ) - self.assertIn('contact_address', updated_vals) - self.assertIn('partner_id', updated_vals) + def test_playing_onchange_on_model(self): + result = self.env['res.partner'].play_onchanges({ + 'company_type': 'company', + }, ['company_type']) + self.assertEqual(result['is_company'], True)