Repository: fossasia/open-event-server

Issue:
CSV Ticket Export: Add Payment Info
In the CSV export of ticket holders the payment info is not added. Therefore please add the following:
* Payment Method
* Billing Info (Name, Email, Company, Address, Tax ID, whatever is shared)



Discussion:

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
@@ -9,12 +9,20 @@ def export_orders_csv(orders):
         'Order Date',
         'Status',
         'Payment Type',
+        'Payment Mode',
         'Total Amount',
         'Quantity',
         'Discount Code',
         'First Name',
         'Last Name',
         'Email',
+        'Tax ID',
+        'Address',
+        'Company',
+        'Country',
+        'State',
+        'City',
+        'Zipcode',
     ]
 
     rows = [headers]
@@ -25,6 +33,7 @@ def export_orders_csv(orders):
                 str(order.created_at) if order.created_at else '',
                 str(order.status) if order.status else '',
                 str(order.paid_via) if order.paid_via else '',
+                str(order.payment_mode) if order.payment_mode else '',
                 str(order.amount) if order.amount else '',
                 str(order.tickets_count),
                 str(order.discount_code.code) if order.discount_code else '',
@@ -33,6 +42,13 @@ def export_orders_csv(orders):
                 else '',
                 str(order.user.last_name) if order.user and order.user.last_name else '',
                 str(order.user.email) if order.user and order.user.email else '',
+                str(order.tax_business_info) if order.tax_business_info else '',
+                str(order.address) if order.address else '',
+                str(order.company) if order.company else '',
+                str(order.country) if order.country else '',
+                str(order.state) if order.state else '',
+                str(order.city) if order.city else '',
+                str(order.zipcode) if order.zipcode else '',
             ]
             rows.append(column)
 
@@ -46,16 +62,23 @@ def export_attendees_csv(attendees, custom_forms):
         'Order Date',
         'Status',
         'Payment Type',
+        'Payment Mode',
         'Ticket Name',
         'Ticket Price',
         'Ticket Type',
+        'Tax ID',
+        'Address',
+        'Company',
+        'Country',
+        'State',
+        'City',
+        'Zipcode',
     ]
 
     for fields in custom_forms:
         headers.append(fields.name)
 
     rows = [headers]
-
     for attendee in attendees:
         column = [
             str(attendee.order.get_invoice_number()) if attendee.order else '-',
@@ -65,6 +88,9 @@ def export_attendees_csv(attendees, custom_forms):
             str(attendee.order.status)
             if attendee.order and attendee.order.status
             else '-',
+            str(attendee.order.paid_via)
+            if attendee.order and attendee.order.paid_via
+            else '',
             str(attendee.order.payment_mode)
             if attendee.order and attendee.order.payment_mode
             else '',
@@ -73,6 +99,15 @@ def export_attendees_csv(attendees, custom_forms):
             if attendee.ticket and attendee.ticket.price
             else '0',
             str(attendee.ticket.type) if attendee.ticket and attendee.ticket.type else '',
+            str(attendee.order.tax_business_info)
+            if attendee.order.tax_business_info
+            else '',
+            str(attendee.order.address) if attendee.order.address else '',
+            str(attendee.order.company) if attendee.order.company else '',
+            str(attendee.order.country) if attendee.order.country else '',
+            str(attendee.order.state) if attendee.order.state else '',
+            str(attendee.order.city) if attendee.order.city else '',
+            str(attendee.order.zipcode) if attendee.order.zipcode else '',
         ]
         for field in custom_forms:
             if field.is_complex:


Test patch:
diff --git a/tests/all/integration/api/helpers/test_csv_jobs_util.py b/tests/all/integration/api/helpers/test_csv_jobs_util.py
--- a/tests/all/integration/api/helpers/test_csv_jobs_util.py
+++ b/tests/all/integration/api/helpers/test_csv_jobs_util.py
@@ -22,16 +22,18 @@ def test_export_orders_csv(self):
             test_order.amount = 2
             field_data = export_orders_csv([test_order])
             self.assertEqual(field_data[1][2], 'initializing')
-            self.assertEqual(field_data[1][4], '2')
+            self.assertEqual(field_data[1][5], '2')
 
     def test_export_attendees_csv(self):
         """Method to check the attendees data export"""
 
         with self.app.test_request_context():
             test_attendee = AttendeeFactory()
+            test_order = OrderFactory(created_at=datetime.now())
+            test_attendee.order = test_order
             custom_forms = CustomFormFactory()
             field_data = export_attendees_csv([test_attendee], [custom_forms])
-            self.assertEqual(field_data[1][7], common.string_)
+            self.assertEqual(field_data[1][8], 'tax id')
 
     def _test_export_session_csv(self, test_session=None):
         with self.app.test_request_context():
diff --git a/tests/factories/order.py b/tests/factories/order.py
--- a/tests/factories/order.py
+++ b/tests/factories/order.py
@@ -11,6 +11,8 @@ class Meta:
 
     payment_mode = 'free'
     status = 'initializing'
+    tax_business_info = 'tax id'
+    company = 'company'
 
 
 class OrderSubFactory(OrderFactoryBase):