Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions event_registration_partner_unique/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["partner_event"],
"data": ["views/event_event_view.xml"],
"depends": ["event", "partner_event"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add the redundant dependency

"data": ["views/event_event_view.xml", "views/event_type_view.xml"],
}
24 changes: 22 additions & 2 deletions event_registration_partner_unique/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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")
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slight behavior change, as previously changing the type doesn't touch the field, but I think it can be acceptable.

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"
Expand All @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change this.

event_reg.event_id.display_name,
", ".join(
partner_id.display_name
Expand All @@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this is a new file.

_inherit = "event.type"
forbid_duplicates = fields.Boolean(
help="Check this to disallow duplicate attendees in this event's "
"registrations"
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field name="priority" eval="99" />
<field name="inherit_id" ref="event.view_event_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='create_partner']" position="after">
<xpath expr="//field[@name='badge_image']" position="after">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this.

<field name="forbid_duplicates" />
</xpath>
</field>
Expand Down
14 changes: 14 additions & 0 deletions event_registration_partner_unique/views/event_type_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<odoo>
<record id="view_event_type_form" model="ir.ui.view">
<field name="name">Add option to avoid duplicates</field>
<field name="model">event.type</field>
<!-- Make sure this view is loaded after event_sale's one, as it replaces full page -->
<field name="priority" eval="99" />
<field name="inherit_id" ref="event.view_event_type_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='tag_ids']" position="after">
<field name="forbid_duplicates" />
</xpath>
</field>
</record>
</odoo>