From 8ff2ee2418a4cb1cbb8e1d2df82c6614f5b5d230 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 20 Nov 2015 13:18:46 +0100 Subject: [PATCH] Remove reference to the model_name on rules Because the model has been removed earlier (dead code) --- .../models/changeset_field_rule.py | 12 ++++-------- .../models/res_partner_changeset.py | 1 - .../tests/test_changeset_field_rule.py | 18 +++++++++--------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/partner_changeset/models/changeset_field_rule.py b/partner_changeset/models/changeset_field_rule.py index 479068cc0..6374a857a 100644 --- a/partner_changeset/models/changeset_field_rule.py +++ b/partner_changeset/models/changeset_field_rule.py @@ -82,10 +82,6 @@ class ChangesetFieldRule(models.Model): """ return self.env.ref('base.model_res_users') - @api.model - def _default_model_id(self): - return self.env.ref('base.model_res_partner').id - @api.model def _selection_action(self): return [('auto', 'Auto'), @@ -93,9 +89,9 @@ class ChangesetFieldRule(models.Model): ('never', 'Never'), ] - @ormcache() + @ormcache(skiparg=1) @api.model - def _get_rules(self, model_name, source_model_name): + def _get_rules(self, source_model_name): """ Cache rules Keep only the id of the rules, because if we keep the recordsets @@ -124,7 +120,7 @@ class ChangesetFieldRule(models.Model): return result @api.model - def get_rules(self, model_name, source_model_name): + def get_rules(self, source_model_name): """ Return the rules for a model When a model is specified, it will return the rules for this @@ -141,7 +137,7 @@ class ChangesetFieldRule(models.Model): they want only global rules. """ rules = {} - cached_rules = self._get_rules(model_name, source_model_name) + cached_rules = self._get_rules(source_model_name) for field, rule_id in cached_rules.iteritems(): rules[field] = self.browse(rule_id) return rules diff --git a/partner_changeset/models/res_partner_changeset.py b/partner_changeset/models/res_partner_changeset.py index d0d25f4d1..51accfba0 100644 --- a/partner_changeset/models/res_partner_changeset.py +++ b/partner_changeset/models/res_partner_changeset.py @@ -134,7 +134,6 @@ class ResPartnerChangeset(models.Model): write_values = values.copy() changes = [] rules = self.env['changeset.field.rule'].get_rules( - record._model._name, source_model_name=source_model, ) for field in values: diff --git a/partner_changeset/tests/test_changeset_field_rule.py b/partner_changeset/tests/test_changeset_field_rule.py index 3cc3e70c8..b10582a2c 100644 --- a/partner_changeset/tests/test_changeset_field_rule.py +++ b/partner_changeset/tests/test_changeset_field_rule.py @@ -41,7 +41,7 @@ class TestChangesetFieldRule(common.TransactionCase): 'field_id': self.field_street.id, 'action': 'never', }) - get_rules = ChangesetFieldRule.get_rules('res.partner', None) + get_rules = ChangesetFieldRule.get_rules(None) self.assertEqual(get_rules, {'name': rule1, 'street': rule2}) def test_get_rules_source(self): @@ -61,10 +61,10 @@ class TestChangesetFieldRule(common.TransactionCase): 'action': 'never', }) model = ChangesetFieldRule - rules = model.get_rules('res.partner', None) - self.assertEqual(rules, {'name': rule1, 'street': rule2}) - rules = model.get_rules('res.partner', 'res.company') - self.assertEqual(rules, {'name': rule1, 'street': rule3}) + rules = model.get_rules(None) + self.assertEqual(rules, {u'name': rule1, u'street': rule2}) + rules = model.get_rules('res.company') + self.assertEqual(rules, {u'name': rule1, u'street': rule3}) def test_get_rules_cache(self): ChangesetFieldRule = self.env['changeset.field.rule'] @@ -74,7 +74,7 @@ class TestChangesetFieldRule(common.TransactionCase): 'action': 'validate', }) self.assertEqual( - ChangesetFieldRule.get_rules('res.partner', None)['name'].action, + ChangesetFieldRule.get_rules(None)['name'].action, 'validate', ) # Write on cursor to bypass the cache invalidation for the @@ -83,13 +83,13 @@ class TestChangesetFieldRule(common.TransactionCase): "SET action = 'never' " "WHERE id = %s", (rule.id,)) self.assertEqual( - ChangesetFieldRule.get_rules('res.partner', None)['name'].action, + ChangesetFieldRule.get_rules(None)['name'].action, 'validate', ) rule.action = 'auto' self.assertEqual( - ChangesetFieldRule.get_rules('res.partner', None)['name'].action, + ChangesetFieldRule.get_rules(None)['name'].action, 'auto', ) rule.unlink() - self.assertFalse(ChangesetFieldRule.get_rules('res.partner', None)) + self.assertFalse(ChangesetFieldRule.get_rules(None))