Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] event_seat_reserve #394

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
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
76 changes: 76 additions & 0 deletions event_seat_reserve/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
==================
Event Seat Reserve
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:93349cd4baa4e5a7a6b3916bf8e139c0f77b95a7d1aa0b772f5e04a67a218a10
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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_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_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.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/event/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 <https://github.com/OCA/event/issues/new?body=module:%20event_seat_reserve%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Italo LOPES <italo.lopes@camptocamp.com>

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 <https://github.com/OCA/event/tree/16.0/event_seat_reserve>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions event_seat_reserve/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions event_seat_reserve/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0).
{
"name": "Event 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",
"depends": ["event"],
"data": [
"views/event_registration.xml",
],
"installable": True,
"auto_install": False,
}
53 changes: 53 additions & 0 deletions event_seat_reserve/i18n/event_seat_reserve.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * event_seat_reserve
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-25 13:30+0000\n"
"PO-Revision-Date: 2024-07-25 13:30+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: event_seat_reserve
#: model:ir.model,name:event_seat_reserve.model_event_event
msgid "Event"
msgstr ""

#. module: event_seat_reserve
#: model:ir.model,name:event_seat_reserve.model_event_registration
msgid "Event Registration"
msgstr ""

#. module: event_seat_reserve
#: model:ir.model,name:event_seat_reserve.model_event_event_ticket
msgid "Event Ticket"
msgstr ""

#. module: event_seat_reserve
#: model:ir.model.fields,field_description:event_seat_reserve.field_event_event__seats_reserved_unconfirmed
#: model:ir.model.fields,field_description:event_seat_reserve.field_event_event_ticket__seats_reserved_unconfirmed
msgid "Number of Reserved Attendees"
msgstr ""

#. module: event_seat_reserve
#: model:ir.model.fields.selection,name:event_seat_reserve.selection__event_registration__state__reserved
#: model_terms:ir.ui.view,arch_db:event_seat_reserve.view_event_regview_registration_searchistration_form
msgid "Reserved"
msgstr ""

#. module: event_seat_reserve
#: model_terms:ir.ui.view,arch_db:event_seat_reserve.view_event_registration_form
msgid "Set To Reserved"
msgstr ""

#. module: event_seat_reserve
#: model:ir.model.fields,field_description:event_seat_reserve.field_event_registration__state
msgid "Status"
msgstr ""
35 changes: 35 additions & 0 deletions event_seat_reserve/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * event_seat_reserve
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-25 13:30+0000\n"
"PO-Revision-Date: 2024-07-25 13:30+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: event_seat_reserve
#: model:ir.model.fields,field_description:event_seat_reserve.field_event_event__seats_reserved_unconfirmed
#: model:ir.model.fields,field_description:event_seat_reserve.field_event_event_ticket__seats_reserved_unconfirmed
msgid "Number of Reserved Attendees"
msgstr "Quantité de participants réservés"

#. module: event_seat_reserve
#: model:ir.model.fields.selection,name:event_seat_reserve.selection__event_registration__state__reserved
#: model_terms:ir.ui.view,arch_db:event_seat_reserve.view_event_regview_registration_searchistration_form
msgid "Reserved"
msgstr "Réservé"

#. module: event_seat_reserve
#: model_terms:ir.ui.view,arch_db:event_seat_reserve.view_event_registration_form
msgid "Set To Reserved"
msgstr "Définir comme réservé"


3 changes: 3 additions & 0 deletions event_seat_reserve/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import event_event
from . import event_registration
from . import event_ticket
49 changes: 49 additions & 0 deletions event_seat_reserve/models/event_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0).
from odoo import api, fields, models


class EventEvent(models.Model):
_inherit = "event.event"

seats_reserved_unconfirmed = fields.Integer(
string="Number of Reserved Attendees",

Choose a reason for hiding this comment

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

Suggested change
string="Number of Reserved Attendees",
string="Number of Unconfirmed Reserved Attendees",

store=False,
readonly=True,
compute="_compute_seats",
)

@api.depends("seats_max", "registration_ids.state", "registration_ids.active")
def _compute_seats(self):
# Override the original method to add the new state and the compute for the new field
imlopes marked this conversation as resolved.
Show resolved Hide resolved
# initialize fields to 0
res = super()._compute_seats()
counts = dict()
if self.ids:
groups = self.env["event.registration"].read_group(
[
("event_id", "in", self.ids),
("state", "=", "reserved"),
],
groupby=["event_id"],
fields=["event_id"],
)
counts = {g["event_id"][0]: g["event_id_count"] for g in groups}

