| 3249 |
varun.gupt |
1 |
'''
|
|
|
2 |
Created on 06-Sept-2011
|
|
|
3 |
|
|
|
4 |
@author: Varun Gupta
|
| 3384 |
varun.gupt |
5 |
|
| 3417 |
varun.gupt |
6 |
Max Uses: 1000
|
|
|
7 |
|
| 3491 |
varun.gupt |
8 |
A user can use the coupon only 2 times.
|
| 3417 |
varun.gupt |
9 |
|
| 3384 |
varun.gupt |
10 |
Samsung Galaxy S II i9100 Rs.1000 off
|
|
|
11 |
Spice Blueberry Mini QT-58 20% off
|
|
|
12 |
Spice Blueberry Exp QT-61 20% off
|
| 3497 |
varun.gupt |
13 |
Nokia (All models, other than C2-03, from Rs.2000 to Rs.5000) Rs.200 off
|
| 3384 |
varun.gupt |
14 |
Nokia (All models above Rs.5000) Rs.500 off
|
| 3249 |
varun.gupt |
15 |
'''
|
|
|
16 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
| 3417 |
varun.gupt |
17 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
| 3249 |
varun.gupt |
18 |
from shop2020.clients.CatalogClient import CatalogClient
|
|
|
19 |
from shop2020.thriftpy.model.v1.catalog.ttypes import Item
|
|
|
20 |
|
|
|
21 |
def execute(cart, coupon_code, args):
|
|
|
22 |
|
|
|
23 |
#Allow only first 1000 users to use the coupon
|
|
|
24 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
|
|
25 |
|
|
|
26 |
if count_coupon_usage >= 1000:
|
|
|
27 |
raise PromotionException(112, 'This promotion is over.')
|
|
|
28 |
|
| 3417 |
varun.gupt |
29 |
#Allow a user to use the coupon only 5 times max.
|
|
|
30 |
count_users_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
|
|
|
31 |
|
| 3491 |
varun.gupt |
32 |
if count_users_usage > 1:
|
| 3417 |
varun.gupt |
33 |
raise PromotionException(111, 'This promotion is over.')
|
|
|
34 |
|
| 3249 |
varun.gupt |
35 |
if cart.lines:
|
|
|
36 |
total_selling_price = 0
|
|
|
37 |
total_discounted_price = 0
|
|
|
38 |
|
|
|
39 |
has_qualified_model = False
|
|
|
40 |
|
|
|
41 |
for line in cart.lines:
|
|
|
42 |
|
|
|
43 |
line.discountedPrice = line.actualPrice
|
|
|
44 |
|
|
|
45 |
if line.itemId in (159, 160, 161, 1557, 1558): #Spice QT-58/61
|
|
|
46 |
|
|
|
47 |
has_qualified_model = True
|
|
|
48 |
|
|
|
49 |
if line.actualPrice:
|
|
|
50 |
line.discountedPrice = round(line.actualPrice * 0.8)
|
|
|
51 |
|
| 3256 |
varun.gupt |
52 |
elif line.itemId == 1502: #Galaxy SII
|
| 3249 |
varun.gupt |
53 |
|
|
|
54 |
has_qualified_model = True
|
|
|
55 |
|
|
|
56 |
if line.actualPrice:
|
|
|
57 |
line.discountedPrice = line.actualPrice - 1000
|
| 3454 |
varun.gupt |
58 |
|
| 3497 |
varun.gupt |
59 |
# Excluded: Nokia C2-03 and Price above Rs.1,999
|
|
|
60 |
elif line.itemId not in (1590, 2014) and line.actualPrice > 1999:
|
| 3454 |
varun.gupt |
61 |
|
| 3249 |
varun.gupt |
62 |
catalog_client = CatalogClient().get_client()
|
|
|
63 |
item = catalog_client.getItem(line.itemId)
|
| 3254 |
varun.gupt |
64 |
print 'Item: %d, Brand: *%s*' % (line.itemId, item.brand.lower())
|
| 3454 |
varun.gupt |
65 |
|
| 3249 |
varun.gupt |
66 |
if item.brand.lower() == 'nokia':
|
| 3257 |
varun.gupt |
67 |
has_qualified_model = True
|
|
|
68 |
|
| 3254 |
varun.gupt |
69 |
print 'Brand matched'
|
| 3249 |
varun.gupt |
70 |
discount_value = 200 if line.actualPrice < 5001 else 500
|
|
|
71 |
line.discountedPrice = line.actualPrice - discount_value
|
| 3254 |
varun.gupt |
72 |
else:
|
|
|
73 |
print 'Brand not matched'
|
| 3249 |
varun.gupt |
74 |
|
|
|
75 |
total_selling_price += line.actualPrice * line.quantity
|
| 3384 |
varun.gupt |
76 |
total_discounted_price += line.discountedPrice + (line.actualPrice * (line.quantity - 1))
|
| 3249 |
varun.gupt |
77 |
|
|
|
78 |
if has_qualified_model is False:
|
| 3401 |
varun.gupt |
79 |
raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
|
| 3249 |
varun.gupt |
80 |
|
|
|
81 |
cart.totalPrice = total_selling_price
|
|
|
82 |
cart.discountedPrice = total_discounted_price
|
|
|
83 |
|
| 3513 |
chandransh |
84 |
return cart
|