Skip to content

Commit

Permalink
Merge pull request #2 from grupoesoc/event_seats_per_registration
Browse files Browse the repository at this point in the history
[8.0][event_registration_seat_limit] Limit how many seats can each registration have
  • Loading branch information
dreispt committed Feb 8, 2016
2 parents a6c0549 + 313c488 commit 4732125
Show file tree
Hide file tree
Showing 11 changed files with 800 additions and 0 deletions.
67 changes: 67 additions & 0 deletions event_registration_seat_limit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

====================================
Seats limits in events registrations
====================================

This module was written to extend the functionality of events to support
setting a maximum and a minimum of seats per registration.

If you have an event where you need to know the name of every attendant, or
where attendants can come only with one companion, you can configure it.

Usage
=====

To use this module, you need to:

* Enter an event form.
* Use the new fields in the *Registrations* tab.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/199/8.0

For further information, please visit:

* https://www.odoo.com/forum/help-1

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 smashing it by providing a detailed and welcomed
feedback `here
<https://github.com/OCA/event/issues/new?body=module:%20event_registration_seat_limit%0Aversion:%208.0.4.0.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
=======

Contributors
------------

* `Jairo Llopis <mailto:j.llopis@grupoesoc.es>`_.

Icon
----

* Original icon from Odoo event module
* https://openclipart.org/detail/19350/classroom-seat-layouts

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit http://odoo-community.org.
5 changes: 5 additions & 0 deletions event_registration_seat_limit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

from . import models, tests
21 changes: 21 additions & 0 deletions event_registration_seat_limit/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

{
"name": "Seats per registration in events",
"version": "8.0.4.0.0",
"category": "Tools",
"author": "Grupo ESOC, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "http://www.grupoesoc.es",
"installable": True,
"application": False,
"summary": "Limit seats per registration",
"depends": [
"event",
],
"data": [
"views/event.xml",
],
}
47 changes: 47 additions & 0 deletions event_registration_seat_limit/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

from openerp import _, exceptions


class SeatsPerRegistrationValidationError(exceptions.ValidationError):
"""Base class for this module's validation errors."""
def __init__(self, *args, **kwargs):
self._args, self._kwargs = args, kwargs
value = self._message()
super(SeatsPerRegistrationValidationError, self).__init__(value)

def _message(self):
"""Format the message."""
return self.__doc__.format(*self._args, **self._kwargs)


class NeedAtLeastOneParticipant(SeatsPerRegistrationValidationError):
__doc__ = _("You need at least one participant per registration.")


class MaxSmallerThanMin(SeatsPerRegistrationValidationError):
__doc__ = _("The maximum of participants per registration cannot "
"be smaller than the minimum.")


class MaxPerRegisterBiggerThanMaxPerEvent(SeatsPerRegistrationValidationError):
__doc__ = _("The maximum of participants per registration "
"cannot be bigger than the maximum of participants "
"for this event.")


class PreviousRegistrationsFail(SeatsPerRegistrationValidationError):
__doc__ = _("There are already registrations that don't fit in "
"the new limits of participants per registration. "
"Change them before setting the limits. "
"The error was: {.value}")


class TooFewParticipants(SeatsPerRegistrationValidationError):
__doc__ = _("You cannot register less than %d participants.")


class TooManyParticipants(SeatsPerRegistrationValidationError):
__doc__ = _("You cannot register more than %d participants.")
111 changes: 111 additions & 0 deletions event_registration_seat_limit/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * event_seats_per_regsitration
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0-20150225\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-11 12:31+0100\n"
"PO-Revision-Date: 2015-12-11 12:31+0100\n"
"Last-Translator: Jairo Llopis <j.llopis@grupoesoc.es>\n"
"Language-Team: \n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.5\n"

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

#. module: event_registration_seat_limit
#: model:ir.model,name:event_registration_seat_limit.model_event_registration
msgid "Event Registration"
msgstr "Registros al evento"

#. module: event_registration_seat_limit
#: field:event.event,registration_seats_max:0
msgid "Maximum of participants per registration"
msgstr "Máximo de participantes por registro"

#. module: event_registration_seat_limit
#: field:event.event,registration_seats_min:0
msgid "Minimum of participants per registration"
msgstr "Mínimo de participantes por registro"

#. module: event_registration_seat_limit
#: help:event.event,registration_seats_min:0
msgid ""
"Registrations with less than this number of participants will be forbidden."
msgstr ""
"Los registros con menos de este número de participantes estarán prohibidos."

#. module: event_registration_seat_limit
#: help:event.event,registration_seats_max:0
msgid ""
"Registrations with more than this number of participants will be forbidden. "
"Set 0 to ignore this setting."
msgstr ""
"Los registros con más de este número de participantes estarán prohibidos. Si "
"se pone 0, se ignora esta opción."

#. module: event_registration_seat_limit
#: code:addons/event_registration_seat_limit/exceptions.py:30
#, python-format
msgid ""
"The maximum of participants per registration cannot be bigger than the "
"maximum of participants for this event."
msgstr ""
"El máximo de participantes por registro no puede ser superior al máximo de "
"participantes para el evento."

#. module: event_registration_seat_limit
#: code:addons/event_registration_seat_limit/exceptions.py:25
#, python-format
msgid ""
"The maximum of participants per registration cannot be smaller than the "
"minimum."
msgstr ""
"El máximo de participantes por registro no puede ser inferior al mínimo."

#. module: event_registration_seat_limit
#: code:addons/event_registration_seat_limit/exceptions.py:36
#, python-format
msgid ""
"There are already registrations that don't fit in the new limits of "
"participants per registration. Change them before setting the limits. The "
"error was: {.value}"
msgstr ""
"Ya hay registros que no encajan en los nuevos límites de participantes por "
"registro. Cámbielos antes de establecer estos límites. El error fue: {.value}"

#. module: event_registration_seat_limit
#: code:addons/event_registration_seat_limit/exceptions.py:43
#, python-format
msgid "You cannot register less than %d participants."
msgstr "No puede registrar menos de %d participantes."

#. module: event_registration_seat_limit
#: code:addons/event_registration_seat_limit/exceptions.py:47
#, python-format
msgid "You cannot register more than %d participants."
msgstr "No puede registrar más de %d participantes."

#. module: event_registration_seat_limit
#: code:addons/event_registration_seat_limit/exceptions.py:21
#, python-format
msgid "You need at least one participant per registration."
msgstr "Necesita al menos un participante por registro."

#. module: event_registration_seat_limit
#: view:event.event:event_registration_seat_limit.event_form
msgid ""
"{\"event_id\": active_id,\n"
" \"default_nb_register\": registration_seats_min}"
msgstr ""
"{\"event_id\": active_id,\n"
" \"default_nb_register\": registration_seats_min}"
76 changes: 76 additions & 0 deletions event_registration_seat_limit/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U.

from openerp import api, fields, models
from . import exceptions


class Event(models.Model):
"""Events enhaced with participants per registration limits."""
_inherit = "event.event"

registration_seats_max = fields.Integer(
"Maximum of participants per registration",
default=0,
help="Registrations with more than this number of participants will "
"be forbidden. Set 0 to ignore this setting.")

registration_seats_min = fields.Integer(
"Minimum of participants per registration",
default=1,
help="Registrations with less than this number of participants will "
"be forbidden.")

@api.multi
@api.constrains("registration_seats_max",
"registration_seats_min",
"seats_max")
def _check_seats_per_registration_limits(self):
"""Ensure you are not setting an invalid maximum."""
for s in self:
if s.registration_seats_min < 1:
raise exceptions.NeedAtLeastOneParticipant()

if s.registration_seats_max and (s.registration_seats_max <
s.registration_seats_min):
raise exceptions.MaxSmallerThanMin()

if s.seats_max and s.registration_seats_max > s.seats_max:
raise exceptions.MaxPerRegisterBiggerThanMaxPerEvent()

try:
s.registration_ids._check_seats_per_registration_limits()
except exceptions.SeatsPerRegistrationValidationError as error:
raise exceptions.PreviousRegistrationsFail(error)


class EventRegistration(models.Model):
"""Event registrations must force the limits imposed in the event."""
_inherit = "event.registration"

@api.multi
@api.constrains("event_id", "nb_register")
def _check_seats_per_registration_limits(self):
"""Ensure the number of reserved seats fits in the limits."""
for s in self:
if s.event_id.registration_seats_max:
if s.nb_register > s.event_id.registration_seats_max:
raise exceptions.TooManyParticipants(
s.event_id.registration_seats_max)

if s.nb_register < s.event_id.registration_seats_min:
raise exceptions.TooFewParticipants(
s.event_id.registration_seats_min)

def _default_seats(self):
"""Set the default number of participants per registration."""
# Normalize cases when there's no record
event = self.event_id or self.event_id.browse(
self.env.context.get("active_id", False))

return event.registration_seats_min or 1

# Default seats to the minimum
nb_register = fields.Integer(
default=_default_seats)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4732125

Please sign in to comment.