| 3299 |
varun.gupt |
1 |
'''
|
|
|
2 |
Created on 14-Sept-2011
|
|
|
3 |
|
|
|
4 |
@author: Varun Gupta
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
|
|
7 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count
|
|
|
8 |
|
|
|
9 |
def execute(cart, coupon_code, args):
|
|
|
10 |
|
|
|
11 |
#Allow only first 100 users to use the coupon
|
|
|
12 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
|
|
13 |
|
|
|
14 |
if count_coupon_usage >= 100:
|
|
|
15 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
16 |
|
|
|
17 |
if cart.lines:
|
|
|
18 |
total_selling_price = 0
|
|
|
19 |
total_discounted_price = 0
|
|
|
20 |
|
|
|
21 |
has_qualified_model = False
|
|
|
22 |
|
|
|
23 |
for line in cart.lines:
|
|
|
24 |
|
|
|
25 |
line.discountedPrice = line.actualPrice
|
|
|
26 |
|
|
|
27 |
if line.itemId in (6, 7, 8, 9, 1499): #Curve 8520
|
|
|
28 |
|
|
|
29 |
has_qualified_model = True
|
|
|
30 |
|
|
|
31 |
if line.actualPrice:
|
|
|
32 |
line.discountedPrice = round(line.actualPrice - 250)
|
|
|
33 |
|
|
|
34 |
elif line.itemId == 1591: #Blackberry 9900 Bold 4
|
|
|
35 |
|
|
|
36 |
has_qualified_model = True
|
|
|
37 |
|
|
|
38 |
if line.actualPrice:
|
|
|
39 |
line.discountedPrice = line.actualPrice - 2000
|
|
|
40 |
|
|
|
41 |
elif line.itemId in (10, 1560, 1561): #Curve 3G 9300
|
|
|
42 |
|
|
|
43 |
has_qualified_model = True
|
|
|
44 |
|
|
|
45 |
if line.actualPrice:
|
|
|
46 |
line.discountedPrice = line.actualPrice - 250
|
|
|
47 |
|
|
|
48 |
elif line.itemId == 2016: #Torch 2 9810
|
|
|
49 |
|
|
|
50 |
has_qualified_model = True
|
|
|
51 |
|
|
|
52 |
if line.actualPrice:
|
|
|
53 |
line.discountedPrice = line.actualPrice - 600
|
|
|
54 |
|
|
|
55 |
elif line.itemId in (1, 2): #Bold 3 9780
|
|
|
56 |
|
|
|
57 |
has_qualified_model = True
|
|
|
58 |
|
|
|
59 |
if line.actualPrice:
|
|
|
60 |
line.discountedPrice = line.actualPrice - 1650
|
|
|
61 |
|
|
|
62 |
elif line.itemId == 1543: #Playbook 16 GB
|
|
|
63 |
|
|
|
64 |
has_qualified_model = True
|
|
|
65 |
|
|
|
66 |
if line.actualPrice:
|
|
|
67 |
line.discountedPrice = line.actualPrice - 1390
|
|
|
68 |
|
|
|
69 |
elif line.itemId == 1550: #Playbook 32 GB
|
|
|
70 |
|
|
|
71 |
has_qualified_model = True
|
|
|
72 |
|
|
|
73 |
if line.actualPrice:
|
|
|
74 |
line.discountedPrice = line.actualPrice - 1690
|
|
|
75 |
|
|
|
76 |
total_selling_price += line.actualPrice * line.quantity
|
|
|
77 |
total_discounted_price += line.discountedPrice * line.quantity
|
|
|
78 |
|
|
|
79 |
if has_qualified_model is False:
|
|
|
80 |
raise PromotionException(115, 'This coupon is applicable only for selected Blackberry handsets.')
|
|
|
81 |
|
|
|
82 |
cart.totalPrice = total_selling_price
|
|
|
83 |
cart.discountedPrice = total_discounted_price
|
|
|
84 |
|
|
|
85 |
return cart
|