Subversion Repositories SmartDukaan

Rev

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

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