| 2121 |
varun.gupt |
1 |
'''
|
|
|
2 |
Created on 08-Jun-2011
|
|
|
3 |
|
|
|
4 |
@author: varungupta
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
|
|
7 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
|
|
8 |
|
|
|
9 |
def execute(cart, coupon_code, args):
|
|
|
10 |
#Allow a user to use the coupon only once.
|
|
|
11 |
count_users_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
|
|
|
12 |
|
|
|
13 |
if count_users_usage > 0:
|
|
|
14 |
raise PromotionException(111, 'You have already used this Coupon.')
|
|
|
15 |
|
|
|
16 |
#Allow only first 100 users to use the coupon
|
|
|
17 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
|
|
18 |
if count_coupon_usage >= 100:
|
|
|
19 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
20 |
|
|
|
21 |
if cart.lines:
|
|
|
22 |
total_selling_price = 0
|
|
|
23 |
|
|
|
24 |
for line in cart.lines:
|
| 2131 |
varun.gupt |
25 |
#Disabling Coupon for Samsung Galaxy SII
|
|
|
26 |
|
|
|
27 |
if line.itemId == 1502:
|
|
|
28 |
raise PromotionException(115, 'This coupon is not applicable for Samsung Galaxy S II')
|
| 2151 |
rajveer |
29 |
if line.itemId == 1491:
|
|
|
30 |
raise PromotionException(115, 'This coupon is not applicable for HTC Desire A8181')
|
| 2121 |
varun.gupt |
31 |
if line.actualPrice:
|
|
|
32 |
total_selling_price += line.actualPrice * line.quantity
|
|
|
33 |
|
|
|
34 |
#MAX Discount 1500
|
|
|
35 |
if total_selling_price * 0.05 >= 1500:
|
|
|
36 |
discount_perc = 1500 / total_selling_price
|
|
|
37 |
elif total_selling_price >= 5000:
|
|
|
38 |
discount_perc = 0.05
|
|
|
39 |
else:
|
|
|
40 |
discount_perc = 0.03
|
|
|
41 |
|
|
|
42 |
cart.totalPrice = round(total_selling_price, 2)
|
|
|
43 |
cart.discountedPrice = round((1 - discount_perc) * total_selling_price, 2)
|
|
|
44 |
|
|
|
45 |
for line in cart.lines:
|
|
|
46 |
if line.actualPrice:
|
|
|
47 |
line.discountedPrice = round((1 - discount_perc) * line.actualPrice, 2)
|
|
|
48 |
print "The final price, after discount is " + str(cart.discountedPrice)
|
| 2151 |
rajveer |
49 |
return cart
|