Skip to content

Commit

Permalink
[FIX] partner_identification: prevent integrity error on delete ID
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon authored and edlopen committed Mar 1, 2024
1 parent f5147d0 commit 31b2419
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion partner_identification/models/res_partner_id_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
9 changes: 7 additions & 2 deletions partner_identification/tests/test_partner_identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 31b2419

Please sign in to comment.