Browse Source

Remove useless 'model_id' on changeset rules

pull/208/head
Guewen Baconnier 9 years ago
parent
commit
4b5f0a54a2
  1. 23
      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

23
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',

7
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',
})

2
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',
})

4
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',
})

2
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',
})

7
partner_changeset/views/changeset_field_rule_views.xml

@ -20,15 +20,12 @@
<form string="Changeset Fields Rules">
<sheet string="Changeset Fields Rules">
<group>
<field name="model_id" invisible="1"/>
<field name="field_id"
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"
options="{'no_create_edit': True, 'no_open': True}"/>
<field name="action"/>
</group>
</sheet>
</form>

Loading…
Cancel
Save