| 5288 |
varun.gupt |
1 |
'''
|
|
|
2 |
Created on 28-May-2012
|
|
|
3 |
|
|
|
4 |
@author: Varun Gupta
|
|
|
5 |
|
| 5394 |
varun.gupt |
6 |
Allows first 300 users to use the coupon
|
|
|
7 |
|
| 5390 |
varun.gupt |
8 |
Chat 322 C3222 Discount: Rs.171
|
|
|
9 |
Champ Duos E2652 Discount: Rs.155
|
|
|
10 |
Champ 3.5G S3770 Discount: Rs.255
|
|
|
11 |
Corby II S3850 Discount: Rs.361
|
|
|
12 |
Chat 527 S5270 Discount: Rs.205
|
| 5288 |
varun.gupt |
13 |
Metro C3530 Discount: Rs.251
|
|
|
14 |
Primo S5610 Discount: Rs.241
|
|
|
15 |
Star II S5263 Discount: Rs.301
|
|
|
16 |
Star II Duos C6712 Discount: Rs.251
|
|
|
17 |
Wave 525 S5253 Discount: Rs.391
|
|
|
18 |
Galaxy Y Color S5360s Discount: Rs.199
|
| 5390 |
varun.gupt |
19 |
|
|
|
20 |
Champ Megacam C3303i Discount: Rs.80
|
|
|
21 |
Champ Deluxe C3312s Discount: Rs.191
|
|
|
22 |
Metro C3520 Discount: Rs.40
|
|
|
23 |
Star II Duos C6712 Discount: Rs.271
|
|
|
24 |
E1200, E1205 Discount: Rs.61
|
|
|
25 |
Guru FM E1220 Discount: Rs.51
|
|
|
26 |
Omnia W I8350 Discount: Rs.701
|
| 5288 |
varun.gupt |
27 |
'''
|
|
|
28 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
|
|
|
29 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
| 5331 |
rajveer |
30 |
from shop2020.clients.UserClient import UserClient
|
| 5288 |
varun.gupt |
31 |
|
|
|
32 |
def execute(cart, coupon_code, args):
|
| 5331 |
rajveer |
33 |
user_client = UserClient().get_client()
|
|
|
34 |
user = user_client.getUserByCartId(cart.id)
|
|
|
35 |
|
| 5394 |
varun.gupt |
36 |
#Allow only first 300 users to use the coupon
|
| 5288 |
varun.gupt |
37 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
|
|
38 |
|
| 5394 |
varun.gupt |
39 |
if count_coupon_usage >= 300:
|
| 5288 |
varun.gupt |
40 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
41 |
|
| 5353 |
varun.gupt |
42 |
if get_coupon_usage_count_by_user(coupon_code, user.userId) > 0:
|
| 5288 |
varun.gupt |
43 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
44 |
|
|
|
45 |
discounts = []
|
|
|
46 |
|
|
|
47 |
if cart.lines:
|
|
|
48 |
total_selling_price = 0
|
|
|
49 |
total_discounted_price = 0
|
|
|
50 |
|
|
|
51 |
has_qualified_model = False
|
|
|
52 |
|
|
|
53 |
for line in cart.lines:
|
|
|
54 |
|
|
|
55 |
line.discountedPrice = line.actualPrice
|
|
|
56 |
discount_value = 0
|
|
|
57 |
|
|
|
58 |
if line.itemId in (1010, 1451): #Chat 322 C3222
|
|
|
59 |
|
|
|
60 |
has_qualified_model = True
|
|
|
61 |
|
|
|
62 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
63 |
discount_value = 171
|
| 5288 |
varun.gupt |
64 |
|
|
|
65 |
elif line.itemId in (1012, 1452, 1453): #Metro C3530
|
|
|
66 |
|
|
|
67 |
has_qualified_model = True
|
|
|
68 |
|
|
|
69 |
if line.actualPrice:
|
|
|
70 |
discount_value = 251
|
|
|
71 |
|
|
|
72 |
elif line.itemId in (999, 988, 5702): #Champ Duos E2652
|
|
|
73 |
|
|
|
74 |
has_qualified_model = True
|
|
|
75 |
|
|
|
76 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
77 |
discount_value = 155
|
| 5288 |
varun.gupt |
78 |
|
|
|
79 |
elif line.itemId in (2576, 2067): #Chat 527 S5270
|
|
|
80 |
|
|
|
81 |
has_qualified_model = True
|
|
|
82 |
|
|
|
83 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
84 |
discount_value = 205
|
| 5288 |
varun.gupt |
85 |
|
|
|
86 |
elif line.itemId in (2073, 2621): #Champ 3.5G S3770
|
|
|
87 |
|
|
|
88 |
has_qualified_model = True
|
|
|
89 |
|
|
|
90 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
91 |
discount_value = 255
|
| 5288 |
varun.gupt |
92 |
|
|
|
93 |
elif line.itemId in (2090, 2256): #Primo S5610
|
|
|
94 |
|
|
|
95 |
has_qualified_model = True
|
|
|
96 |
|
|
|
97 |
if line.actualPrice:
|
|
|
98 |
discount_value = 241
|
|
|
99 |
|
|
|
100 |
elif line.itemId in (968, 995): #Star II S5263
|
|
|
101 |
|
|
|
102 |
has_qualified_model = True
|
|
|
103 |
|
|
|
104 |
if line.actualPrice:
|
|
|
105 |
discount_value = 301
|
|
|
106 |
|
|
|
107 |
elif line.itemId in (996, 1000, 1524, 1563): #Corby II S3850
|
|
|
108 |
|
|
|
109 |
has_qualified_model = True
|
|
|
110 |
|
|
|
111 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
112 |
discount_value = 361
|
| 5288 |
varun.gupt |
113 |
|
|
|
114 |
elif line.itemId in (1537, 2227): #Star II Duos C6712
|
|
|
115 |
|
|
|
116 |
has_qualified_model = True
|
|
|
117 |
|
|
|
118 |
if line.actualPrice:
|
|
|
119 |
discount_value = 251
|
|
|
120 |
|
|
|
121 |
elif line.itemId in (949, 4690, 948): #Wave 525 S5253
|
|
|
122 |
|
|
|
123 |
has_qualified_model = True
|
|
|
124 |
|
|
|
125 |
if line.actualPrice:
|
|
|
126 |
discount_value = 391
|
|
|
127 |
|
|
|
128 |
elif line.itemId == 2446: #Galaxy Y Color S5360s
|
|
|
129 |
|
|
|
130 |
has_qualified_model = True
|
|
|
131 |
|
|
|
132 |
if line.actualPrice:
|
|
|
133 |
discount_value = 199
|
|
|
134 |
|
| 5390 |
varun.gupt |
135 |
elif line.itemId in (1001, 2226, 1004, 1011, 998): #Champ Megacam C3303i
|
|
|
136 |
has_qualified_model = True
|
|
|
137 |
|
|
|
138 |
if line.actualPrice: discount_value = 80
|
|
|
139 |
|
|
|
140 |
elif line.itemId == 4629: #Champ Deluxe C3312s
|
|
|
141 |
has_qualified_model = True
|
|
|
142 |
|
|
|
143 |
if line.actualPrice: discount_value = 191
|
|
|
144 |
|
|
|
145 |
elif line.itemId in (2445, 4636): #Metro C3520
|
|
|
146 |
has_qualified_model = True
|
|
|
147 |
|
|
|
148 |
if line.actualPrice: discount_value = 40
|
|
|
149 |
|
|
|
150 |
elif line.itemId in (1537, 2227): #Star II Duos C6712
|
|
|
151 |
has_qualified_model = True
|
|
|
152 |
|
|
|
153 |
if line.actualPrice: discount_value = 271
|
|
|
154 |
|
|
|
155 |
elif line.itemId in (5700, 5701): #E1200, E1205
|
|
|
156 |
has_qualified_model = True
|
|
|
157 |
|
|
|
158 |
if line.actualPrice: discount_value = 61
|
|
|
159 |
|
|
|
160 |
elif line.itemId == 2603: #Guru FM E1220
|
|
|
161 |
has_qualified_model = True
|
|
|
162 |
|
|
|
163 |
if line.actualPrice: discount_value = 51
|
|
|
164 |
|
|
|
165 |
elif line.itemId == 2470: #Omnia W I8350
|
|
|
166 |
has_qualified_model = True
|
|
|
167 |
|
|
|
168 |
if line.actualPrice: discount_value = 701
|
|
|
169 |
|
| 5288 |
varun.gupt |
170 |
if discount_value > 0:
|
|
|
171 |
discount = Discount()
|
|
|
172 |
discount.cart_id = cart.id
|
|
|
173 |
discount.item_id = line.itemId
|
|
|
174 |
discount.discount = discount_value
|
|
|
175 |
discount.quantity = line.quantity
|
|
|
176 |
|
|
|
177 |
discounts.append(discount)
|
| 5390 |
varun.gupt |
178 |
line.discountedPrice = round(line.actualPrice - discount_value)
|
|
|
179 |
|
|
|
180 |
total_selling_price += line.actualPrice * line.quantity
|
|
|
181 |
total_discounted_price += line.discountedPrice * line.quantity
|
|
|
182 |
|
| 5288 |
varun.gupt |
183 |
if has_qualified_model is False:
|
| 5390 |
varun.gupt |
184 |
raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
|
| 5288 |
varun.gupt |
185 |
|
|
|
186 |
cart.totalPrice = total_selling_price
|
|
|
187 |
cart.discountedPrice = total_discounted_price
|
|
|
188 |
|
|
|
189 |
return cart, discounts
|
|
|
190 |
|
|
|
191 |
def getDiscountOnItem(item):
|
| 5298 |
varun.gupt |
192 |
|
| 5288 |
varun.gupt |
193 |
discount_expressions = [
|
| 5390 |
varun.gupt |
194 |
'171 if item.id in (1010, 1451) else None',
|
| 5298 |
varun.gupt |
195 |
'251 if item.id in (1012, 1452, 1453) else None',
|
| 5390 |
varun.gupt |
196 |
'155 if item.id in (999, 988, 5702) else None',
|
|
|
197 |
'205 if item.id in (2576, 2067) else None',
|
|
|
198 |
'255 if item.id in (2073, 2621) else None',
|
| 5298 |
varun.gupt |
199 |
'241 if item.id in (2090, 2256) else None',
|
|
|
200 |
'301 if item.id in (968, 995) else None',
|
| 5390 |
varun.gupt |
201 |
'361 if item.id in (996, 1000, 1524, 1563) else None',
|
| 5298 |
varun.gupt |
202 |
'251 if item.id in (1537, 2227) else None',
|
|
|
203 |
'391 if item.id in (949, 4690, 948) else None',
|
|
|
204 |
'199 if item.id == 2446 else None',
|
| 5418 |
varun.gupt |
205 |
'80 if item.id in (1001, 2226, 1004, 1011, 998) else None',
|
|
|
206 |
'191 if item.id == 4629 else None',
|
|
|
207 |
'40 if item.id in (2445, 4636) else None',
|
|
|
208 |
'271 if item.id in (1537, 2227) else None',
|
|
|
209 |
'61 if item.id in (5700, 5701) else None',
|
|
|
210 |
'51 if item.id == 2603 else None',
|
| 5485 |
varun.gupt |
211 |
'701 if item.id == 2470 else None'
|
| 5288 |
varun.gupt |
212 |
]
|
|
|
213 |
for expression in discount_expressions:
|
|
|
214 |
discount = eval(expression)
|
|
|
215 |
|
|
|
216 |
if discount is not None:
|
|
|
217 |
return discount
|
| 5298 |
varun.gupt |
218 |
|
| 5288 |
varun.gupt |
219 |
return None
|