-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
9 changed files
with
100 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import base_partner_merge |
33 changes: 33 additions & 0 deletions
33
event_registration_partner_unique/wizards/base_partner_merge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2023 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from odoo import fields, models | ||
|
||
|
||
class BasePartnerMergeAutomaticWizard(models.TransientModel): | ||
_inherit = "base.partner.merge.automatic.wizard" | ||
|
||
merge_duplicated_registrations = fields.Boolean( | ||
help="If the merged partners were linked to registrations in an event that had " | ||
"unique attendees flag we'll take only the oldest one", | ||
) | ||
|
||
def action_merge(self): | ||
"""Allow to get rid of duplicated registrations linked to the merged partners""" | ||
if not self.merge_duplicated_registrations: | ||
return super().action_merge() | ||
# Skip the constraints and do the partner merge first | ||
res = super( | ||
BasePartnerMergeAutomaticWizard, | ||
self.with_context(skip_registration_partner_unique=True), | ||
).action_merge() | ||
# Now let's merge the attendees | ||
dupes_to_unlink = self.env["event.registration"] | ||
partner_registrations = self.dst_partner_id.event_registration_ids | ||
for attendee, dupes in partner_registrations._find_duplicated_attendees(): | ||
# Keep the oldest one -> min id will be | ||
event_attendees_for_partner = attendee + dupes | ||
attendee_to_keep = min(event_attendees_for_partner, key=lambda x: x.id) | ||
dupes_to_unlink += event_attendees_for_partner - attendee_to_keep | ||
# Call with skipping context to avoid triggering the constraint again | ||
dupes_to_unlink.with_context(skip_registration_partner_unique=True).unlink() | ||
return res |
12 changes: 12 additions & 0 deletions
12
event_registration_partner_unique/wizards/base_partner_merge_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="base_partner_merge_automatic_wizard_form" model="ir.ui.view"> | ||
<field name="inherit_id" ref="base.base_partner_merge_automatic_wizard_form" /> | ||
<field name='model'>base.partner.merge.automatic.wizard</field> | ||
<field name='arch' type='xml'> | ||
<field name="dst_partner_id" position="after"> | ||
<field name="merge_duplicated_registrations" /> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |