Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payment date to registrations API #6287

Merged
merged 3 commits into from Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,7 +6,7 @@
# LICENSE file for more details.

from flask import request
from sqlalchemy.orm import selectinload, undefer
from sqlalchemy.orm import joinedload, selectinload, undefer
from webargs import fields
from werkzeug.exceptions import NotFound

Expand Down Expand Up @@ -75,6 +75,7 @@ def _process(self):
.filter(~Registration.is_deleted)
.options(selectinload('data').joinedload('field_data'),
selectinload('tags'),
joinedload('transaction'),
undefer('occupied_slots'))
.all())
return CheckinRegistrationSchema(many=True, exclude=('registration_data',)).jsonify(registrations)
Expand All @@ -94,6 +95,10 @@ def _process_args(self):
registration_id = request.view_args['registration_id']
self.registration = (Registration.query
.with_parent(self.regform)
.options(selectinload('data').joinedload('field_data'),
selectinload('tags'),
joinedload('transaction'),
undefer('occupied_slots'))
.filter_by(id=registration_id, is_deleted=False)
.first_or_404())

Expand Down
Expand Up @@ -9,6 +9,7 @@ full_name: Guinea Pig
id: <id>
is_paid: false
occupied_slots: 1
payment_date: null
price: 0
regform_id: <id>
registration_data:
Expand Down
Expand Up @@ -9,6 +9,7 @@
id: <id>
is_paid: false
occupied_slots: 1
payment_date: null
price: 0
regform_id: <id>
registration_date: <timestamp>
Expand Down
10 changes: 8 additions & 2 deletions indico/modules/events/registration/schemas.py
Expand Up @@ -62,18 +62,24 @@ class CheckinRegistrationSchema(mm.SQLAlchemyAutoSchema):
class Meta:
model = Registration
fields = ('id', 'regform_id', 'event_id', 'full_name', 'email', 'state', 'checked_in', 'checked_in_dt',
'checkin_secret', 'is_paid', 'price', 'currency', 'formatted_price', 'tags', 'occupied_slots',
'registration_date', 'registration_data')
'checkin_secret', 'is_paid', 'price', 'payment_date', 'currency', 'formatted_price', 'tags',
'occupied_slots', 'registration_date', 'registration_data')

regform_id = fields.Int(attribute='registration_form_id')
full_name = fields.Str(attribute='display_full_name')
state = fields.Enum(RegistrationState)
checkin_secret = fields.UUID(attribute='ticket_uuid')
payment_date = fields.Method('_get_payment_date')
formatted_price = fields.Function(lambda reg: reg.render_price())
tags = fields.Function(lambda reg: sorted(t.title for t in reg.tags))
registration_date = fields.DateTime(attribute='submitted_dt')
registration_data = fields.Method('_get_registration_data')

def _get_payment_date(self, registration):
if registration.is_paid and (transaction := registration.transaction):
return fields.DateTime().serialize('timestamp', transaction)
return None

def _get_filenames(self, registration):
"""Extract filenames from file fields."""
return {r.field_data.field.id: r.filename
Expand Down