Repository: fossasia/open-event-server

Issue:
Email for all tickets not sent to Ticket Purchaser.
The ticket purchaser should receive all the tickets as a PDF in email.


Discussion:

Resolving patch:
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -11,7 +11,7 @@
 from app.api.helpers.utilities import string_empty, get_serializer, str_generator
 from app.models.mail import Mail, USER_CONFIRM, NEW_SESSION, USER_CHANGE_EMAIL, SESSION_ACCEPT_REJECT, EVENT_ROLE, \
     AFTER_EVENT, MONTHLY_PAYMENT_EMAIL, MONTHLY_PAYMENT_FOLLOWUP_EMAIL, EVENT_EXPORTED, EVENT_EXPORT_FAIL, \
-    EVENT_IMPORTED, EVENT_IMPORT_FAIL, TICKET_PURCHASED_ATTENDEE, TICKET_CANCELLED
+    EVENT_IMPORTED, EVENT_IMPORT_FAIL, TICKET_PURCHASED_ATTENDEE, TICKET_CANCELLED, TICKET_PURCHASED
 from app.models.user import User
 
 
@@ -277,20 +277,34 @@ def send_email_change_user_email(user, email):
     send_email_with_action(email, USER_CHANGE_EMAIL, email=email, new_email=user.email)
 
 
-def send_email_to_attendees(order):
+def send_email_to_attendees(order, purchaser_id):
     for holder in order.ticket_holders:
-        send_email(
-            to=holder.email,
-            action=TICKET_PURCHASED_ATTENDEE,
-            subject=MAILS[TICKET_PURCHASED_ATTENDEE]['subject'].format(
-                event_name=order.event.name,
-                invoice_id=order.invoice_number
-            ),
-            html= MAILS[TICKET_PURCHASED_ATTENDEE]['message'].format(
-                pdf_url=holder.pdf_url,
-                event_name=order.event.name
+        if holder.id != purchaser_id:
+            send_email(
+                to=holder.email,
+                action=TICKET_PURCHASED_ATTENDEE,
+                subject=MAILS[TICKET_PURCHASED_ATTENDEE]['subject'].format(
+                    event_name=order.event.name,
+                    invoice_id=order.invoice_number
+                ),
+                html=MAILS[TICKET_PURCHASED_ATTENDEE]['message'].format(
+                    pdf_url=holder.pdf_url,
+                    event_name=order.event.name
+                )
+            )
+        else:
+            send_email(
+                to=holder.email,
+                action=TICKET_PURCHASED,
+                subject=MAILS[TICKET_PURCHASED]['subject'].format(
+                    event_name=order.event.name,
+                    invoice_id=order.invoice_number
+                ),
+                html= MAILS[TICKET_PURCHASED]['message'].format(
+                    pdf_url=holder.pdf_url,
+                    event_name=order.event.name
+                )
             )
-        )
 
 def send_order_cancel_email(order):
     send_email(
diff --git a/app/api/helpers/system_mails.py b/app/api/helpers/system_mails.py
--- a/app/api/helpers/system_mails.py
+++ b/app/api/helpers/system_mails.py
@@ -135,9 +135,8 @@
         'subject': u'Your order invoice and tickets for {event_name} ({invoice_id}) ',
         'message': (
             u"Hi, this is a confirmation mail of your tickets for the event {event_name}"
-            u"<br/>The event is organised by {event_organiser}"
             u"<br/>Your order has been processed successfully." +
-            u"<br/> <a href='{order_url}'>Click here</a> to view/download your invoice."
+            u"<br/> <a href='{pdf_url}'>Click here</a> to view/download your invoice."
             u"<br><br><em>Looking forward to seeing you at the event."
             u"<br/>Login to manage your orders at https://eventyay.com </em>"
         )
diff --git a/app/api/orders.py b/app/api/orders.py
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@ -74,7 +74,7 @@ def after_create_object(self, order, data, view_kwargs):
         save_to_db(order)
         if not has_access('is_coorganizer', event_id=data['event']):
             TicketingManager.calculate_update_amount(order)
-        send_email_to_attendees(order)
+        send_email_to_attendees(order, current_user.id)
         send_notif_to_attendees(order, current_user.id)
 
         order_url = make_frontend_url(path='/orders/{identifier}'.format(identifier=order.identifier))


Test patch: