Subversion Repositories SmartDukaan

Rev

Rev 5418 | Rev 5470 | 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
 
5394 varun.gupt 6
Allows first 300 users to use the coupon
7
 
5390 varun.gupt 8
Galaxy Y Pro Duos B5512       Discount: Rs.502
9
Chat 322 C3222        Discount: Rs.171
10
Champ Deluxe Duos C3312       Discount: Rs.211
11
Champ Duos E2652       Discount: Rs.155
12
Champ 3.5G S3770       Discount: Rs.255
13
Corby II S3850       Discount: Rs.361
14
Star 3 Duos S5222       Discount: Rs.151
15
Chat 527 S5270       Discount: Rs.205
16
Galaxy Pocket S5300       Discount: Rs.245
17
Wave Y S5380       Discount: Rs.345
5288 varun.gupt 18
Metro C3530       Discount: Rs.251
19
Primo S5610       Discount: Rs.241
20
Star II S5263       Discount: Rs.301
21
Star II Duos C6712       Discount: Rs.251
22
Wave 525 S5253       Discount: Rs.391
23
Galaxy Y Color S5360s       Discount: Rs.199
5390 varun.gupt 24
 
25
Champ Megacam C3303i    Discount: Rs.80
26
Champ Deluxe C3312s    Discount: Rs.191
27
Metro Duos C3322    Discount: Rs.151
28
Metro C3520    Discount: Rs.40
29
Star II Duos C6712    Discount: Rs.271
30
E1200, E1205    Discount: Rs.61
31
Guru FM E1220    Discount: Rs.51
32
Omnia W I8350    Discount: Rs.701
33
Galaxy S II I9100    Discount: Rs.905
34
Galaxy Note N7000    Discount: Rs.901
5288 varun.gupt 35
'''
36
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
37
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
5331 rajveer 38
from shop2020.clients.UserClient import UserClient
5288 varun.gupt 39
 
40
def execute(cart, coupon_code, args):
5331 rajveer 41
    user_client = UserClient().get_client()
42
    user = user_client.getUserByCartId(cart.id)
43
 
5394 varun.gupt 44
    #Allow only first 300 users to use the coupon
5288 varun.gupt 45
    count_coupon_usage = get_coupon_usage_count(coupon_code)
46
 
5394 varun.gupt 47
    if count_coupon_usage >= 300:
5288 varun.gupt 48
        raise PromotionException(112, 'This promotion is over.')
49
 
5353 varun.gupt 50
    if get_coupon_usage_count_by_user(coupon_code, user.userId) > 0:
5288 varun.gupt 51
        raise PromotionException(112, 'This promotion is over.')
52
 
53
    discounts = []
54
 
55
    if cart.lines:
56
        total_selling_price = 0
57
        total_discounted_price = 0
58
 
59
        has_qualified_model = False
60
 
61
        for line in cart.lines:
62
 
63
            line.discountedPrice = line.actualPrice
64
            discount_value = 0
65
 
66
            if line.itemId in (1010, 1451):  #Chat 322 C3222
67
 
68
                has_qualified_model = True
69
 
70
                if line.actualPrice:
5390 varun.gupt 71
                    discount_value = 171
5288 varun.gupt 72
 
73
            elif line.itemId in (3356, 4628, 5730, 2563, 3357):  #Champ Deluxe Duos C3312
74
 
75
                has_qualified_model = True
76
 
77
                if line.actualPrice:
5390 varun.gupt 78
                    discount_value = 211
5288 varun.gupt 79
 
80
            elif line.itemId in (1012, 1452, 1453):  #Metro C3530
81
 
82
                has_qualified_model = True
83
 
84
                if line.actualPrice:
85
                    discount_value = 251
86
 
87
            elif line.itemId in (999, 988, 5702):  #Champ Duos E2652
88
 
89
                has_qualified_model = True
90
 
91
                if line.actualPrice:
5390 varun.gupt 92
                    discount_value = 155
5288 varun.gupt 93
 
94
            elif line.itemId in (2576, 2067):  #Chat 527 S5270
95
 
96
                has_qualified_model = True
97
 
98
                if line.actualPrice:
5390 varun.gupt 99
                    discount_value = 205
5288 varun.gupt 100
 
101
            elif line.itemId in (2073, 2621):  #Champ 3.5G S3770
102
 
103
                has_qualified_model = True
104
 
105
                if line.actualPrice:
5390 varun.gupt 106
                    discount_value = 255
5288 varun.gupt 107
 
108
            elif line.itemId in (3358, 4643):  #Star 3 Duos S5222
109
 
110
                has_qualified_model = True
111
 
112
                if line.actualPrice:
5390 varun.gupt 113
                    discount_value = 151
5288 varun.gupt 114
 
115
            elif line.itemId in (2090, 2256):  #Primo S5610
116
 
117
                has_qualified_model = True
118
 
119
                if line.actualPrice:
120
                    discount_value = 241
121
 
122
            elif line.itemId in (968, 995):  #Star II S5263
123
 
124
                has_qualified_model = True
125
 
126
                if line.actualPrice:
127
                    discount_value = 301
128
 
129
            elif line.itemId in (996, 1000, 1524, 1563):  #Corby II S3850
130
 
131
                has_qualified_model = True
132
 
133
                if line.actualPrice:
5390 varun.gupt 134
                    discount_value = 361
5288 varun.gupt 135
 
136
            elif line.itemId in (1537, 2227):  #Star II Duos C6712
137
 
138
                has_qualified_model = True
139
 
140
                if line.actualPrice:
141
                    discount_value = 251
142
 
143
            elif line.itemId in (949, 4690, 948):  #Wave 525 S5253
144
 
145
                has_qualified_model = True
146
 
147
                if line.actualPrice:
148
                    discount_value = 391
149
 
150
            elif line.itemId == 5834:  #Galaxy Pocket S5300
151
 
152
                has_qualified_model = True
153
 
154
                if line.actualPrice:
5390 varun.gupt 155
                    discount_value = 245
5288 varun.gupt 156
 
157
            elif line.itemId in (2537, 2622):  #Wave Y S5380
158
 
159
                has_qualified_model = True
160
 
161
                if line.actualPrice:
5390 varun.gupt 162
                    discount_value = 345
5288 varun.gupt 163
 
164
            elif line.itemId == 2446:  #Galaxy Y Color S5360s
165
 
166
                has_qualified_model = True
167
 
168
                if line.actualPrice:
169
                    discount_value = 199
170
 
171
            elif line.itemId == 2630:  #Galaxy Y Pro Duos B5512
172
 
173
                has_qualified_model = True
174
 
175
                if line.actualPrice:
176
                    discount_value = 502
177
 
5390 varun.gupt 178
            elif line.itemId in (1001, 2226, 1004, 1011, 998): #Champ Megacam C3303i
179
                has_qualified_model = True
180
 
181
                if line.actualPrice:    discount_value = 80
182
 
183
            elif line.itemId == 4629: #Champ Deluxe C3312s
184
                has_qualified_model = True
185
 
186
                if line.actualPrice:    discount_value = 191 
187
 
188
            elif line.itemId in (2532, 4689, 1500): #Metro Duos C3322
189
                has_qualified_model = True
190
 
191
                if line.actualPrice:    discount_value = 151 
192
 
193
            elif line.itemId in (2445, 4636): #Metro C3520
194
                has_qualified_model = True
195
 
196
                if line.actualPrice:    discount_value = 40
197
 
198
            elif line.itemId in (1537, 2227): #Star II Duos C6712
199
                has_qualified_model = True
200
 
201
                if line.actualPrice:    discount_value = 271 
202
 
203
            elif line.itemId in (5700, 5701): #E1200, E1205
204
                has_qualified_model = True
205
 
206
                if line.actualPrice:    discount_value = 61
207
 
208
            elif line.itemId == 2603: #Guru FM E1220
209
                has_qualified_model = True
210
 
211
                if line.actualPrice:    discount_value = 51
212
 
213
            elif line.itemId == 2470: #Omnia W I8350
214
                has_qualified_model = True
215
 
216
                if line.actualPrice:    discount_value = 701
217
 
218
            elif line.itemId in (1493, 1502): #Galaxy S II I9100
219
                has_qualified_model = True
220
 
221
                if line.actualPrice:    discount_value = 905
222
 
223
            elif line.itemId in (2215, 2481): #Galaxy Note N7000
224
                has_qualified_model = True
225
 
226
                if line.actualPrice:    discount_value = 901
227
 
5288 varun.gupt 228
            if discount_value > 0:
229
                discount = Discount()
230
                discount.cart_id = cart.id
231
                discount.item_id = line.itemId
232
                discount.discount = discount_value
233
                discount.quantity = line.quantity
234
 
235
                discounts.append(discount)
5390 varun.gupt 236
                line.discountedPrice = round(line.actualPrice - discount_value)
237
 
238
            total_selling_price += line.actualPrice * line.quantity
239
            total_discounted_price += line.discountedPrice * line.quantity
240
 
5288 varun.gupt 241
        if has_qualified_model is False:
5390 varun.gupt 242
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
5288 varun.gupt 243
 
244
        cart.totalPrice = total_selling_price
245
        cart.discountedPrice = total_discounted_price
246
 
247
    return cart, discounts
248
 
249
def getDiscountOnItem(item):
5298 varun.gupt 250
 
5288 varun.gupt 251
    discount_expressions = [
5390 varun.gupt 252
            '171 if item.id in (1010, 1451) else None',
253
            '211 if item.id in (3356, 4628, 5730, 2563, 3357) else None',
5298 varun.gupt 254
            '251 if item.id in (1012, 1452, 1453) else None',
5390 varun.gupt 255
            '155 if item.id in (999, 988, 5702) else None',
256
            '205 if item.id in (2576, 2067) else None',
257
            '255 if item.id in (2073, 2621) else None',
258
            '151 if item.id in (3358, 4643) else None',
5298 varun.gupt 259
            '241 if item.id in (2090, 2256) else None',
260
            '301 if item.id in (968, 995) else None',
5390 varun.gupt 261
            '361 if item.id in (996, 1000, 1524, 1563) else None',
5298 varun.gupt 262
            '251 if item.id in (1537, 2227) else None',
263
            '391 if item.id in (949, 4690, 948) else None',
5390 varun.gupt 264
            '245 if item.id == 5834 else None',
265
            '345 if item.id in (2537, 2622) else None',
5298 varun.gupt 266
            '199 if item.id == 2446 else None',
5418 varun.gupt 267
            '502 if item.id == 2630 else None',
268
            '80 if item.id in (1001, 2226, 1004, 1011, 998) else None',
269
            '191 if item.id == 4629 else None',
270
            '151 if item.id in (2532, 4689, 1500) else None',
271
            '40 if item.id in (2445, 4636) else None',
272
            '271 if item.id in (1537, 2227) else None',
273
            '61 if item.id in (5700, 5701) else None',
274
            '51 if item.id == 2603 else None',
275
            '701 if item.id == 2470 else None',
276
            '905 if item.id in (1493, 1502) else None',
277
            '901 if item.id in (2215, 2481) else None'
5288 varun.gupt 278
        ]
279
    for expression in discount_expressions:
280
        discount = eval(expression)
281
 
282
        if discount is not None:
283
            return discount
5298 varun.gupt 284
 
5288 varun.gupt 285
    return None