diff --git a/event_registration_partner_unique/__manifest__.py b/event_registration_partner_unique/__manifest__.py
index b3c089661..5b34b371d 100644
--- a/event_registration_partner_unique/__manifest__.py
+++ b/event_registration_partner_unique/__manifest__.py
@@ -14,6 +14,6 @@
"license": "AGPL-3",
"application": False,
"installable": True,
- "depends": ["partner_event"],
- "data": ["views/event_event_view.xml"],
+ "depends": ["event", "partner_event"],
+ "data": ["views/event_event_view.xml", "views/event_type_view.xml"],
}
diff --git a/event_registration_partner_unique/models/event.py b/event_registration_partner_unique/models/event.py
index ca19d9a03..c41ce410c 100644
--- a/event_registration_partner_unique/models/event.py
+++ b/event_registration_partner_unique/models/event.py
@@ -3,7 +3,7 @@
# Copyright 2022 Tecnativa - Luis D. Lafaurie
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-from odoo import api, fields, models
+from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
@@ -13,6 +13,9 @@ class EventEvent(models.Model):
forbid_duplicates = fields.Boolean(
help="Check this to disallow duplicate attendees in this event's "
"registrations",
+ compute="_compute_forbid_duplicates",
+ store=True,
+ readonly=False,
)
@api.constrains("forbid_duplicates", "registration_ids")
@@ -22,6 +25,15 @@ def _check_forbid_duplicates(self):
"forbid_duplicates"
).registration_ids._check_forbid_duplicates()
+ @api.depends("event_type_id")
+ def _compute_forbid_duplicates(self):
+ """Update event configuration from its event type. Depends are set only
+ on event_type_id itself, not its sub fields. Purpose is to emulate an
+ onchange: if event type is changed, update event configuration. Changing
+ event type content itself should not trigger this method."""
+ for event in self:
+ event.forbid_duplicates = event.event_type_id.forbid_duplicates
+
class EventRegistration(models.Model):
_inherit = "event.registration"
@@ -34,7 +46,7 @@ def _check_forbid_duplicates(self):
if dupes:
# pylint: disable=W8120
raise ValidationError(
- self.env._("Duplicated partners found in event {0}: {1}.").format(
+ _("Duplicated partners found in event {0}: {1}.").format(
event_reg.event_id.display_name,
", ".join(
partner_id.display_name
@@ -51,3 +63,11 @@ def _duplicate_search_domain(self):
("attendee_partner_id", "=", self.attendee_partner_id.id),
("attendee_partner_id", "!=", False),
]
+
+
+class EventType(models.Model):
+ _inherit = "event.type"
+ forbid_duplicates = fields.Boolean(
+ help="Check this to disallow duplicate attendees in this event's "
+ "registrations"
+ )
diff --git a/event_registration_partner_unique/views/event_event_view.xml b/event_registration_partner_unique/views/event_event_view.xml
index 477558f2a..fabb48fcb 100644
--- a/event_registration_partner_unique/views/event_event_view.xml
+++ b/event_registration_partner_unique/views/event_event_view.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/event_registration_partner_unique/views/event_type_view.xml b/event_registration_partner_unique/views/event_type_view.xml
new file mode 100644
index 000000000..bae02c1e6
--- /dev/null
+++ b/event_registration_partner_unique/views/event_type_view.xml
@@ -0,0 +1,14 @@
+
+
+ Add option to avoid duplicates
+ event.type
+
+
+
+
+
+
+
+
+
+