| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo.http import request |
| 4 |
|
| 5 |
from odoo.addons.website_sale.controllers.payment import PaymentPortal |
| 6 |
|
| 7 |
|
| 8 |
class PaymentPortalOnsite(PaymentPortal): |
| 9 |
|
| 10 |
def _validate_transaction_for_order(self, transaction, sale_order): |
| 11 |
""" |
| 12 |
Throws a ValidationError if the user tries to pay for a ticket which isn't available |
| 13 |
""" |
| 14 |
super()._validate_transaction_for_order(transaction, sale_order) |
| 15 |
registration_domain = [ |
| 16 |
('sale_order_id', '=', sale_order.id), |
| 17 |
('event_ticket_id', '!=', False), |
| 18 |
('state', '!=', 'cancel'), |
| 19 |
] |
| 20 |
registrations_per_event = request.env['event.registration'].sudo()._read_group( |
| 21 |
registration_domain, |
| 22 |
['event_id'], ['id:recordset'] |
| 23 |
) |
| 24 |
for event, registrations in registrations_per_event: |
| 25 |
count_per_slot_ticket = request.env['event.registration'].sudo()._read_group( |
| 26 |
[('id', 'in', registrations.ids)], |
| 27 |
['event_slot_id', 'event_ticket_id'], ['__count'] |
| 28 |
) |
| 29 |
event._verify_seats_availability([ |
| 30 |
(slot, ticket, count) |
| 31 |
for slot, ticket, count in count_per_slot_ticket |
| 32 |
]) |