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