From 4b5f0a54a23d2f8483a20208798479f3f11df854 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Mon, 26 Oct 2015 11:45:30 +0100 Subject: [PATCH] Remove useless 'model_id' on changeset rules --- .../models/changeset_field_rule.py | 23 +++++++++++-------- .../tests/test_changeset_field_rule.py | 7 ------ .../tests/test_changeset_field_type.py | 2 -- .../tests/test_changeset_flow.py | 4 ---- .../tests/test_changeset_origin.py | 2 -- .../views/changeset_field_rule_views.xml | 7 ++---- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/partner_changeset/models/changeset_field_rule.py b/partner_changeset/models/changeset_field_rule.py index 2a29ff975..479068cc0 100644 --- a/partner_changeset/models/changeset_field_rule.py +++ b/partner_changeset/models/changeset_field_rule.py @@ -28,13 +28,17 @@ class ChangesetFieldRule(models.Model): _description = 'Changeset Field Rules' _rec_name = 'field_id' - model_id = fields.Many2one(comodel_name='ir.model', - string='Model', - ondelete='cascade', - default=lambda self: self._default_model_id()) - field_id = fields.Many2one(comodel_name='ir.model.fields', - string='Field', - ondelete='cascade') + field_id = fields.Many2one( + comodel_name='ir.model.fields', + string='Field', + domain="[('model_id.model', '=', 'res.partner'), " + " ('ttype', 'in', ('char', 'selection', 'date', 'datetime', " + " 'float', 'integer', 'text', 'boolean', " + " 'many2one')), " + " ('readonly', '=', False)]", + ondelete='cascade', + required=True, + ) action = fields.Selection( selection='_selection_action', string='Action', @@ -59,7 +63,7 @@ class ChangesetFieldRule(models.Model): _sql_constraints = [ ('model_field_uniq', - 'unique (model_id, source_model_id, field_id)', + 'unique (source_model_id, field_id)', 'A rule already exists for this field.'), ] @@ -103,8 +107,7 @@ class ChangesetFieldRule(models.Model): """ model_rules = self.search( - [('model_id', '=', model_name), - '|', ('source_model_id.model', '=', source_model_name), + ['|', ('source_model_id.model', '=', source_model_name), ('source_model_id', '=', False)], # using 'ASC' means that 'NULLS LAST' is the default order='source_model_id ASC', diff --git a/partner_changeset/tests/test_changeset_field_rule.py b/partner_changeset/tests/test_changeset_field_rule.py index 2054396b9..3cc3e70c8 100644 --- a/partner_changeset/tests/test_changeset_field_rule.py +++ b/partner_changeset/tests/test_changeset_field_rule.py @@ -26,7 +26,6 @@ class TestChangesetFieldRule(common.TransactionCase): def setUp(self): super(TestChangesetFieldRule, self).setUp() - self.partner_model_id = self.env.ref('base.model_res_partner').id self.company_model_id = self.env.ref('base.model_res_company').id self.field_name = self.env.ref('base.field_res_partner_name') self.field_street = self.env.ref('base.field_res_partner_street') @@ -35,12 +34,10 @@ class TestChangesetFieldRule(common.TransactionCase): ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule.search([]).unlink() rule1 = ChangesetFieldRule.create({ - 'model_id': self.partner_model_id, 'field_id': self.field_name.id, 'action': 'validate', }) rule2 = ChangesetFieldRule.create({ - 'model_id': self.partner_model_id, 'field_id': self.field_street.id, 'action': 'never', }) @@ -51,17 +48,14 @@ class TestChangesetFieldRule(common.TransactionCase): ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule.search([]).unlink() rule1 = ChangesetFieldRule.create({ - 'model_id': self.partner_model_id, 'field_id': self.field_name.id, 'action': 'validate', }) rule2 = ChangesetFieldRule.create({ - 'model_id': self.partner_model_id, 'field_id': self.field_street.id, 'action': 'never', }) rule3 = ChangesetFieldRule.create({ - 'model_id': self.partner_model_id, 'source_model_id': self.company_model_id, 'field_id': self.field_street.id, 'action': 'never', @@ -76,7 +70,6 @@ class TestChangesetFieldRule(common.TransactionCase): ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule.search([]).unlink() rule = ChangesetFieldRule.create({ - 'model_id': self.partner_model_id, 'field_id': self.field_name.id, 'action': 'validate', }) diff --git a/partner_changeset/tests/test_changeset_field_type.py b/partner_changeset/tests/test_changeset_field_type.py index a75adf190..52b4821dc 100644 --- a/partner_changeset/tests/test_changeset_field_type.py +++ b/partner_changeset/tests/test_changeset_field_type.py @@ -28,7 +28,6 @@ class TestChangesetFieldType(ChangesetMixin, common.TransactionCase): def _setup_rules(self): ChangesetFieldRule = self.env['changeset.field.rule'] - partner_model_id = self.env.ref('base.model_res_partner').id ChangesetFieldRule.search([]).unlink() fields = (('char', 'ref'), ('text', 'comment'), @@ -52,7 +51,6 @@ class TestChangesetFieldType(ChangesetMixin, common.TransactionCase): # ir.model.fields record of the field res_partner.ref setattr(self, attr_name, field_record) ChangesetFieldRule.create({ - 'model_id': partner_model_id, 'field_id': field_record.id, 'action': 'validate', }) diff --git a/partner_changeset/tests/test_changeset_flow.py b/partner_changeset/tests/test_changeset_flow.py index 950de183f..f97c0b130 100644 --- a/partner_changeset/tests/test_changeset_flow.py +++ b/partner_changeset/tests/test_changeset_flow.py @@ -46,22 +46,18 @@ class TestChangesetFlow(ChangesetMixin, common.TransactionCase): def _setup_rules(self): ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule.search([]).unlink() - partner_model_id = self.env.ref('base.model_res_partner').id self.field_name = self.env.ref('base.field_res_partner_name') self.field_street = self.env.ref('base.field_res_partner_street') self.field_street2 = self.env.ref('base.field_res_partner_street2') ChangesetFieldRule.create({ - 'model_id': partner_model_id, 'field_id': self.field_name.id, 'action': 'auto', }) ChangesetFieldRule.create({ - 'model_id': partner_model_id, 'field_id': self.field_street.id, 'action': 'validate', }) ChangesetFieldRule.create({ - 'model_id': partner_model_id, 'field_id': self.field_street2.id, 'action': 'never', }) diff --git a/partner_changeset/tests/test_changeset_origin.py b/partner_changeset/tests/test_changeset_origin.py index a29329b56..a6841a43d 100644 --- a/partner_changeset/tests/test_changeset_origin.py +++ b/partner_changeset/tests/test_changeset_origin.py @@ -35,10 +35,8 @@ class TestChangesetOrigin(ChangesetMixin, common.TransactionCase): def _setup_rules(self): ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule.search([]).unlink() - partner_model_id = self.env.ref('base.model_res_partner').id self.field_name = self.env.ref('base.field_res_partner_name') ChangesetFieldRule.create({ - 'model_id': partner_model_id, 'field_id': self.field_name.id, 'action': 'validate', }) diff --git a/partner_changeset/views/changeset_field_rule_views.xml b/partner_changeset/views/changeset_field_rule_views.xml index e357890e2..b55333a7b 100644 --- a/partner_changeset/views/changeset_field_rule_views.xml +++ b/partner_changeset/views/changeset_field_rule_views.xml @@ -20,15 +20,12 @@
- + /> + -