Subversion Repositories SmartDukaan

Rev

Rev 5353 | Rev 5394 | 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
 
5390 varun.gupt 6
Galaxy Y Pro Duos B5512       Discount: Rs.502
7
Chat 322 C3222        Discount: Rs.171
8
Champ Deluxe Duos C3312       Discount: Rs.211
9
Champ Duos E2652       Discount: Rs.155
10
Champ 3.5G S3770       Discount: Rs.255
11
Corby II S3850       Discount: Rs.361
12
Star 3 Duos S5222       Discount: Rs.151
13
Chat 527 S5270       Discount: Rs.205
14
Galaxy Pocket S5300       Discount: Rs.245
15
Wave Y S5380       Discount: Rs.345
5288 varun.gupt 16
Metro C3530       Discount: Rs.251
17
Primo S5610       Discount: Rs.241
18
Star II S5263       Discount: Rs.301
19
Star II Duos C6712       Discount: Rs.251
20
Wave 525 S5253       Discount: Rs.391
21
Galaxy Y S5360       Discount: Rs.415
22
Galaxy Y Color S5360s       Discount: Rs.199
23
Galaxy Y Duos S6102       Discount: Rs.595
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
 
5288 varun.gupt 44
    #Allow only first 100 users to use the coupon
45
    count_coupon_usage = get_coupon_usage_count(coupon_code)
46
 
47
    if count_coupon_usage >= 100:
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 in (2091, 3882, 2527):  #Galaxy Y S5360
165
 
166
                has_qualified_model = True
167
 
168
                if line.actualPrice:
169
                    discount_value = 415
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
 
178
            elif line.itemId in (2629, 5839):  #Galaxy Y Duos S6102
179
 
180
                has_qualified_model = True
181
 
182
                if line.actualPrice:
183
                    discount_value = 595
184
 
185
            elif line.itemId == 2630:  #Galaxy Y Pro Duos B5512
186
 
187
                has_qualified_model = True
188
 
189
                if line.actualPrice:
190
                    discount_value = 502
191
 
5390 varun.gupt 192
            elif line.itemId in (1001, 2226, 1004, 1011, 998): #Champ Megacam C3303i
193
                has_qualified_model = True
194
 
195
                if line.actualPrice:    discount_value = 80
196
 
197
            elif line.itemId == 4629: #Champ Deluxe C3312s
198
                has_qualified_model = True
199
 
200
                if line.actualPrice:    discount_value = 191 
201
 
202
            elif line.itemId in (2532, 4689, 1500): #Metro Duos C3322
203
                has_qualified_model = True
204
 
205
                if line.actualPrice:    discount_value = 151 
206
 
207
            elif line.itemId in (2445, 4636): #Metro C3520
208
                has_qualified_model = True
209
 
210
                if line.actualPrice:    discount_value = 40
211
 
212
            elif line.itemId in (1537, 2227): #Star II Duos C6712
213
                has_qualified_model = True
214
 
215
                if line.actualPrice:    discount_value = 271 
216
 
217
            elif line.itemId in (5700, 5701): #E1200, E1205
218
                has_qualified_model = True
219
 
220
                if line.actualPrice:    discount_value = 61
221
 
222
            elif line.itemId == 2603: #Guru FM E1220
223
                has_qualified_model = True
224
 
225
                if line.actualPrice:    discount_value = 51
226
 
227
            elif line.itemId == 2470: #Omnia W I8350
228
                has_qualified_model = True
229
 
230
                if line.actualPrice:    discount_value = 701
231
 
232
            elif line.itemId in (1493, 1502): #Galaxy S II I9100
233
                has_qualified_model = True
234
 
235
                if line.actualPrice:    discount_value = 905
236
 
237
            elif line.itemId in (2215, 2481): #Galaxy Note N7000
238
                has_qualified_model = True
239
 
240
                if line.actualPrice:    discount_value = 901
241
 
5288 varun.gupt 242
            if discount_value > 0:
243
                discount = Discount()
244
                discount.cart_id = cart.id
245
                discount.item_id = line.itemId
246
                discount.discount = discount_value
247
                discount.quantity = line.quantity
248
 
249
                discounts.append(discount)
5390 varun.gupt 250
                line.discountedPrice = round(line.actualPrice - discount_value)
251
 
252
            total_selling_price += line.actualPrice * line.quantity
253
            total_discounted_price += line.discountedPrice * line.quantity
254
 
5288 varun.gupt 255
        if has_qualified_model is False:
5390 varun.gupt 256
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
5288 varun.gupt 257
 
258
        cart.totalPrice = total_selling_price
259
        cart.discountedPrice = total_discounted_price
260
 
261
    return cart, discounts
262
 
263
def getDiscountOnItem(item):
5298 varun.gupt 264
 
5288 varun.gupt 265
    discount_expressions = [
5390 varun.gupt 266
            '171 if item.id in (1010, 1451) else None',
267
            '211 if item.id in (3356, 4628, 5730, 2563, 3357) else None',
5298 varun.gupt 268
            '251 if item.id in (1012, 1452, 1453) else None',
5390 varun.gupt 269
            '155 if item.id in (999, 988, 5702) else None',
270
            '205 if item.id in (2576, 2067) else None',
271
            '255 if item.id in (2073, 2621) else None',
272
            '151 if item.id in (3358, 4643) else None',
5298 varun.gupt 273
            '241 if item.id in (2090, 2256) else None',
274
            '301 if item.id in (968, 995) else None',
5390 varun.gupt 275
            '361 if item.id in (996, 1000, 1524, 1563) else None',
5298 varun.gupt 276
            '251 if item.id in (1537, 2227) else None',
277
            '391 if item.id in (949, 4690, 948) else None',
5390 varun.gupt 278
            '245 if item.id == 5834 else None',
279
            '345 if item.id in (2537, 2622) else None',
5298 varun.gupt 280
            '415 if item.id in (2091, 3882, 2527) else None',
281
            '199 if item.id == 2446 else None',
282
            '595 if item.id in (2629, 5839) else None',
283
            '502 if item.id == 2630 else None'
5288 varun.gupt 284
        ]
285
    for expression in discount_expressions:
286
        discount = eval(expression)
287
 
288
        if discount is not None:
289
            return discount
5298 varun.gupt 290
 
5288 varun.gupt 291
    return None