| 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 |
Galaxy Y Pro Duos B5512 Discount: Rs.502
|
|
|
9 |
Chat 322 C3222 Discount: Rs.171
|
|
|
10 |
Champ Deluxe Duos C3312 Discount: Rs.211
|
|
|
11 |
Champ Duos E2652 Discount: Rs.155
|
|
|
12 |
Champ 3.5G S3770 Discount: Rs.255
|
|
|
13 |
Corby II S3850 Discount: Rs.361
|
|
|
14 |
Star 3 Duos S5222 Discount: Rs.151
|
|
|
15 |
Chat 527 S5270 Discount: Rs.205
|
|
|
16 |
Galaxy Pocket S5300 Discount: Rs.245
|
|
|
17 |
Wave Y S5380 Discount: Rs.345
|
| 5288 |
varun.gupt |
18 |
Metro C3530 Discount: Rs.251
|
|
|
19 |
Primo S5610 Discount: Rs.241
|
|
|
20 |
Star II S5263 Discount: Rs.301
|
|
|
21 |
Star II Duos C6712 Discount: Rs.251
|
|
|
22 |
Wave 525 S5253 Discount: Rs.391
|
|
|
23 |
Galaxy Y S5360 Discount: Rs.415
|
|
|
24 |
Galaxy Y Color S5360s Discount: Rs.199
|
|
|
25 |
Galaxy Y Duos S6102 Discount: Rs.595
|
| 5390 |
varun.gupt |
26 |
|
|
|
27 |
Champ Megacam C3303i Discount: Rs.80
|
|
|
28 |
Champ Deluxe C3312s Discount: Rs.191
|
|
|
29 |
Metro Duos C3322 Discount: Rs.151
|
|
|
30 |
Metro C3520 Discount: Rs.40
|
|
|
31 |
Star II Duos C6712 Discount: Rs.271
|
|
|
32 |
E1200, E1205 Discount: Rs.61
|
|
|
33 |
Guru FM E1220 Discount: Rs.51
|
|
|
34 |
Omnia W I8350 Discount: Rs.701
|
|
|
35 |
Galaxy S II I9100 Discount: Rs.905
|
|
|
36 |
Galaxy Note N7000 Discount: Rs.901
|
| 5288 |
varun.gupt |
37 |
'''
|
|
|
38 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
|
|
|
39 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
| 5331 |
rajveer |
40 |
from shop2020.clients.UserClient import UserClient
|
| 5288 |
varun.gupt |
41 |
|
|
|
42 |
def execute(cart, coupon_code, args):
|
| 5331 |
rajveer |
43 |
user_client = UserClient().get_client()
|
|
|
44 |
user = user_client.getUserByCartId(cart.id)
|
|
|
45 |
|
| 5394 |
varun.gupt |
46 |
#Allow only first 300 users to use the coupon
|
| 5288 |
varun.gupt |
47 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
|
|
48 |
|
| 5394 |
varun.gupt |
49 |
if count_coupon_usage >= 300:
|
| 5288 |
varun.gupt |
50 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
51 |
|
| 5353 |
varun.gupt |
52 |
if get_coupon_usage_count_by_user(coupon_code, user.userId) > 0:
|
| 5288 |
varun.gupt |
53 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
54 |
|
|
|
55 |
discounts = []
|
|
|
56 |
|
|
|
57 |
if cart.lines:
|
|
|
58 |
total_selling_price = 0
|
|
|
59 |
total_discounted_price = 0
|
|
|
60 |
|
|
|
61 |
has_qualified_model = False
|
|
|
62 |
|
|
|
63 |
for line in cart.lines:
|
|
|
64 |
|
|
|
65 |
line.discountedPrice = line.actualPrice
|
|
|
66 |
discount_value = 0
|
|
|
67 |
|
|
|
68 |
if line.itemId in (1010, 1451): #Chat 322 C3222
|
|
|
69 |
|
|
|
70 |
has_qualified_model = True
|
|
|
71 |
|
|
|
72 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
73 |
discount_value = 171
|
| 5288 |
varun.gupt |
74 |
|
|
|
75 |
elif line.itemId in (3356, 4628, 5730, 2563, 3357): #Champ Deluxe Duos C3312
|
|
|
76 |
|
|
|
77 |
has_qualified_model = True
|
|
|
78 |
|
|
|
79 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
80 |
discount_value = 211
|
| 5288 |
varun.gupt |
81 |
|
|
|
82 |
elif line.itemId in (1012, 1452, 1453): #Metro C3530
|
|
|
83 |
|
|
|
84 |
has_qualified_model = True
|
|
|
85 |
|
|
|
86 |
if line.actualPrice:
|
|
|
87 |
discount_value = 251
|
|
|
88 |
|
|
|
89 |
elif line.itemId in (999, 988, 5702): #Champ Duos E2652
|
|
|
90 |
|
|
|
91 |
has_qualified_model = True
|
|
|
92 |
|
|
|
93 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
94 |
discount_value = 155
|
| 5288 |
varun.gupt |
95 |
|
|
|
96 |
elif line.itemId in (2576, 2067): #Chat 527 S5270
|
|
|
97 |
|
|
|
98 |
has_qualified_model = True
|
|
|
99 |
|
|
|
100 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
101 |
discount_value = 205
|
| 5288 |
varun.gupt |
102 |
|
|
|
103 |
elif line.itemId in (2073, 2621): #Champ 3.5G S3770
|
|
|
104 |
|
|
|
105 |
has_qualified_model = True
|
|
|
106 |
|
|
|
107 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
108 |
discount_value = 255
|
| 5288 |
varun.gupt |
109 |
|
|
|
110 |
elif line.itemId in (3358, 4643): #Star 3 Duos S5222
|
|
|
111 |
|
|
|
112 |
has_qualified_model = True
|
|
|
113 |
|
|
|
114 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
115 |
discount_value = 151
|
| 5288 |
varun.gupt |
116 |
|
|
|
117 |
elif line.itemId in (2090, 2256): #Primo S5610
|
|
|
118 |
|
|
|
119 |
has_qualified_model = True
|
|
|
120 |
|
|
|
121 |
if line.actualPrice:
|
|
|
122 |
discount_value = 241
|
|
|
123 |
|
|
|
124 |
elif line.itemId in (968, 995): #Star II S5263
|
|
|
125 |
|
|
|
126 |
has_qualified_model = True
|
|
|
127 |
|
|
|
128 |
if line.actualPrice:
|
|
|
129 |
discount_value = 301
|
|
|
130 |
|
|
|
131 |
elif line.itemId in (996, 1000, 1524, 1563): #Corby II S3850
|
|
|
132 |
|
|
|
133 |
has_qualified_model = True
|
|
|
134 |
|
|
|
135 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
136 |
discount_value = 361
|
| 5288 |
varun.gupt |
137 |
|
|
|
138 |
elif line.itemId in (1537, 2227): #Star II Duos C6712
|
|
|
139 |
|
|
|
140 |
has_qualified_model = True
|
|
|
141 |
|
|
|
142 |
if line.actualPrice:
|
|
|
143 |
discount_value = 251
|
|
|
144 |
|
|
|
145 |
elif line.itemId in (949, 4690, 948): #Wave 525 S5253
|
|
|
146 |
|
|
|
147 |
has_qualified_model = True
|
|
|
148 |
|
|
|
149 |
if line.actualPrice:
|
|
|
150 |
discount_value = 391
|
|
|
151 |
|
|
|
152 |
elif line.itemId == 5834: #Galaxy Pocket S5300
|
|
|
153 |
|
|
|
154 |
has_qualified_model = True
|
|
|
155 |
|
|
|
156 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
157 |
discount_value = 245
|
| 5288 |
varun.gupt |
158 |
|
|
|
159 |
elif line.itemId in (2537, 2622): #Wave Y S5380
|
|
|
160 |
|
|
|
161 |
has_qualified_model = True
|
|
|
162 |
|
|
|
163 |
if line.actualPrice:
|
| 5390 |
varun.gupt |
164 |
discount_value = 345
|
| 5288 |
varun.gupt |
165 |
|
|
|
166 |
elif line.itemId in (2091, 3882, 2527): #Galaxy Y S5360
|
|
|
167 |
|
|
|
168 |
has_qualified_model = True
|
|
|
169 |
|
|
|
170 |
if line.actualPrice:
|
|
|
171 |
discount_value = 415
|
|
|
172 |
|
|
|
173 |
elif line.itemId == 2446: #Galaxy Y Color S5360s
|
|
|
174 |
|
|
|
175 |
has_qualified_model = True
|
|
|
176 |
|
|
|
177 |
if line.actualPrice:
|
|
|
178 |
discount_value = 199
|
|
|
179 |
|
|
|
180 |
elif line.itemId in (2629, 5839): #Galaxy Y Duos S6102
|
|
|
181 |
|
|
|
182 |
has_qualified_model = True
|
|
|
183 |
|
|
|
184 |
if line.actualPrice:
|
|
|
185 |
discount_value = 595
|
|
|
186 |
|
|
|
187 |
elif line.itemId == 2630: #Galaxy Y Pro Duos B5512
|
|
|
188 |
|
|
|
189 |
has_qualified_model = True
|
|
|
190 |
|
|
|
191 |
if line.actualPrice:
|
|
|
192 |
discount_value = 502
|
|
|
193 |
|
| 5390 |
varun.gupt |
194 |
elif line.itemId in (1001, 2226, 1004, 1011, 998): #Champ Megacam C3303i
|
|
|
195 |
has_qualified_model = True
|
|
|
196 |
|
|
|
197 |
if line.actualPrice: discount_value = 80
|
|
|
198 |
|
|
|
199 |
elif line.itemId == 4629: #Champ Deluxe C3312s
|
|
|
200 |
has_qualified_model = True
|
|
|
201 |
|
|
|
202 |
if line.actualPrice: discount_value = 191
|
|
|
203 |
|
|
|
204 |
elif line.itemId in (2532, 4689, 1500): #Metro Duos C3322
|
|
|
205 |
has_qualified_model = True
|
|
|
206 |
|
|
|
207 |
if line.actualPrice: discount_value = 151
|
|
|
208 |
|
|
|
209 |
elif line.itemId in (2445, 4636): #Metro C3520
|
|
|
210 |
has_qualified_model = True
|
|
|
211 |
|
|
|
212 |
if line.actualPrice: discount_value = 40
|
|
|
213 |
|
|
|
214 |
elif line.itemId in (1537, 2227): #Star II Duos C6712
|
|
|
215 |
has_qualified_model = True
|
|
|
216 |
|
|
|
217 |
if line.actualPrice: discount_value = 271
|
|
|
218 |
|
|
|
219 |
elif line.itemId in (5700, 5701): #E1200, E1205
|
|
|
220 |
has_qualified_model = True
|
|
|
221 |
|
|
|
222 |
if line.actualPrice: discount_value = 61
|
|
|
223 |
|
|
|
224 |
elif line.itemId == 2603: #Guru FM E1220
|
|
|
225 |
has_qualified_model = True
|
|
|
226 |
|
|
|
227 |
if line.actualPrice: discount_value = 51
|
|
|
228 |
|
|
|
229 |
elif line.itemId == 2470: #Omnia W I8350
|
|
|
230 |
has_qualified_model = True
|
|
|
231 |
|
|
|
232 |
if line.actualPrice: discount_value = 701
|
|
|
233 |
|
|
|
234 |
elif line.itemId in (1493, 1502): #Galaxy S II I9100
|
|
|
235 |
has_qualified_model = True
|
|
|
236 |
|
|
|
237 |
if line.actualPrice: discount_value = 905
|
|
|
238 |
|
|
|
239 |
elif line.itemId in (2215, 2481): #Galaxy Note N7000
|
|
|
240 |
has_qualified_model = True
|
|
|
241 |
|
|
|
242 |
if line.actualPrice: discount_value = 901
|
|
|
243 |
|
| 5288 |
varun.gupt |
244 |
if discount_value > 0:
|
|
|
245 |
discount = Discount()
|
|
|
246 |
discount.cart_id = cart.id
|
|
|
247 |
discount.item_id = line.itemId
|
|
|
248 |
discount.discount = discount_value
|
|
|
249 |
discount.quantity = line.quantity
|
|
|
250 |
|
|
|
251 |
discounts.append(discount)
|
| 5390 |
varun.gupt |
252 |
line.discountedPrice = round(line.actualPrice - discount_value)
|
|
|
253 |
|
|
|
254 |
total_selling_price += line.actualPrice * line.quantity
|
|
|
255 |
total_discounted_price += line.discountedPrice * line.quantity
|
|
|
256 |
|
| 5288 |
varun.gupt |
257 |
if has_qualified_model is False:
|
| 5390 |
varun.gupt |
258 |
raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
|
| 5288 |
varun.gupt |
259 |
|
|
|
260 |
cart.totalPrice = total_selling_price
|
|
|
261 |
cart.discountedPrice = total_discounted_price
|
|
|
262 |
|
|
|
263 |
return cart, discounts
|
|
|
264 |
|
|
|
265 |
def getDiscountOnItem(item):
|
| 5298 |
varun.gupt |
266 |
|
| 5288 |
varun.gupt |
267 |
discount_expressions = [
|
| 5390 |
varun.gupt |
268 |
'171 if item.id in (1010, 1451) else None',
|
|
|
269 |
'211 if item.id in (3356, 4628, 5730, 2563, 3357) else None',
|
| 5298 |
varun.gupt |
270 |
'251 if item.id in (1012, 1452, 1453) else None',
|
| 5390 |
varun.gupt |
271 |
'155 if item.id in (999, 988, 5702) else None',
|
|
|
272 |
'205 if item.id in (2576, 2067) else None',
|
|
|
273 |
'255 if item.id in (2073, 2621) else None',
|
|
|
274 |
'151 if item.id in (3358, 4643) else None',
|
| 5298 |
varun.gupt |
275 |
'241 if item.id in (2090, 2256) else None',
|
|
|
276 |
'301 if item.id in (968, 995) else None',
|
| 5390 |
varun.gupt |
277 |
'361 if item.id in (996, 1000, 1524, 1563) else None',
|
| 5298 |
varun.gupt |
278 |
'251 if item.id in (1537, 2227) else None',
|
|
|
279 |
'391 if item.id in (949, 4690, 948) else None',
|
| 5390 |
varun.gupt |
280 |
'245 if item.id == 5834 else None',
|
|
|
281 |
'345 if item.id in (2537, 2622) else None',
|
| 5298 |
varun.gupt |
282 |
'415 if item.id in (2091, 3882, 2527) else None',
|
|
|
283 |
'199 if item.id == 2446 else None',
|
|
|
284 |
'595 if item.id in (2629, 5839) else None',
|
|
|
285 |
'502 if item.id == 2630 else None'
|
| 5288 |
varun.gupt |
286 |
]
|
|
|
287 |
for expression in discount_expressions:
|
|
|
288 |
discount = eval(expression)
|
|
|
289 |
|
|
|
290 |
if discount is not None:
|
|
|
291 |
return discount
|
| 5298 |
varun.gupt |
292 |
|
| 5288 |
varun.gupt |
293 |
return None
|