# compute seats_available and expected
for event in self:
event.seats_reserved_unconfirmed = counts.get(event.id, 0)
if event.seats_max > 0:
event.seats_available = event.seats_max - (
event.seats_reserved
+ event.seats_used
+ event.seats_reserved_unconfirmed
)

event.seats_expected = (
event.seats_unconfirmed
+ event.seats_reserved_unconfirmed
+ event.seats_reserved
+ event.seats_used
)
return res
33 changes: 33 additions & 0 deletions event_seat_reserve/models/event_registration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0).
import logging

from odoo import fields, models
from odoo.tools import config

_logger = logging.getLogger(__name__)


class EventRegistration(models.Model):
_inherit = "event.registration"

state = fields.Selection(
selection_add=[("reserved", "Reserved"), ("open",)],
ondelete={"reserved": "set default"},
)

def action_set_reserved(self):
if config["test_enable"] and not self.env.context.get(
"test_event_seat_reserve"
):
_logger.info("Test mode is enabled, you cannot reserve a registration.")
return True

Check warning on line 24 in event_seat_reserve/models/event_registration.py

View check run for this annotation

Codecov / codecov/patch

event_seat_reserve/models/event_registration.py#L23-L24

Added lines #L23 - L24 were not covered by tests
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Author

Choose a reason for hiding this comment

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

Some tests are failing on the two others PR's because when create a sale, normally the event. registration still on draft state but it's no more the case with these modules. So to avoid failing...

self.write({"state": "reserved"})

def write(self, vals):
res = super().write(vals)
confirming = vals.get("state") == "reserved"
if confirming:
self.event_id._check_seats_availability()
self.event_ticket_id._check_seats_availability()
return res
41 changes: 41 additions & 0 deletions event_seat_reserve/models/event_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3.0).
from odoo import api, fields, models


class EventTicket(models.Model):
_inherit = "event.event.ticket"

seats_reserved_unconfirmed = fields.Integer(
string="Number of Reserved Attendees", compute="_compute_seats"
)

@api.depends("seats_max", "registration_ids.state", "registration_ids.active")
def _compute_seats(self):
"""Determine reserved, available, reserved but unconfirmed and used seats."""
imlopes marked this conversation as resolved.
Show resolved Hide resolved
# initialize fields to 0 + compute seats availability
res = super()._compute_seats()
counts = dict()

Check warning on line 18 in event_seat_reserve/models/event_ticket.py

View check run for this annotation

Codecov / codecov/patch

event_seat_reserve/models/event_ticket.py#L17-L18

Added lines #L17 - L18 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

This compute method is not covered by tests.
Could we add a test to check the seats_reserved_unconfirmed value?

if self.ids:
groups = self.env["event.registration"].read_group(

Check warning on line 20 in event_seat_reserve/models/event_ticket.py

View check run for this annotation

Codecov / codecov/patch

event_seat_reserve/models/event_ticket.py#L20

Added line #L20 was not covered by tests
[
("event_ticket_id", "in", self.ids),
("state", "=", "reserved"),
],
groupby=["event_ticket_id"],
fields=["event_ticket_id"],
)
counts = {
g["event_ticket_id"][0]: g["event_ticket_id_count"] for g in groups
}

# compute seats_available
for ticket in self:
ticket.seats_reserved_unconfirmed = counts.get(ticket.id, 0)

Check warning on line 34 in event_seat_reserve/models/event_ticket.py

View check run for this annotation

Codecov / codecov/patch

event_seat_reserve/models/event_ticket.py#L34

Added line #L34 was not covered by tests
if ticket.seats_max > 0:
ticket.seats_available = ticket.seats_max - (

Check warning on line 36 in event_seat_reserve/models/event_ticket.py

View check run for this annotation

Codecov / codecov/patch

event_seat_reserve/models/event_ticket.py#L36

Added line #L36 was not covered by tests
ticket.seats_reserved
+ ticket.seats_used
+ ticket.seats_reserved_unconfirmed
)
return res

Check warning on line 41 in event_seat_reserve/models/event_ticket.py

View check run for this annotation

Codecov / codecov/patch

event_seat_reserve/models/event_ticket.py#L41

Added line #L41 was not covered by tests
1 change: 1 addition & 0 deletions event_seat_reserve/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Italo LOPES <italo.lopes@camptocamp.com>
1 change: 1 addition & 0 deletions event_seat_reserve/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to make a pre-reserve on registrations.
Binary file added event_seat_reserve/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading