diff --git a/partner_identification/models/res_partner_id_number.py b/partner_identification/models/res_partner_id_number.py index 2f0c621aa5c..a8859cec75d 100644 --- a/partner_identification/models/res_partner_id_number.py +++ b/partner_identification/models/res_partner_id_number.py @@ -29,7 +29,8 @@ def validate_id_number(self): 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 d46a243c462..9d46f7642b6 100644 --- a/partner_identification/tests/test_partner_identification.py +++ b/partner_identification/tests/test_partner_identification.py @@ -20,16 +20,21 @@ def test_base_functionalities(self): 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):