Subversion Repositories SmartDukaan

Rev

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