Skip to content

Commit

Permalink
fix-9127: Add the unique ticket code into the downlad CSV file (#9133)
Browse files Browse the repository at this point in the history
* fix-9127: Add the unique ticket code into the downlad CSV file

* fix-9127: Add the unique ticket code into the downlad CSV file

* fix-9127: Add the unique ticket code into the downlad CSV file
  • Loading branch information
Hieu Lam - TMA authored Mar 25, 2024
1 parent 7b0fdd1 commit 2d8025e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
12 changes: 9 additions & 3 deletions app/api/helpers/csv_jobs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def export_orders_csv(orders):
return rows


def get_order_ticket_data(order, ticket):
def get_order_ticket_data(attendee, order, ticket):
"""Get order ticket data"""
data = {}
if not order:
Expand All @@ -104,6 +104,12 @@ def get_order_ticket_data(order, ticket):
'City': '',
'Zipcode': '',
}
ticketId = ''
if order.identifier:
if not attendee.identifier:
ticketId = order.identifier + '-' + attendee.get_new_identifier()
else:
ticketId = order.identifier + '-' + attendee.identifier

data = {
'Order#': str(order.get_invoice_number()),
Expand All @@ -113,7 +119,7 @@ def get_order_ticket_data(order, ticket):
'Status': str(order.status) if order.status else '-',
'Payment Type': str(order.paid_via) if order.paid_via else '',
'Payment Mode': str(order.payment_mode) if order.payment_mode else '',
'Ticket ID': str(order.identifier) if order.identifier else '',
'Ticket ID': ticketId,
}

if ticket:
Expand Down Expand Up @@ -162,7 +168,7 @@ def get_ticket_data(ticket):

def get_attendee_data(attendee, custom_forms, attendee_form_dict):
"""Get attendee data from attendee object"""
order_ticket_data = get_order_ticket_data(attendee.order, attendee.ticket)
order_ticket_data = get_order_ticket_data(attendee, attendee.order, attendee.ticket)
data = {
**order_ticket_data,
'Email': '',
Expand Down
1 change: 1 addition & 0 deletions app/api/schema/attendees.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def validate_json(self, data, original_data):
is_discount_applied = fields.Boolean(allow_none=True)
is_access_code_applied = fields.Boolean(allow_none=True)
tag_id = fields.Int(allow_none=True)
identifier = fields.Str(dump_only=True)
event = Relationship(
self_view='v1.attendee_event',
self_view_kwargs={'id': '<id>'},
Expand Down
19 changes: 18 additions & 1 deletion app/models/ticket_holder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import base64
import binascii
import os
from dataclasses import dataclass
from datetime import datetime
from io import BytesIO
Expand All @@ -11,6 +13,11 @@
from app.models.base import SoftDeletionModel


def get_new_id():
"""Generate a new id for a ticket holder."""
return str(binascii.b2a_hex(os.urandom(3)), 'utf-8')


@dataclass(init=False, unsafe_hash=True)
class TicketHolder(SoftDeletionModel):
__tablename__ = "ticket_holders"
Expand Down Expand Up @@ -90,6 +97,7 @@ class TicketHolder(SoftDeletionModel):
is_access_code_applied: bool = db.Column(db.Boolean, default=False)
tag_id: int = db.Column(db.Integer, db.ForeignKey('tags.id', ondelete='CASCADE'))
tag = db.relationship('Tag', backref='ticket_holders')
identifier = db.Column(db.String, default=get_new_id)

@property
def name(self):
Expand All @@ -108,7 +116,11 @@ def qr_code(self):
box_size=10,
border=0,
)
qr.add_data(self.order.identifier)
identifier = self.identifier
if not self.identifier:
identifier = get_new_id()

qr.add_data(self.order.identifier + "-" + identifier)
qr.make(fit=True)
img = qr.make_image()

Expand Down Expand Up @@ -143,3 +155,8 @@ def pdf_url_path(self) -> str:
+ self.order.identifier
+ '.pdf'
)

@staticmethod
def get_new_identifier():
"""Generate a new identifier for the ticket holder."""
return str(binascii.b2a_hex(os.urandom(3)), 'utf-8')
6 changes: 5 additions & 1 deletion app/templates/pdf/attendees_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ <h3 style="text-align:center;">{{ holders[0].event.name }} - {{ ("Attendees List
{% else %}
{{ "Free Ticket" }} <br>
{% endif %}
{{ holder.order.identifier }}<br>
{% if holder.identifier %}
{{ holder.order.identifier }} - {{ holder.identifier }} <br>
{% else %}
{{ holder.order.identifier }} - {{ holder.get_new_identifier()}}<br>
{% endif %}
{{ holder.ticket.name }}<br>
{% if holder.is_checked_in %}
{{ ("Checked In") }}<br>
Expand Down
27 changes: 27 additions & 0 deletions migrations/versions/rev-2024-03-23-08:47:20-e7e952b58504_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""empty message
Revision ID: e7e952b58504
Revises: 414c776ae509
Create Date: 2024-03-23 08:47:20.614874
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e7e952b58504'
down_revision = '414c776ae509'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('ticket_holders', sa.Column('identifier', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('ticket_holders', 'identifier')
# ### end Alembic commands ###

0 comments on commit 2d8025e

Please sign in to comment.