diff --git a/event_registration_firstname/README.rst b/event_registration_firstname/README.rst new file mode 100644 index 000000000..a1accfa0d --- /dev/null +++ b/event_registration_firstname/README.rst @@ -0,0 +1,79 @@ +============================ +Event Registration Firstname +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:62ec43670bb8a53a7774e60bb442dfed655d0dc99a392c374e349cb08db70564 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github + :target: https://github.com/OCA/event/tree/18.0/event_registration_firstname + :alt: OCA/event +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/event-18-0/event-18-0-event_registration_firstname + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/event&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Adds ``firstname`` and ``lastname`` fields to ``event.registration``. + +The ``name`` field is kept in sync using the same order rules as +``partner_firstname`` (``partner_names_order`` system parameter). + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* INVITU + +Contributors +------------ + +- Cyril VINH-TUNG <> + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/event `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/event_registration_firstname/__init__.py b/event_registration_firstname/__init__.py new file mode 100644 index 000000000..d6f9b1a58 --- /dev/null +++ b/event_registration_firstname/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2026 INVITU () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/event_registration_firstname/__manifest__.py b/event_registration_firstname/__manifest__.py new file mode 100644 index 000000000..556525956 --- /dev/null +++ b/event_registration_firstname/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2026 INVITU () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Event Registration Firstname", + "version": "18.0.1.0.0", + "category": "Marketing", + "author": "INVITU, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/event", + "license": "AGPL-3", + "depends": ["event", "partner_firstname"], + "data": ["views/event_registration_view.xml"], + "installable": True, +} diff --git a/event_registration_firstname/models/__init__.py b/event_registration_firstname/models/__init__.py new file mode 100644 index 000000000..03ec2a076 --- /dev/null +++ b/event_registration_firstname/models/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2026 INVITU () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import event_registration diff --git a/event_registration_firstname/models/event_registration.py b/event_registration_firstname/models/event_registration.py new file mode 100644 index 000000000..470435da4 --- /dev/null +++ b/event_registration_firstname/models/event_registration.py @@ -0,0 +1,48 @@ +# Copyright 2026 INVITU () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class EventRegistration(models.Model): + _inherit = "event.registration" + + firstname = fields.Char() + lastname = fields.Char() + + @api.model + def _get_name(self, lastname, firstname): + """Compute name from parts using partner_firstname names order config.""" + return self.env["res.partner"]._get_computed_name(lastname, firstname) + + @api.onchange("firstname", "lastname") + def _onchange_firstname_lastname(self): + if self.firstname or self.lastname: + self.name = self._get_name(self.lastname, self.firstname) + + def _prepare_vals_on_create_firstname_lastname(self, vals): + if vals.get("firstname") or vals.get("lastname"): + vals["name"] = self._get_name(vals.get("lastname"), vals.get("firstname")) + elif vals.get("name"): + parts = self.env["res.partner"]._get_inverse_name(vals["name"]) + vals["lastname"] = parts.get("lastname") + vals["firstname"] = parts.get("firstname") + + def _prepare_vals_on_write_firstname_lastname(self, vals): + if "firstname" in vals or "lastname" in vals: + lastname = vals.get("lastname", self.lastname) + firstname = vals.get("firstname", self.firstname) + vals["name"] = self._get_name(lastname, firstname) + elif vals.get("name"): + parts = self.env["res.partner"]._get_inverse_name(vals["name"]) + vals["lastname"] = parts.get("lastname") + vals["firstname"] = parts.get("firstname") + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + self._prepare_vals_on_create_firstname_lastname(vals) + return super().create(vals_list) + + def write(self, vals): + self._prepare_vals_on_write_firstname_lastname(vals) + return super().write(vals) diff --git a/event_registration_firstname/pyproject.toml b/event_registration_firstname/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/event_registration_firstname/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/event_registration_firstname/readme/CONTRIBUTORS.md b/event_registration_firstname/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..8570aec2f --- /dev/null +++ b/event_registration_firstname/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +* Cyril VINH-TUNG <\> diff --git a/event_registration_firstname/readme/DESCRIPTION.md b/event_registration_firstname/readme/DESCRIPTION.md new file mode 100644 index 000000000..01027d9cf --- /dev/null +++ b/event_registration_firstname/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +Adds ``firstname`` and ``lastname`` fields to ``event.registration``. + +The ``name`` field is kept in sync using the same order rules as +``partner_firstname`` (``partner_names_order`` system parameter). diff --git a/event_registration_firstname/static/description/index.html b/event_registration_firstname/static/description/index.html new file mode 100644 index 000000000..d4f53b302 --- /dev/null +++ b/event_registration_firstname/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +Event Registration Firstname + + + +
+

Event Registration Firstname

+ + +

Beta License: AGPL-3 OCA/event Translate me on Weblate Try me on Runboat

+

Adds firstname and lastname fields to event.registration.

+

The name field is kept in sync using the same order rules as +partner_firstname (partner_names_order system parameter).

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • INVITU
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/event project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/event_registration_firstname/tests/__init__.py b/event_registration_firstname/tests/__init__.py new file mode 100644 index 000000000..9dc302ce7 --- /dev/null +++ b/event_registration_firstname/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2026 INVITU () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import test_event_registration_firstname diff --git a/event_registration_firstname/tests/test_event_registration_firstname.py b/event_registration_firstname/tests/test_event_registration_firstname.py new file mode 100644 index 000000000..5da47f208 --- /dev/null +++ b/event_registration_firstname/tests/test_event_registration_firstname.py @@ -0,0 +1,51 @@ +# Copyright 2026 INVITU () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from datetime import datetime + +from odoo.tests.common import TransactionCase + + +class TestEventRegistrationFirstname(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.event = cls.env["event.event"].create( + { + "name": "Test Event", + "date_begin": datetime(2026, 9, 1, 8, 0), + "date_end": datetime(2026, 9, 1, 18, 0), + } + ) + + def _new_reg(self, vals): + vals["event_id"] = self.event.id + return self.env["event.registration"].create(vals) + + def _set_order(self, order): + self.env["ir.config_parameter"].sudo().set_param("partner_names_order", order) + + def test_create_from_firstname_lastname_last_first(self): + """firstname + lastname → name computed in last_first order.""" + self._set_order("last_first") + reg = self._new_reg({"firstname": "John", "lastname": "Smith"}) + self.assertEqual(reg.name, "Smith John") + + def test_create_from_firstname_lastname_first_last(self): + """firstname + lastname → name computed in first_last order.""" + self._set_order("first_last") + reg = self._new_reg({"firstname": "John", "lastname": "Smith"}) + self.assertEqual(reg.name, "John Smith") + + def test_create_from_name_splits(self): + """name only → split into firstname + lastname per configured order.""" + self._set_order("last_first") + reg = self._new_reg({"name": "Smith John"}) + self.assertEqual(reg.lastname, "Smith") + self.assertEqual(reg.firstname, "John") + + def test_write_firstname_updates_name(self): + """Updating firstname recomputes name.""" + self._set_order("last_first") + reg = self._new_reg({"firstname": "John", "lastname": "Smith"}) + reg.write({"firstname": "Peter"}) + self.assertEqual(reg.name, "Smith Peter") diff --git a/event_registration_firstname/views/event_registration_view.xml b/event_registration_firstname/views/event_registration_view.xml new file mode 100644 index 000000000..bcb6146ab --- /dev/null +++ b/event_registration_firstname/views/event_registration_view.xml @@ -0,0 +1,18 @@ + + + + + event.registration + + + + 1 + + + + + + + +