From d1385e170389b31798c6bc7db5d2b7c5dfb67346 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 13 Nov 2023 11:36:40 +0100 Subject: [PATCH] [FIX] event_registration_partner_unique: avoid constraint on merge If a user merge two contacts we should not raise the duplicates constraint for that contact attendee. TT45921 --- event_registration_partner_unique/__init__.py | 1 + event_registration_partner_unique/models/event.py | 2 ++ .../wizards/__init__.py | 1 + .../wizards/base_partner_merge.py | 14 ++++++++++++++ 4 files changed, 18 insertions(+) create mode 100644 event_registration_partner_unique/wizards/__init__.py create mode 100644 event_registration_partner_unique/wizards/base_partner_merge.py diff --git a/event_registration_partner_unique/__init__.py b/event_registration_partner_unique/__init__.py index 83e553ac4..0aa9b03c5 100644 --- a/event_registration_partner_unique/__init__.py +++ b/event_registration_partner_unique/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models +from . import wizards diff --git a/event_registration_partner_unique/models/event.py b/event_registration_partner_unique/models/event.py index 3ed3fa9ca..621f42207 100644 --- a/event_registration_partner_unique/models/event.py +++ b/event_registration_partner_unique/models/event.py @@ -18,6 +18,8 @@ class EventEvent(models.Model): @api.constrains("forbid_duplicates", "registration_ids") def _check_forbid_duplicates(self): """Ensure no duplicated attendee are found in the event.""" + if self.env.context.get("skip_registration_partner_unique"): + return return self.filtered( "forbid_duplicates" ).registration_ids._check_forbid_duplicates() diff --git a/event_registration_partner_unique/wizards/__init__.py b/event_registration_partner_unique/wizards/__init__.py new file mode 100644 index 000000000..e3fc7010c --- /dev/null +++ b/event_registration_partner_unique/wizards/__init__.py @@ -0,0 +1 @@ +from . import base_partner_merge diff --git a/event_registration_partner_unique/wizards/base_partner_merge.py b/event_registration_partner_unique/wizards/base_partner_merge.py new file mode 100644 index 000000000..2933abd2f --- /dev/null +++ b/event_registration_partner_unique/wizards/base_partner_merge.py @@ -0,0 +1,14 @@ +# Copyright 2023 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class BasePartnerMergeAutomaticWizard(models.TransientModel): + _inherit = "base.partner.merge.automatic.wizard" + + def action_merge(self): + """Inject context for avoiding the duplicated partner constraint""" + return super( + BasePartnerMergeAutomaticWizard, + self.with_context(skip_registration_partner_unique=True), + ).action_merge()