Browse Source

[FIX] partner_identification: prevent integrity error on delete ID

pull/644/head
Laurent Mignon 9 years ago
committed by tarteo
parent
commit
be85b7c10b
  1. 3
      partner_identification/models/res_partner_id_number.py
  2. 5
      partner_identification/tests/test_partner_identification.py

3
partner_identification/models/res_partner_id_number.py

@ -29,7 +29,8 @@ class ResPartnerIdNumber(models.Model):
comodel_name='res.partner.id_category', comodel_name='res.partner.id_category',
help="ID type defined in configuration. For example, Driver License") help="ID type defined in configuration. For example, Driver License")
partner_id = fields.Many2one(string="Partner", required=True, partner_id = fields.Many2one(string="Partner", required=True,
comodel_name='res.partner')
comodel_name='res.partner',
ondelete='cascade')
partner_issued_id = fields.Many2one( partner_issued_id = fields.Many2one(
string="Issued by", comodel_name='res.partner', string="Issued by", comodel_name='res.partner',
help="Another partner, who issued this ID. For example, Traffic " help="Another partner, who issued this ID. For example, Traffic "

5
partner_identification/tests/test_partner_identification.py

@ -20,16 +20,21 @@ class TestPartnerIdentificationBase(common.TransactionCase):
partner_1 = self.env.ref('base.res_partner_1') partner_1 = self.env.ref('base.res_partner_1')
self.assertEquals(len(partner_1.id_numbers), 0) self.assertEquals(len(partner_1.id_numbers), 0)
# create without required category
with self.assertRaises(IntegrityError), self.cr.savepoint(): with self.assertRaises(IntegrityError), self.cr.savepoint():
partner_1.write({'id_numbers': [(0, 0, { partner_1.write({'id_numbers': [(0, 0, {
'name': '1234', 'name': '1234',
})]}) })]})
# successful creation
partner_1.write({'id_numbers': [(0, 0, { partner_1.write({'id_numbers': [(0, 0, {
'name': '1234', 'name': '1234',
'category_id': partner_id_category.id 'category_id': partner_id_category.id
})]}) })]})
self.assertEquals(len(partner_1.id_numbers), 1) self.assertEquals(len(partner_1.id_numbers), 1)
self.assertEquals(partner_1.id_numbers.name, '1234') self.assertEquals(partner_1.id_numbers.name, '1234')
# delete
partner_1.write({'id_numbers': [(5, 0, 0)]})
self.assertEquals(len(partner_1.id_numbers), 0)
class TestPartnerCategoryValidation(common.TransactionCase): class TestPartnerCategoryValidation(common.TransactionCase):

Loading…
Cancel
Save