[FIX] website_event: Ordering more tickets than available seats

Steps to reproduce the bug:

- Let's consider an event E with Maximum Attendees = 2 and Autoconfirm
- Create two kind of tickets Premium with Maximum available seats = 2 and Normal with Maximum available seats = 2
- Go to the website and register for E
- Take two tickets Premium and two tickets Normal

Bug:

Odoo gave the possibility to buy for tickets for E even if the Maximum Attendees was 2
and Odoo never autoconfirm these tickets.

opw:2214576

closes odoo/odoo#48567

X-original-commit: ff49afc6c71285cf90f720f2e97f8adedee7204b
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2020-03-30 14:34:55 +00:00
parent 1daf8eb127
commit e4be7ad7a6
3 changed files with 24 additions and 4 deletions
+8 -1
View File
@@ -299,9 +299,16 @@ class WebsiteEventController(http.Controller):
@http.route(['/event/<model("event.event"):event>/registration/new'], type='json', auth="public", methods=['POST'], website=True)
def registration_new(self, event, **post):
tickets = self._process_tickets_form(event, post)
availability_check = True
if event.seats_availability == 'limited':
ordered_seats = 0
for ticket in tickets:
ordered_seats += ticket['quantity']
if event.seats_available < ordered_seats:
availability_check = False
if not tickets:
return False
return request.env['ir.ui.view'].render_template("website_event.registration_attendee_details", {'tickets': tickets, 'event': event})
return request.env['ir.ui.view'].render_template("website_event.registration_attendee_details", {'tickets': tickets, 'event': event, 'availability_check': availability_check})
def _process_attendees_form(self, event, form_details):
""" Process data posted from the attendee details form.
@@ -165,6 +165,11 @@ msgstr ""
msgid "<span>Online Events</span>"
msgstr ""
#. module: website_event
#: model_terms:ir.ui.view,arch_db:website_event.registration_attendee_details
msgid "<strong> You ordered more tickets than available seats</strong>"
msgstr ""
#. module: website_event
#: model_terms:ir.ui.view,arch_db:website_event.index_sidebar_photos
msgid "A past event"
@@ -222,6 +227,11 @@ msgstr ""
msgid "Author"
msgstr ""
#. module: website_event
#: model_terms:ir.ui.view,arch_db:website_event.registration_template
msgid "Available seats: "
msgstr ""
#. module: website_event
#: model_terms:ir.ui.view,arch_db:website_event.registration_attendee_details
msgid "Cancel"
@@ -612,7 +612,7 @@
</div>
<div class="row no-gutters">
<div class="col-md-4 offset-md-8 py-2 pl-md-0 pr-md-2">
<button type="submit" class="btn btn-primary o_wait_lazy_js btn-block a-submit" disabled="" t-attf-id="#{event.id}">Register</button>
<button type="submit" class="btn btn-primary o_wait_lazy_js btn-block a-submit" disabled="" t-attf-id="#{event.id}">Register<t t-if="event.seats_availability != 'unlimited'">(Available seats: <t t-esc="event.seats_available"/>)</t></button>
</div>
</div>
</div>
@@ -665,7 +665,7 @@
</div>
<t t-set="counter_type" t-value="1"/>
<t t-set="counter" t-value="0"/>
<t t-foreach="tickets" t-as="ticket">
<t t-foreach="tickets" t-as="ticket" t-if="availability_check">
<t t-foreach="range(1, ticket['quantity'] + 1)" t-as="att_counter" name="attendee_loop">
<t t-set="counter" t-value="counter + 1"/>
<div class="modal-body bg-light border-bottom">
@@ -689,9 +689,12 @@
</t>
<t t-set="counter_type" t-value="counter_type + 1"/>
</t>
<t t-if="not availability_check">
<strong> You ordered more tickets than available seats</strong>
</t>
<div class="modal-footer border-0 justify-content-between">
<button type="button" class="btn btn-secondary js_goto_event" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Continue</button>
<button type="submit" class="btn btn-primary" t-if="availability_check">Continue</button>
</div>
</div>
</form>