Subversion Repositories SmartDukaan

Rev

Rev 4189 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3535 varun.gupt 1
'''
2
Created on 01-Oct-2011
3
 
4
@author: Varun Gupta
5
 
6
Max uses: 100
7
 
4155 varun.gupt 8
Apple 16GB iPad 2 Wi-Fi+3G Rs.900 off
9
Apple 32GB iPad 2 Wi-Fi+3G Rs.900 off
10
Apple 64GB iPad 2 Wi-Fi+3G Rs.900 off
11
BlackBerry playbook 32gb Rs.250 off
12
BlackBerry playbook 64gb Rs.2500 off
13
HTC P510e Flyer Rs.500 off
14
Motorola MZ601 Xoom Rs.2000 off
15
Samsung N7000 Galaxy Note Rs.2500 off
16
Samsung P7300 Tablet 8.9" Rs.1500 off
17
Samsung P7500 Galaxy Tab 750 Rs.1800 off
18
Spice Mi-720 Tab Rs.1200 off
3535 varun.gupt 19
'''
3559 varun.gupt 20
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
3535 varun.gupt 21
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
22
from shop2020.clients.CatalogClient import CatalogClient
23
 
24
def execute(cart, coupon_code, args):
25
 
26
    #Allow only first 100 users to use the coupon
27
    count_coupon_usage = get_coupon_usage_count(coupon_code)
28
 
29
    if count_coupon_usage >= 100:
30
        raise PromotionException(112, 'This promotion is over.')
31
 
3559 varun.gupt 32
    discounts = []
33
 
3535 varun.gupt 34
    if cart.lines:
35
        total_selling_price = 0
36
        total_discounted_price = 0
37
 
38
        has_qualified_model = False
39
 
40
        for line in cart.lines:
41
 
42
            line.discountedPrice = line.actualPrice
3559 varun.gupt 43
            discount_value = 0
3535 varun.gupt 44
 
4155 varun.gupt 45
            if line.itemId in [2177, 2178, 2179, 2180, 2181, 2182]:  #iPad 16GB, iPad 32GB, iPad 64GB
3535 varun.gupt 46
 
47
                has_qualified_model = True
48
 
49
                if line.actualPrice:
4155 varun.gupt 50
                    line.discountedPrice = line.actualPrice - 900
51
                    discount_value = 900
3535 varun.gupt 52
 
4155 varun.gupt 53
            elif line.itemId == 2199:   #BlackBerry PlayBook 32GB
3535 varun.gupt 54
 
55
                has_qualified_model = True
56
 
57
                if line.actualPrice:
4155 varun.gupt 58
                    line.discountedPrice = line.actualPrice - 250
59
                    discount_value = 250
3535 varun.gupt 60
 
4155 varun.gupt 61
            elif line.itemId == 1550:   #BlackBerry PlayBook 64GB
3535 varun.gupt 62
 
63
                has_qualified_model = True
64
 
65
                if line.actualPrice:
4155 varun.gupt 66
                    line.discountedPrice = line.actualPrice - 2500
67
                    discount_value = 2500
68
 
69
            elif line.itemId == 1551:   #HTC P510e Flyer
70
 
71
                has_qualified_model = True
72
 
73
                if line.actualPrice:
3535 varun.gupt 74
                    line.discountedPrice = line.actualPrice - 500
3559 varun.gupt 75
                    discount_value = 500
3535 varun.gupt 76
 
4155 varun.gupt 77
            elif line.itemId == 1552:   #Motorola MZ601 Xoom
3535 varun.gupt 78
 
79
                has_qualified_model = True
80
 
81
                if line.actualPrice:
4155 varun.gupt 82
                    line.discountedPrice = line.actualPrice - 2000
83
                    discount_value = 2000
3535 varun.gupt 84
 
4155 varun.gupt 85
            elif line.itemId == 2215:   #Samsung N7000 Galaxy Note
3535 varun.gupt 86
 
87
                has_qualified_model = True
88
 
89
                if line.actualPrice:
3713 varun.gupt 90
                    line.discountedPrice = line.actualPrice - 2500
91
                    discount_value = 2500
3535 varun.gupt 92
 
4155 varun.gupt 93
            elif line.itemId == 2230:   #Samsung P7300 Galaxy Tab
3535 varun.gupt 94
 
95
                has_qualified_model = True
96
 
97
                if line.actualPrice:
3713 varun.gupt 98
                    line.discountedPrice = line.actualPrice - 1500
99
                    discount_value = 1500
3535 varun.gupt 100
 
4190 varun.gupt 101
            elif line.itemId in (2005, 2194):   #Samsung P7500 Galaxy Tab
4155 varun.gupt 102
 
103
                has_qualified_model = True
104
 
105
                if line.actualPrice:
106
                    line.discountedPrice = line.actualPrice - 1700
107
                    discount_value = 1700
108
 
109
            elif line.itemId == 2022:   #Spice Mi-720 Tab
110
 
111
                has_qualified_model = True
112
 
113
                if line.actualPrice:
114
                    line.discountedPrice = line.actualPrice - 1200
115
                    discount_value = 1200
116
 
3535 varun.gupt 117
            total_selling_price += line.actualPrice * line.quantity
3559 varun.gupt 118
            total_discounted_price += line.discountedPrice * line.quantity
3535 varun.gupt 119
 
3559 varun.gupt 120
            if discount_value > 0:
121
                discount = Discount()
122
                discount.cart_id = cart.id
123
                discount.item_id = line.itemId
124
                discount.discount = discount_value
125
                discount.quantity = line.quantity
126
 
127
                discounts.append(discount)
128
 
3535 varun.gupt 129
        if has_qualified_model is False:
130
            raise PromotionException(115, 'This coupon is applicable only for selective tablets.')
131
 
132
        cart.totalPrice = total_selling_price
133
        cart.discountedPrice = total_discounted_price
134
 
4189 varun.gupt 135
    return cart, discounts
136
 
137
 
138
def getDiscountOnItem(item):
139
    discount_expressions = [
140
            '900 if item.id in [2177, 2178, 2179, 2180, 2181, 2182] else None',
141
            '250 if item.id == 2199 else None',
142
            '2500 if item.id == 1550 else None',
143
            '500 if item.id == 1551 else None',
144
            '2000 if item.id == 1552 else None',
145
            '2500 if item.id == 2215 else None',
146
            '1500 if item.id == 2230 else None',
147
            '1700 if item.id == 2005 else None',
148
            '1200 if item.id == 2022 else None'
149
        ]
150
    for expression in discount_expressions:
151
        discount = eval(expression)
152
 
153
        if discount is not None:
154
            return discount
155
 
156
    return None