Repository: fossasia/open-event-server

Issue:
Implement "Apply" Promotional Code on event site itself
Our promotional code/discount gets applied only after the user advances to the next page.

Expected: 
* [x] There should be an "Apply" button on the right hand side of the promotion field (when it is expanded).
![screenshot from 2017-01-07 19-33-17](https://cloud.githubusercontent.com/assets/1583873/21744213/9ed3ba18-d511-11e6-9eef-06cb652f6cdf.png)

* [ ] After the user hits "Apply":
    * [ ] Display below the ticket type the applied discount, e.g. Discounted 50%
    * [ ] Display the new (discounted) ticket price in the price column and the old ticket price crossed

Compare:

![screenshot from 2017-01-07 19-41-23](https://cloud.githubusercontent.com/assets/1583873/21744210/93941abc-d511-11e6-987c-002254742874.png)



Discussion:
I'd like to work on this
Implementation of this issue is not complete. When the discount code is applied the user should see the ticket cost striked through and the discounted cost. Please compare to screenshot.

![screenshot from 2017-01-07 19-41-23](https://cloud.githubusercontent.com/assets/1583873/21744210/93941abc-d511-11e6-987c-002254742874.png)

:+1:

hi guys, can someone take care of this please? 
@hpdang sorry for the delay, been busy with academics lately, will take it up tonight and fix it :smiley:

Resolving patch:
diff --git a/app/helpers/ticketing.py b/app/helpers/ticketing.py
--- a/app/helpers/ticketing.py
+++ b/app/helpers/ticketing.py
@@ -251,7 +251,7 @@ def create_order(form, from_organizer=False):
                 flash('Your access code is applied and you can make this order now.', 'success')
             else:
                 flash('The promotional code entered is not valid. No offer has been applied to this order.', 'danger')
-                
+
         ticket_subtotals = []
         if from_organizer:
             ticket_subtotals = form.getlist('ticket_subtotals[]')
@@ -267,6 +267,18 @@ def create_order(form, from_organizer=False):
                     order_ticket.quantity = int(ticket_quantity[index])
                     order.tickets.append(order_ticket)
 
+                    if order_ticket.ticket.absorb_fees or not fees:
+                        ticket_amount = (order_ticket.ticket.price * order_ticket.quantity)
+                        amount += (order_ticket.ticket.price * order_ticket.quantity)
+                    else:
+                        order_fee = fees.service_fee * (order_ticket.ticket.price * order_ticket.quantity) / 100
+                        if order_fee > fees.maximum_fee:
+                            ticket_amount = (order_ticket.ticket.price * order_ticket.quantity) + fees.maximum_fee
+                            amount += (order_ticket.ticket.price * order_ticket.quantity) + fees.maximum_fee
+                        else:
+                            ticket_amount = (order_ticket.ticket.price * order_ticket.quantity) + order_fee
+                            amount += (order_ticket.ticket.price * order_ticket.quantity) + order_fee
+
                     if from_organizer:
                         amount += float(ticket_subtotals[index])
                     else:
@@ -274,20 +286,10 @@ def create_order(form, from_organizer=False):
                             if discount.type == "amount":
                                 total_discount += discount.value * order_ticket.quantity
                             else:
-                                total_discount += discount.value * order_ticket.ticket.price *\
-                                                 order_ticket.quantity/100.0
-
-                        if order_ticket.ticket.absorb_fees or not fees:
-                            amount += (order_ticket.ticket.price * order_ticket.quantity)
-                        else:
-                            order_fee = fees.service_fee * (order_ticket.ticket.price * order_ticket.quantity) / 100
-                            if order_fee > fees.maximum_fee:
-                                amount += (order_ticket.ticket.price * order_ticket.quantity) + fees.maximum_fee
-                            else:
-                                amount += (order_ticket.ticket.price * order_ticket.quantity) + order_fee
+                                total_discount += discount.value * ticket_amount / 100
 
         if discount:
-            order.amount = max(amount - total_discount,0)
+            order.amount = max(amount - total_discount, 0)
         elif discount:
             order.amount = amount-(discount.value*amount/100.0)
         else:


Test patch: