Browse Source

Remove useless 'model_id' on changeset rules

pull/208/head
Guewen Baconnier 9 years ago
parent
commit
4b5f0a54a2
  1. 21
      partner_changeset/models/changeset_field_rule.py
  2. 7
      partner_changeset/tests/test_changeset_field_rule.py
  3. 2
      partner_changeset/tests/test_changeset_field_type.py
  4. 4
      partner_changeset/tests/test_changeset_flow.py
  5. 2
      partner_changeset/tests/test_changeset_origin.py
  6. 7
      partner_changeset/views/changeset_field_rule_views.xml

21
partner_changeset/models/changeset_field_rule.py

@ -28,13 +28,17 @@ class ChangesetFieldRule(models.Model):
_description = 'Changeset Field Rules' _description = 'Changeset Field Rules'
_rec_name = 'field_id' _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',
field_id = fields.Many2one(
comodel_name='ir.model.fields',
string='Field', string='Field',
ondelete='cascade')
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( action = fields.Selection(
selection='_selection_action', selection='_selection_action',
string='Action', string='Action',
@ -59,7 +63,7 @@ class ChangesetFieldRule(models.Model):
_sql_constraints = [ _sql_constraints = [
('model_field_uniq', ('model_field_uniq',
'unique (model_id, source_model_id, field_id)',
'unique (source_model_id, field_id)',
'A rule already exists for this field.'), 'A rule already exists for this field.'),
] ]
@ -103,8 +107,7 @@ class ChangesetFieldRule(models.Model):
""" """
model_rules = self.search( 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)], ('source_model_id', '=', False)],
# using 'ASC' means that 'NULLS LAST' is the default # using 'ASC' means that 'NULLS LAST' is the default
order='source_model_id ASC', order='source_model_id ASC',

7
partner_changeset/tests/test_changeset_field_rule.py

@ -26,7 +26,6 @@ class TestChangesetFieldRule(common.TransactionCase):
def setUp(self): def setUp(self):
super(TestChangesetFieldRule, self).setUp() 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.company_model_id = self.env.ref('base.model_res_company').id
self.field_name = self.env.ref('base.field_res_partner_name') self.field_name = self.env.ref('base.field_res_partner_name')
self.field_street = self.env.ref('base.field_res_partner_street') 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 = self.env['changeset.field.rule']
ChangesetFieldRule.search([]).unlink() ChangesetFieldRule.search([]).unlink()
rule1 = ChangesetFieldRule.create({ rule1 = ChangesetFieldRule.create({
'model_id': self.partner_model_id,
'field_id': self.field_name.id, 'field_id': self.field_name.id,
'action': 'validate', 'action': 'validate',
}) })
rule2 = ChangesetFieldRule.create({ rule2 = ChangesetFieldRule.create({
'model_id': self.partner_model_id,
'field_id': self.field_street.id, 'field_id': self.field_street.id,
'action': 'never', 'action': 'never',
}) })
@ -51,17 +48,14 @@ class TestChangesetFieldRule(common.TransactionCase):
ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule = self.env['changeset.field.rule']
ChangesetFieldRule.search([]).unlink() ChangesetFieldRule.search([]).unlink()
rule1 = ChangesetFieldRule.create({ rule1 = ChangesetFieldRule.create({
'model_id': self.partner_model_id,
'field_id': self.field_name.id, 'field_id': self.field_name.id,
'action': 'validate', 'action': 'validate',
}) })
rule2 = ChangesetFieldRule.create({ rule2 = ChangesetFieldRule.create({
'model_id': self.partner_model_id,
'field_id': self.field_street.id, 'field_id': self.field_street.id,
'action': 'never', 'action': 'never',
}) })
rule3 = ChangesetFieldRule.create({ rule3 = ChangesetFieldRule.create({
'model_id': self.partner_model_id,
'source_model_id': self.company_model_id, 'source_model_id': self.company_model_id,
'field_id': self.field_street.id, 'field_id': self.field_street.id,
'action': 'never', 'action': 'never',
@ -76,7 +70,6 @@ class TestChangesetFieldRule(common.TransactionCase):
ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule = self.env['changeset.field.rule']
ChangesetFieldRule.search([]).unlink() ChangesetFieldRule.search([]).unlink()
rule = ChangesetFieldRule.create({ rule = ChangesetFieldRule.create({
'model_id': self.partner_model_id,
'field_id': self.field_name.id, 'field_id': self.field_name.id,
'action': 'validate', 'action': 'validate',
}) })

2
partner_changeset/tests/test_changeset_field_type.py

@ -28,7 +28,6 @@ class TestChangesetFieldType(ChangesetMixin, common.TransactionCase):
def _setup_rules(self): def _setup_rules(self):
ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule = self.env['changeset.field.rule']
partner_model_id = self.env.ref('base.model_res_partner').id
ChangesetFieldRule.search([]).unlink() ChangesetFieldRule.search([]).unlink()
fields = (('char', 'ref'), fields = (('char', 'ref'),
('text', 'comment'), ('text', 'comment'),
@ -52,7 +51,6 @@ class TestChangesetFieldType(ChangesetMixin, common.TransactionCase):
# ir.model.fields record of the field res_partner.ref # ir.model.fields record of the field res_partner.ref
setattr(self, attr_name, field_record) setattr(self, attr_name, field_record)
ChangesetFieldRule.create({ ChangesetFieldRule.create({
'model_id': partner_model_id,
'field_id': field_record.id, 'field_id': field_record.id,
'action': 'validate', 'action': 'validate',
}) })

4
partner_changeset/tests/test_changeset_flow.py

@ -46,22 +46,18 @@ class TestChangesetFlow(ChangesetMixin, common.TransactionCase):
def _setup_rules(self): def _setup_rules(self):
ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule = self.env['changeset.field.rule']
ChangesetFieldRule.search([]).unlink() 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_name = self.env.ref('base.field_res_partner_name')
self.field_street = self.env.ref('base.field_res_partner_street') self.field_street = self.env.ref('base.field_res_partner_street')
self.field_street2 = self.env.ref('base.field_res_partner_street2') self.field_street2 = self.env.ref('base.field_res_partner_street2')
ChangesetFieldRule.create({ ChangesetFieldRule.create({
'model_id': partner_model_id,
'field_id': self.field_name.id, 'field_id': self.field_name.id,
'action': 'auto', 'action': 'auto',
}) })
ChangesetFieldRule.create({ ChangesetFieldRule.create({
'model_id': partner_model_id,
'field_id': self.field_street.id, 'field_id': self.field_street.id,
'action': 'validate', 'action': 'validate',
}) })
ChangesetFieldRule.create({ ChangesetFieldRule.create({
'model_id': partner_model_id,
'field_id': self.field_street2.id, 'field_id': self.field_street2.id,
'action': 'never', 'action': 'never',
}) })

2
partner_changeset/tests/test_changeset_origin.py

@ -35,10 +35,8 @@ class TestChangesetOrigin(ChangesetMixin, common.TransactionCase):
def _setup_rules(self): def _setup_rules(self):
ChangesetFieldRule = self.env['changeset.field.rule'] ChangesetFieldRule = self.env['changeset.field.rule']
ChangesetFieldRule.search([]).unlink() 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_name = self.env.ref('base.field_res_partner_name')
ChangesetFieldRule.create({ ChangesetFieldRule.create({
'model_id': partner_model_id,
'field_id': self.field_name.id, 'field_id': self.field_name.id,
'action': 'validate', 'action': 'validate',
}) })

7
partner_changeset/views/changeset_field_rule_views.xml

@ -20,15 +20,12 @@
<form string="Changeset Fields Rules"> <form string="Changeset Fields Rules">
<sheet string="Changeset Fields Rules"> <sheet string="Changeset Fields Rules">
<group> <group>
<field name="model_id" invisible="1"/>
<field name="field_id" <field name="field_id"
options="{'no_create_edit': True, 'no_open': True}" options="{'no_create_edit': True, 'no_open': True}"
domain="[('model_id', '=', model_id),
('ttype', 'in', ('char', 'selection', 'date', 'datetime', 'float', 'integer', 'text', 'boolean', 'many2one')),
('readonly', '=', False)]"/>
/>
<field name="action"/>
<field name="source_model_id" <field name="source_model_id"
options="{'no_create_edit': True, 'no_open': True}"/> options="{'no_create_edit': True, 'no_open': True}"/>
<field name="action"/>
</group> </group>
</sheet> </sheet>
</form> </form>

Loading…
Cancel
Save