Subversion Repositories SmartDukaan

Rev

Rev 4190 | 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
 
23
def execute(cart, coupon_code, args):
24
 
25
    #Allow only first 100 users to use the coupon
26
    count_coupon_usage = get_coupon_usage_count(coupon_code)
27
 
28
    if count_coupon_usage >= 100:
29
        raise PromotionException(112, 'This promotion is over.')
30
 
3559 varun.gupt 31
    discounts = []
32
 
3535 varun.gupt 33
    if cart.lines:
34
        total_selling_price = 0
35
        total_discounted_price = 0
36
 
37
        has_qualified_model = False
38
 
39
        for line in cart.lines:
40
 
41
            line.discountedPrice = line.actualPrice
3559 varun.gupt 42
            discount_value = 0
3535 varun.gupt 43
 
4155 varun.gupt 44
            if line.itemId in [2177, 2178, 2179, 2180, 2181, 2182]:  #iPad 16GB, iPad 32GB, iPad 64GB
3535 varun.gupt 45
 
46
                has_qualified_model = True
47
 
48
                if line.actualPrice:
4155 varun.gupt 49
                    line.discountedPrice = line.actualPrice - 900
50
                    discount_value = 900
3535 varun.gupt 51
 
4155 varun.gupt 52
            elif line.itemId == 2199:   #BlackBerry PlayBook 32GB
3535 varun.gupt 53
 
54
                has_qualified_model = True
55
 
56
                if line.actualPrice:
4155 varun.gupt 57
                    line.discountedPrice = line.actualPrice - 250
58
                    discount_value = 250
3535 varun.gupt 59
 
4155 varun.gupt 60
            elif line.itemId == 1550:   #BlackBerry PlayBook 64GB
3535 varun.gupt 61
 
62
                has_qualified_model = True
63
 
64
                if line.actualPrice:
4155 varun.gupt 65
                    line.discountedPrice = line.actualPrice - 2500
66
                    discount_value = 2500
67
 
68
            elif line.itemId == 1551:   #HTC P510e Flyer
69
 
70
                has_qualified_model = True
71
 
72
                if line.actualPrice:
3535 varun.gupt 73
                    line.discountedPrice = line.actualPrice - 500
3559 varun.gupt 74
                    discount_value = 500
3535 varun.gupt 75
 
4155 varun.gupt 76
            elif line.itemId == 1552:   #Motorola MZ601 Xoom
3535 varun.gupt 77
 
78
                has_qualified_model = True
79
 
80
                if line.actualPrice:
4155 varun.gupt 81
                    line.discountedPrice = line.actualPrice - 2000
82
                    discount_value = 2000
3535 varun.gupt 83
 
4155 varun.gupt 84
            elif line.itemId == 2215:   #Samsung N7000 Galaxy Note
3535 varun.gupt 85
 
86
                has_qualified_model = True
87
 
88
                if line.actualPrice:
3713 varun.gupt 89
                    line.discountedPrice = line.actualPrice - 2500
90
                    discount_value = 2500
3535 varun.gupt 91
 
4155 varun.gupt 92
            elif line.itemId == 2230:   #Samsung P7300 Galaxy Tab
3535 varun.gupt 93
 
94
                has_qualified_model = True
95
 
96
                if line.actualPrice:
3713 varun.gupt 97
                    line.discountedPrice = line.actualPrice - 1500
98
                    discount_value = 1500
3535 varun.gupt 99
 
4190 varun.gupt 100
            elif line.itemId in (2005, 2194):   #Samsung P7500 Galaxy Tab
4155 varun.gupt 101
 
102
                has_qualified_model = True
103
 
104
                if line.actualPrice:
105
                    line.discountedPrice = line.actualPrice - 1700
106
                    discount_value = 1700
107
 
108
            elif line.itemId == 2022:   #Spice Mi-720 Tab
109
 
110
                has_qualified_model = True
111
 
112
                if line.actualPrice:
113
                    line.discountedPrice = line.actualPrice - 1200
114
                    discount_value = 1200
115
 
3535 varun.gupt 116
            total_selling_price += line.actualPrice * line.quantity
3559 varun.gupt 117
            total_discounted_price += line.discountedPrice * line.quantity
3535 varun.gupt 118
 
3559 varun.gupt 119
            if discount_value > 0:
120
                discount = Discount()
121
                discount.cart_id = cart.id
122
                discount.item_id = line.itemId
123
                discount.discount = discount_value
124
                discount.quantity = line.quantity
125
 
126
                discounts.append(discount)
127
 
3535 varun.gupt 128
        if has_qualified_model is False:
129
            raise PromotionException(115, 'This coupon is applicable only for selective tablets.')
130
 
131
        cart.totalPrice = total_selling_price
132
        cart.discountedPrice = total_discounted_price
133
 
4189 varun.gupt 134
    return cart, discounts
135
 
136
 
137
def getDiscountOnItem(item):
138
    discount_expressions = [
139
            '900 if item.id in [2177, 2178, 2179, 2180, 2181, 2182] else None',
140
            '250 if item.id == 2199 else None',
141
            '2500 if item.id == 1550 else None',
142
            '500 if item.id == 1551 else None',
143
            '2000 if item.id == 1552 else None',
144
            '2500 if item.id == 2215 else None',
145
            '1500 if item.id == 2230 else None',
146
            '1700 if item.id == 2005 else None',
147
            '1200 if item.id == 2022 else None'
148
        ]
149
    for expression in discount_expressions:
150
        discount = eval(expression)
151
 
152
        if discount is not None:
153
            return discount
154
 
155
    return None