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