Subversion Repositories SmartDukaan

Rev

Rev 5353 | Rev 5394 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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