Repository: fossasia/open-event-server

Issue:
Add the unique ticket code into the downlad CSV file
The CSV download file of the attendee list does not include the numbers on the QR Code. Please add this field "Ticket-ID".

The ticket ID has the following format: 135ccbd7-9b23-4a52-a7fd-326fec1b2c1c
Whereas the order has a format like this: #O1691408152-34896

![Screenshot from 2024-03-18 11-40-16](https://github.com/fossasia/open-event-server/assets/1583873/97568f6a-bd5a-4706-899f-64400c2f4da6)

Expected: The exported CSV should have a table column "Ticket ID" with the ticket ID number that is encoded in the QR code as well.

![Screenshot from 2024-03-18 11-48-30](https://github.com/fossasia/open-event-server/assets/1583873/be8e84dd-7088-4a71-8d03-a89d4414904e)



Discussion:
Hi @mariobehling

I have a query:
When will the ticket ID column data be generate? when the ticket is created by events or when the attendee purchasing the ticket?

Please help me confirm it. Thanks
> I have a query: When will the ticket ID column data be generate? when the ticket is created by events or when the attendee purchasing the ticket?
> 
> Please help me confirm it. Thanks

The CSV is generated when the user (organiser) clicks "Export as CSV". Into this CSV generation process one column ticket ID is missing.

As you can see in the screenshot below. The web UI already shows the ticket ID in the table column "Order". Every order has an order number (it can be several tickets in one order) and every ticket has a ticket ID (the long string that we see also in the table).

![Screenshot from 2024-03-19 10-17-44](https://github.com/fossasia/open-event-server/assets/1583873/27d1f7d8-3583-4a81-841a-29474653c697)



Currently the ticket ID and the QR code are 90% identical, but there is an additional number at the end of the ticket ID in the QR code which should not be there.

Ticket ID in download CSV: b8f78f85-b602-43dc-b639-fd2e5114de56
Ticket ID in QR code: b8f78f85-b602-43dc-b639-fd2e5114de56-960

![Screenshot from 2024-03-21 09-59-36](https://github.com/fossasia/open-event-server/assets/1583873/8556c32f-8387-4b2e-8704-90a1cf4d4ff1)

@lthanhhieu Please compare here: https://test.eventyay.com/orders/b8f78f85-b602-43dc-b639-fd2e5114de56/view
(This is an old ticket from you)

Resolving patch:
diff --git a/app/api/helpers/csv_jobs_util.py b/app/api/helpers/csv_jobs_util.py
--- a/app/api/helpers/csv_jobs_util.py
+++ b/app/api/helpers/csv_jobs_util.py
@@ -107,7 +107,7 @@ def get_order_ticket_data(attendee, order, ticket):
     ticketId = ''
     if order.identifier:
         if not attendee.identifier:
-            ticketId = order.identifier + '-' + attendee.get_new_identifier()
+            ticketId = order.identifier + '-' + str(attendee.id)
         else:
             ticketId = order.identifier + '-' + attendee.identifier
 
diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py
--- a/app/models/ticket_holder.py
+++ b/app/models/ticket_holder.py
@@ -118,7 +118,7 @@ def qr_code(self):
         )
         identifier = self.identifier
         if not self.identifier:
-            identifier = get_new_id()
+            identifier = str(self.id)
 
         qr.add_data(self.order.identifier + "-" + identifier)
         qr.make(fit=True)
@@ -155,8 +155,3 @@ 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')


Test patch: