Skip to content

Commit

Permalink
[FIX] event_registration_partner_unique: avoid constraint on merge
Browse files Browse the repository at this point in the history
If a user merge two contacts we should not raise the duplicates
constraint for that contact attendee.

TT45921
  • Loading branch information
chienandalu committed Nov 13, 2023
1 parent 80a92d9 commit d1385e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions event_registration_partner_unique/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizards
2 changes: 2 additions & 0 deletions event_registration_partner_unique/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions event_registration_partner_unique/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base_partner_merge
14 changes: 14 additions & 0 deletions event_registration_partner_unique/wizards/base_partner_merge.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d1385e1

Please sign in to comment.