From de0520d5a8f35addbf52d2134f2ab0ce4ea35773 Mon Sep 17 00:00:00 2001 From: luis Date: Mon, 4 May 2026 11:47:25 +0200 Subject: [PATCH] add portal_event_registration --- portal_event_registration/__init__.py | 3 + portal_event_registration/__manifest__.py | 18 ++ .../controllers/__init__.py | 3 + .../controllers/portal.py | 117 ++++++++++ portal_event_registration/models/__init__.py | 3 + .../models/event_registration.py | 11 + .../security/ir.model.access.csv | 3 + .../security/security.xml | 30 +++ .../views/portal_templates.xml | 205 ++++++++++++++++++ 9 files changed, 393 insertions(+) create mode 100644 portal_event_registration/__init__.py create mode 100644 portal_event_registration/__manifest__.py create mode 100644 portal_event_registration/controllers/__init__.py create mode 100644 portal_event_registration/controllers/portal.py create mode 100644 portal_event_registration/models/__init__.py create mode 100644 portal_event_registration/models/event_registration.py create mode 100644 portal_event_registration/security/ir.model.access.csv create mode 100644 portal_event_registration/security/security.xml create mode 100644 portal_event_registration/views/portal_templates.xml diff --git a/portal_event_registration/__init__.py b/portal_event_registration/__init__.py new file mode 100644 index 0000000..819d632 --- /dev/null +++ b/portal_event_registration/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import controllers, models diff --git a/portal_event_registration/__manifest__.py b/portal_event_registration/__manifest__.py new file mode 100644 index 0000000..da15c91 --- /dev/null +++ b/portal_event_registration/__manifest__.py @@ -0,0 +1,18 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Portal Event Registration", + "summary": "Allows portal users to view their event registrations " + "and upload attachments to the chatter.", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Custom", + "depends": ["event", "portal"], + "data": [ + "security/security.xml", + "security/ir.model.access.csv", + "security/ir.model.access.csv", + "views/portal_templates.xml", + ], + "installable": True, +} diff --git a/portal_event_registration/controllers/__init__.py b/portal_event_registration/controllers/__init__.py new file mode 100644 index 0000000..6981380 --- /dev/null +++ b/portal_event_registration/controllers/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import portal diff --git a/portal_event_registration/controllers/portal.py b/portal_event_registration/controllers/portal.py new file mode 100644 index 0000000..b771439 --- /dev/null +++ b/portal_event_registration/controllers/portal.py @@ -0,0 +1,117 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, http +from odoo.exceptions import AccessError, MissingError +from odoo.http import request + +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.addons.portal.controllers.portal import pager as portal_pager + + +class EventRegistrationPortal(CustomerPortal): + + def _prepare_home_portal_values(self, counters): + values = super()._prepare_home_portal_values(counters) + if "event_count" in counters: + Registration = request.env["event.registration"] + partner = request.env.user.partner_id + domain = self._get_event_registration_domain(partner) + values["event_count"] = ( + Registration.search_count(domain) + if Registration.has_access("read") + else 0 + ) + return values + + def _get_event_registration_domain(self, partner): + return [ + ("partner_id", "child_of", [partner.commercial_partner_id.id]), + ("state", "!=", "cancel"), + ] + + def _get_event_searchbar_sortings(self): + return { + "date": {"label": _("Event Date"), "order": "event_begin_date desc"}, + "name": {"label": _("Event Name"), "order": "event_id asc"}, + "state": {"label": _("Status"), "order": "state asc"}, + } + + @http.route( + ["/my/events", "/my/events/page/"], + type="http", + auth="user", + website=True, + ) + def portal_my_events(self, page=1, sortby=None, **kw): + partner = request.env.user.partner_id + Registration = request.env["event.registration"] + domain = self._get_event_registration_domain(partner) + + searchbar_sortings = self._get_event_searchbar_sortings() + if not sortby: + sortby = "date" + order = searchbar_sortings[sortby]["order"] + + total = ( + Registration.search_count(domain) if Registration.has_access("read") else 0 + ) + pager = portal_pager( + url="/my/events", + url_args={"sortby": sortby}, + total=total, + page=page, + step=self._items_per_page, + ) + registrations = ( + Registration.search( + domain, + order=order, + limit=self._items_per_page, + offset=pager["offset"], + ) + if Registration.has_access("read") + else Registration + ) + + request.session["my_events_history"] = registrations.ids[:100] + + values = self._prepare_portal_layout_values() + values.update( + { + "registrations": registrations, + "page_name": "event", + "pager": pager, + "sortby": sortby, + "searchbar_sortings": searchbar_sortings, + "default_url": "/my/events", + } + ) + return request.render("portal_event_registration.portal_my_events", values) + + @http.route( + ["/my/events/"], + type="http", + auth="user", + website=True, + ) + def portal_my_event_detail(self, registration_id, access_token=None, **kw): + try: + registration_sudo = self._document_check_access( + "event.registration", registration_id, access_token=access_token + ) + except (AccessError, MissingError): + return request.redirect("/my") + + values = self._prepare_portal_layout_values() + values["registration"] = registration_sudo + values = self._get_page_view_values( + registration_sudo, + access_token, + values, + "my_events_history", + False, + **kw, + ) + return request.render( + "portal_event_registration.portal_my_event_detail", values + ) diff --git a/portal_event_registration/models/__init__.py b/portal_event_registration/models/__init__.py new file mode 100644 index 0000000..96bbf53 --- /dev/null +++ b/portal_event_registration/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import event_registration diff --git a/portal_event_registration/models/event_registration.py b/portal_event_registration/models/event_registration.py new file mode 100644 index 0000000..4282149 --- /dev/null +++ b/portal_event_registration/models/event_registration.py @@ -0,0 +1,11 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class EventRegistration(models.Model): + _inherit = "event.registration" + + # Allow portal users (who only have read access) to post messages + # and upload attachments via the portal chatter. + _mail_post_access = "read" diff --git a/portal_event_registration/security/ir.model.access.csv b/portal_event_registration/security/ir.model.access.csv new file mode 100644 index 0000000..e2cfc15 --- /dev/null +++ b/portal_event_registration/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_event_event_portal,event.event.portal,event.model_event_event,base.group_portal,1,0,0,0 +access_event_registration_portal,event.registration.portal,event.model_event_registration,base.group_portal,1,0,0,0 diff --git a/portal_event_registration/security/security.xml b/portal_event_registration/security/security.xml new file mode 100644 index 0000000..a34cd37 --- /dev/null +++ b/portal_event_registration/security/security.xml @@ -0,0 +1,30 @@ + + + + + Event Registration: portal users see own registrations + + + [('partner_id', 'child_of', [user.commercial_partner_id.id])] + + + + + + + + + + + Event Event: portal users see events with own registrations + + + [('registration_ids.partner_id', 'child_of', [user.commercial_partner_id.id])] + + + + + + + + diff --git a/portal_event_registration/views/portal_templates.xml b/portal_event_registration/views/portal_templates.xml new file mode 100644 index 0000000..f1e97a2 --- /dev/null +++ b/portal_event_registration/views/portal_templates.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + +