diff --git a/event_sale_seat_reserve/README.rst b/event_sale_seat_reserve/README.rst new file mode 100644 index 000000000..629d33a15 --- /dev/null +++ b/event_sale_seat_reserve/README.rst @@ -0,0 +1,76 @@ +======================= +Event Sale Seat Reserve +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5da17a3c8f6a4044d9f9ca98e471773ea81dad23707648a0325d3eaf997f4f11 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/event_sale_seat_reserve + :alt: OCA/event +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/event-16-0/event-16-0-event_sale_seat_reserve + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to make a pre-reserve on registrations after confirming the sale order. + +**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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Italo LOPES + +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_sale_seat_reserve/__init__.py b/event_sale_seat_reserve/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/event_sale_seat_reserve/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/event_sale_seat_reserve/__manifest__.py b/event_sale_seat_reserve/__manifest__.py new file mode 100644 index 000000000..3271a1483 --- /dev/null +++ b/event_sale_seat_reserve/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0). +{ + "name": "Event Sale Seat Reserve", + "version": "16.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/event", + "category": "Marketing", + "summary": "Allow pre-reserve registrations on sales", + "depends": ["event_sale", "event_seat_reserve"], + "installable": True, + "auto_install": False, +} diff --git a/event_sale_seat_reserve/models/__init__.py b/event_sale_seat_reserve/models/__init__.py new file mode 100644 index 000000000..2d7ee6c3d --- /dev/null +++ b/event_sale_seat_reserve/models/__init__.py @@ -0,0 +1,2 @@ +from . import sale_order +from . import sale_order_line diff --git a/event_sale_seat_reserve/models/sale_order.py b/event_sale_seat_reserve/models/sale_order.py new file mode 100644 index 000000000..5ff4d6a6c --- /dev/null +++ b/event_sale_seat_reserve/models/sale_order.py @@ -0,0 +1,13 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0). + +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def action_draft(self): + result = super().action_draft() + self.order_line._set_draft_associated_registrations() + return result diff --git a/event_sale_seat_reserve/models/sale_order_line.py b/event_sale_seat_reserve/models/sale_order_line.py new file mode 100644 index 000000000..c127ba09d --- /dev/null +++ b/event_sale_seat_reserve/models/sale_order_line.py @@ -0,0 +1,39 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0). + +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def _update_registrations( + self, + confirm=True, + cancel_to_draft=False, + registration_data=None, + mark_as_paid=False, + ): + res = super(SaleOrderLine, self)._update_registrations( + confirm=confirm, + cancel_to_draft=cancel_to_draft, + registration_data=registration_data, + mark_as_paid=mark_as_paid, + ) + RegistrationSudo = self.env["event.registration"].sudo() + registrations = RegistrationSudo.search( + [("sale_order_line_id", "in", self.ids), ("state", "=", "draft")] + ) + registrations.action_set_reserved() + return res + + def _set_draft_associated_registrations(self): + RegistrationSudo = self.env["event.registration"].sudo() + registrations = RegistrationSudo.search( + [ + ("sale_order_line_id", "in", self.ids), + ("state", "!=", "done") + ] + ) + registrations.action_set_draft() + return True diff --git a/event_sale_seat_reserve/readme/CONTRIBUTORS.rst b/event_sale_seat_reserve/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..04b04faf0 --- /dev/null +++ b/event_sale_seat_reserve/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Italo LOPES diff --git a/event_sale_seat_reserve/readme/DESCRIPTION.rst b/event_sale_seat_reserve/readme/DESCRIPTION.rst new file mode 100644 index 000000000..78cea4d69 --- /dev/null +++ b/event_sale_seat_reserve/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to make a pre-reserve on registrations after confirming the sale order. diff --git a/event_sale_seat_reserve/static/description/icon.png b/event_sale_seat_reserve/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/event_sale_seat_reserve/static/description/icon.png differ diff --git a/event_sale_seat_reserve/static/description/index.html b/event_sale_seat_reserve/static/description/index.html new file mode 100644 index 000000000..8ba118c4e --- /dev/null +++ b/event_sale_seat_reserve/static/description/index.html @@ -0,0 +1,420 @@ + + + + + +Event Sale Seat Reserve + + + +
+

Event Sale Seat Reserve

+ + +

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

+

This module allows to make a pre-reserve on registrations after confirming the sale order.

+

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

+
    +
  • Camptocamp
  • +
