from odoo import fields, http from odoo.exceptions import AccessDenied from odoo.http import request def _require_registration_desk(): if not request.env.user.has_group('event.group_event_registration_desk'): raise AccessDenied() class EventCheckinController(http.Controller): @http.route(['/event/checkin', '/event/checkin/'], type='http', auth='user', website=True) def checkin_page(self, event_id=None, **kwargs): _require_registration_desk() events = request.env['event.event'].search([('date_end', '>=', fields.Datetime.now())]) event = request.env['event.event'].browse(event_id) if event_id else events[:1] return request.render('event_qr_ticketing.checkin_page', { 'events': events, 'event': event, }) @http.route(['/event/checkin/scan'], type='jsonrpc', auth='user', website=True) def checkin_scan(self, value=None, manual=False, **kwargs): _require_registration_desk() Registration = request.env['event.registration'] if manual: status, registration = Registration._lookup_by_ticket_ref((value or '').strip()) else: status, registration = Registration._verify_scanned_token(value) result = {'status': status} if registration: result.update( name=registration.name or registration.partner_id.name, event=registration.event_id.name, ticket_ref=registration.ticket_ref, ) if status == 'ok': registration.action_check_in() return result @http.route(['/event/checkin/dashboard/'], type='jsonrpc', auth='user', website=True) def checkin_dashboard(self, event_id, **kwargs): _require_registration_desk() event = request.env['event.event'].browse(event_id) registrations = event.registration_ids.filtered(lambda r: r.state in ('open', 'done')) return { 'registered': len(registrations), 'checked_in': len(registrations.filtered('checked_in')), }