selvi b04e39b202
Some checks failed
CI / Brand-leak check (push) Has been cancelled
CI / flake8 / pylint-odoo / manifest completeness (push) Has been cancelled
CI / Install all modules with --test-enable (push) Has been cancelled
event qr code updated
2026-10-05 22:12:08 +05:30

68 lines
2.7 KiB
Python

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()
def _redirect_to_login_if_public(path):
"""Manual login-required redirect - see community_classifieds for why this
is needed instead of auth='user' (a bug in this Odoo version's own
SessionExpiredException -> login-redirect handling)."""
if request.env.user._is_public():
return request.redirect(f'/web/login?redirect={path}')
return None
class EventCheckinController(http.Controller):
@http.route(['/event/checkin', '/event/checkin/<int:event_id>'], type='http', auth='public', website=True)
def checkin_page(self, event_id=None, **kwargs):
redirect = _redirect_to_login_if_public('/event/checkin')
if redirect:
return redirect
_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:
names = [r.name or r.partner_id.name or 'Unknown' for r in registration]
display_name = names[0] if len(names) == 1 else f"{names[0]} + {len(names)-1} others"
result.update(
name=display_name,
event=registration[0].event_id.name,
ticket_ref=registration[0].ticket_ref,
)
if status == 'ok':
registration.action_check_in()
return result
@http.route(['/event/checkin/dashboard/<int:event_id>'], 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')),
}