From 2133411501c281842aa5bda4a5a508a95dee33af Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 30 May 2016 08:36:55 +0200 Subject: [PATCH] [FIX] partner_identification: prevent integrity error on delete ID --- partner_identification/models/res_partner_id_number.py | 3 ++- .../tests/test_partner_identification.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/partner_identification/models/res_partner_id_number.py b/partner_identification/models/res_partner_id_number.py index 2f0c621aa..a8859cec7 100644 --- a/partner_identification/models/res_partner_id_number.py +++ b/partner_identification/models/res_partner_id_number.py @@ -29,7 +29,8 @@ class ResPartnerIdNumber(models.Model): comodel_name='res.partner.id_category', help="ID type defined in configuration. For example, Driver License") partner_id = fields.Many2one(string="Partner", required=True, - comodel_name='res.partner') + comodel_name='res.partner', + ondelete='cascade') partner_issued_id = fields.Many2one( string="Issued by", comodel_name='res.partner', help="Another partner, who issued this ID. For example, Traffic " diff --git a/partner_identification/tests/test_partner_identification.py b/partner_identification/tests/test_partner_identification.py index d46a243c4..9d46f7642 100644 --- a/partner_identification/tests/test_partner_identification.py +++ b/partner_identification/tests/test_partner_identification.py @@ -20,16 +20,21 @@ class TestPartnerIdentificationBase(common.TransactionCase): partner_1 = self.env.ref('base.res_partner_1') self.assertEquals(len(partner_1.id_numbers), 0) + # create without required category with self.assertRaises(IntegrityError), self.cr.savepoint(): - partner_1.write({'id_numbers': [(0, 0, { + partner_1.write({'id_numbers': [(0, 0, { 'name': '1234', })]}) - partner_1.write({'id_numbers': [(0, 0, { + # successful creation + partner_1.write({'id_numbers': [(0, 0, { 'name': '1234', 'category_id': partner_id_category.id })]}) self.assertEquals(len(partner_1.id_numbers), 1) 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):