+
+ +
+

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_sale_seat_reserve/tests/__init__.py b/event_sale_seat_reserve/tests/__init__.py new file mode 100644 index 000000000..51487beaa --- /dev/null +++ b/event_sale_seat_reserve/tests/__init__.py @@ -0,0 +1 @@ +from . import test_event_sale_seat_reserve diff --git a/event_sale_seat_reserve/tests/test_event_sale_seat_reserve.py b/event_sale_seat_reserve/tests/test_event_sale_seat_reserve.py new file mode 100644 index 000000000..86a74e25e --- /dev/null +++ b/event_sale_seat_reserve/tests/test_event_sale_seat_reserve.py @@ -0,0 +1,110 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestEventSaleSeatReserve(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # ../event/data/event_demo.xml + # using this demo data, we have a max_seats = 4 + # and 3 registrations + cls.event = cls.env.ref("event.event_4") + cls.event_ticket = cls.env.ref("event.event_4_ticket_0") + cls.event_product = cls.env.ref("event_sale.product_product_event") + cls.partner = cls.env.ref("base.res_partner_1") + cls.partner2 = cls.env.ref("base.res_partner_2") + cls.sale_order1 = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "payment_term_id": cls.env.ref( + "account.account_payment_term_end_following_month" + ).id, + } + ) + + cls.env["sale.order.line"].create( + { + "product_id": cls.event_product.id, + "price_unit": 30, + "order_id": cls.sale_order1.id, + "event_id": cls.event.id, + "event_ticket_id": cls.event_ticket.id, + } + ) + + cls.registration1 = cls.env["event.registration"].create( + { + "event_id": cls.event.id, + "event_ticket_id": cls.event_ticket.id, + "name": cls.partner.name, + "partner_id": cls.partner.id, + "sale_order_id": cls.sale_order1.id, + "sale_order_line_id": cls.sale_order1.order_line.id, + } + ) + + cls.sale_order2 = cls.env["sale.order"].create( + { + "partner_id": cls.partner2.id, + "payment_term_id": cls.env.ref( + "account.account_payment_term_end_following_month" + ).id, + } + ) + + cls.env["sale.order.line"].create( + { + "product_id": cls.event_product.id, + "price_unit": 30, + "order_id": cls.sale_order2.id, + "event_id": cls.event.id, + "event_ticket_id": cls.event_ticket.id, + } + ) + + cls.registration2 = cls.env["event.registration"].create( + { + "event_id": cls.event.id, + "event_ticket_id": cls.event_ticket.id, + "name": cls.partner2.name, + "partner_id": cls.partner2.id, + "sale_order_id": cls.sale_order2.id, + "sale_order_line_id": cls.sale_order2.order_line.id, + } + ) + + def test_01_confirm_sale(self): + """ + Test that reserved quantity is set and if seats are available or not + """ + self.sale_order1.action_confirm() + self.assertEqual(self.event_ticket.seats_reserved_unconfirmed, 1) + self.assertEqual(self.registration1.state, "reserved") + self.assertEqual(self.event.seats_available, 0) + + def test_02_confirm_sale_no_available_seats(self): + """ + Test that reserved quantity is set and if seats are available or not + """ + self.sale_order1.action_confirm() + with self.assertRaisesRegex( + ValidationError, "There are not enough seats available*" + ): + self.sale_order2.action_confirm() + + def test_03_reset_confirmed_sale_to_draft(self): + """ + Test if the reserved quantity is set to 0 when the sale is reset to draft + """ + self.sale_order1.action_confirm() + self.assertEqual(self.event_ticket.seats_reserved_unconfirmed, 1) + self.assertEqual(self.registration1.state, "reserved") + self.assertEqual(self.event.seats_available, 0) + self.sale_order1.action_draft() + self.assertEqual(self.event_ticket.seats_reserved_unconfirmed, 0) + self.assertEqual(self.registration1.state, "draft") + self.assertEqual(self.event.seats_available, 1) diff --git a/setup/event_sale_seat_reserve/odoo/addons/event_sale_seat_reserve b/setup/event_sale_seat_reserve/odoo/addons/event_sale_seat_reserve new file mode 120000 index 000000000..ef7f909dd --- /dev/null +++ b/setup/event_sale_seat_reserve/odoo/addons/event_sale_seat_reserve @@ -0,0 +1 @@ +../../../../event_sale_seat_reserve \ No newline at end of file diff --git a/setup/event_sale_seat_reserve/setup.py b/setup/event_sale_seat_reserve/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/event_sale_seat_reserve/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..07f6f0186 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-event_seat_reserve @ git+https://github.com/OCA/event.git@refs/pull/394/head#subdirectory=event_seat_reserve