From dd8653ff827e7fc3c31e2826189cf4451080e390 Mon Sep 17 00:00:00 2001 From: Stephan Keller Date: Wed, 29 Apr 2020 10:56:14 +0200 Subject: [PATCH] [FIX] partner_multi_relation: fix unlinking of record sets with same res_id --- partner_multi_relation/models/res_partner_relation_all.py | 7 +++++-- partner_multi_relation/tests/test_partner_relation_all.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/partner_multi_relation/models/res_partner_relation_all.py b/partner_multi_relation/models/res_partner_relation_all.py index c8189a312..496a60b27 100644 --- a/partner_multi_relation/models/res_partner_relation_all.py +++ b/partner_multi_relation/models/res_partner_relation_all.py @@ -7,7 +7,7 @@ import logging from psycopg2.extensions import AsIs from odoo import _, api, fields, models -from odoo.exceptions import ValidationError +from odoo.exceptions import MissingError, ValidationError from odoo.tools import drop_view_if_exists @@ -466,6 +466,9 @@ CREATE OR REPLACE VIEW %%(table)s AS """For model 'res.partner.relation' call unlink on underlying model. """ for rec in self: - base_resource = rec.get_base_resource() + try: + base_resource = rec.get_base_resource() + except MissingError: + continue rec.unlink_resource(base_resource) return True diff --git a/partner_multi_relation/tests/test_partner_relation_all.py b/partner_multi_relation/tests/test_partner_relation_all.py index bbf64b216..7ebefb2b2 100644 --- a/partner_multi_relation/tests/test_partner_relation_all.py +++ b/partner_multi_relation/tests/test_partner_relation_all.py @@ -170,6 +170,8 @@ class TestPartnerRelation(TestPartnerRelationCommon): base_relation = base_model.browse([relation.res_id]) relation.unlink() self.assertFalse(base_relation.exists()) + # Check unlinking record sets with both derived relation records + self.assertTrue(self.relation_all_model.search([]).unlink()) def test_on_change_type_selection(self): """Test on_change_type_selection."""