Browse Source

[FIX] Add missing constrains on category_id in res_partner.id_number

The number must be validated also when we change the category
pull/255/head
Laurent Mignon (ACSONE) 9 years ago
parent
commit
beb2a3813a
  1. 2
      partner_identification/models/res_partner_id_number.py
  2. 42
      partner_identification/tests/test_partner_identification.py

2
partner_identification/models/res_partner_id_number.py

@ -16,7 +16,7 @@ class ResPartnerIdNumber(models.Model):
_name = "res.partner.id_number"
_order = "name"
@api.constrains('name')
@api.constrains('name', 'category_id')
def validate_id_number(self):
self.category_id.validate_id_number(self)

42
partner_identification/tests/test_partner_identification.py

@ -21,13 +21,13 @@ class TestPartnerIdentificationBase(common.TransactionCase):
partner_1 = self.env.ref('base.res_partner_1')
self.assertEquals(len(partner_1.id_numbers), 0)
with self.assertRaises(IntegrityError), self.cr.savepoint():
partner_1.id_numbers = [(0, 0, {
partner_1.write({'id_numbers': [(0, 0, {
'name': '1234',
})]
partner_1.id_numbers = [(0, 0, {
})]})
partner_1.write({'id_numbers': [(0, 0, {
'name': '1234',
'category_id': partner_id_category
})]
'category_id': partner_id_category.id
})]})
self.assertEquals(len(partner_1.id_numbers), 1)
self.assertEquals(partner_1.id_numbers.name, '1234')
@ -45,17 +45,31 @@ if id_number.name != '1234':
})
partner_1 = self.env.ref('base.res_partner_1')
with self.assertRaises(ValidationError), self.cr.savepoint():
partner_1.id_numbers = [(0, 0, {
partner_1.write({'id_numbers': [(0, 0, {
'name': '01234',
'category_id': partner_id_category
})]
partner_1.id_numbers = [(0, 0, {
'category_id': partner_id_category.id
})]})
partner_1.write({'id_numbers': [(0, 0, {
'name': '1234',
'category_id': partner_id_category
})]
'category_id': partner_id_category.id
})]})
self.assertEquals(len(partner_1.id_numbers), 1)
self.assertEquals(partner_1.id_numbers.name, '1234')
partner_id_category2 = self.env['res.partner.id_category'].create({
'code': 'id_code2',
'name': 'id_name2',
'validation_code': """
if id_number.name != '1235':
failed = True
"""})
# check that the constrains is also checked when we change the
# associated category
with self.assertRaises(ValidationError), self.cr.savepoint():
partner_1.id_numbers.write({
'category_id': partner_id_category2.id
})
def test_bad_calidation_code(self):
partner_id_category = self.env['res.partner.id_category'].create({
'code': 'id_code',
@ -67,7 +81,7 @@ if id_number.name != '1234' # missing :
})
partner_1 = self.env.ref('base.res_partner_1')
with self.assertRaises(ValidationError):
partner_1.id_numbers = [(0, 0, {
partner_1.write({'id_numbers': [(0, 0, {
'name': '1234',
'category_id': partner_id_category
})]
'category_id': partner_id_category.id
})]})
Loading…
Cancel
Save