Rev 5298 | Rev 5353 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 28-May-2012@author: Varun GuptaChat 322 C3222 Discount: Rs.121Champ Deluxe Duos C3312 Discount: Rs.191Metro C3530 Discount: Rs.251Champ Duos E2652 Discount: Rs.120Chat 527 S5270 Discount: Rs.121Champ 3.5G S3770 Discount: Rs.215Star 3 Duos S5222 Discount: Rs.161Primo S5610 Discount: Rs.241Star II S5263 Discount: Rs.301Corby II S3850 Discount: Rs.365Star II Duos C6712 Discount: Rs.251Wave 525 S5253 Discount: Rs.391Galaxy Pocket S5300 Discount: Rs.101Wave Y S5380 Discount: Rs.341Galaxy Y S5360 Discount: Rs.415Galaxy Y Color S5360s Discount: Rs.199Galaxy Y Duos S6102 Discount: Rs.595Galaxy Y Pro Duos B5512 Discount: Rs.502'''from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discountfrom shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_userfrom shop2020.clients.UserClient import UserClientdef execute(cart, coupon_code, args):user_client = UserClient().get_client()user = user_client.getUserByCartId(cart.id)#Allow only first 100 users to use the couponcount_coupon_usage = get_coupon_usage_count(coupon_code)if count_coupon_usage >= 100:raise PromotionException(112, 'This promotion is over.')if get_coupon_usage_count_by_user(coupon_code, user.id) > 0:raise PromotionException(112, 'This promotion is over.')discounts = []if cart.lines:total_selling_price = 0total_discounted_price = 0has_qualified_model = Falsefor line in cart.lines:line.discountedPrice = line.actualPricediscount_value = 0if line.itemId in (1010, 1451): #Chat 322 C3222has_qualified_model = Trueif line.actualPrice:discount_value = 121line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (3356, 4628, 5730, 2563, 3357): #Champ Deluxe Duos C3312has_qualified_model = Trueif line.actualPrice:discount_value = 191line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (1012, 1452, 1453): #Metro C3530has_qualified_model = Trueif line.actualPrice:discount_value = 251line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (999, 988, 5702): #Champ Duos E2652has_qualified_model = Trueif line.actualPrice:discount_value = 120line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (2576, 2067): #Chat 527 S5270has_qualified_model = Trueif line.actualPrice:discount_value = 121line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (2073, 2621): #Champ 3.5G S3770has_qualified_model = Trueif line.actualPrice:discount_value = 215line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (3358, 4643): #Star 3 Duos S5222has_qualified_model = Trueif line.actualPrice:discount_value = 161line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (2090, 2256): #Primo S5610has_qualified_model = Trueif line.actualPrice:discount_value = 241line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (968, 995): #Star II S5263has_qualified_model = Trueif line.actualPrice:discount_value = 301line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (996, 1000, 1524, 1563): #Corby II S3850has_qualified_model = Trueif line.actualPrice:discount_value = 365line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (1537, 2227): #Star II Duos C6712has_qualified_model = Trueif line.actualPrice:discount_value = 251line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (949, 4690, 948): #Wave 525 S5253has_qualified_model = Trueif line.actualPrice:discount_value = 391line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId == 5834: #Galaxy Pocket S5300has_qualified_model = Trueif line.actualPrice:discount_value = 101line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (2537, 2622): #Wave Y S5380has_qualified_model = Trueif line.actualPrice:discount_value = 341line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (2091, 3882, 2527): #Galaxy Y S5360has_qualified_model = Trueif line.actualPrice:discount_value = 415line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId == 2446: #Galaxy Y Color S5360shas_qualified_model = Trueif line.actualPrice:discount_value = 199line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId in (2629, 5839): #Galaxy Y Duos S6102has_qualified_model = Trueif line.actualPrice:discount_value = 595line.discountedPrice = round(line.actualPrice - discount_value)elif line.itemId == 2630: #Galaxy Y Pro Duos B5512has_qualified_model = Trueif line.actualPrice:discount_value = 502line.discountedPrice = round(line.actualPrice - discount_value)total_selling_price += line.actualPrice * line.quantitytotal_discounted_price += line.discountedPrice * line.quantityif discount_value > 0:discount = Discount()discount.cart_id = cart.iddiscount.item_id = line.itemIddiscount.discount = discount_valuediscount.quantity = line.quantitydiscounts.append(discount)if has_qualified_model is False:raise PromotionException(115, 'This coupon is applicable only for selective Blackberry handsets.')cart.totalPrice = total_selling_pricecart.discountedPrice = total_discounted_pricereturn cart, discountsdef getDiscountOnItem(item):discount_expressions = ['121 if item.id in (1010, 1451) else None','191 if item.id in (3356, 4628, 5730, 2563, 3357) else None','251 if item.id in (1012, 1452, 1453) else None','120 if item.id in (999, 988, 5702) else None','121 if item.id in (2576, 2067) else None','215 if item.id in (2073, 2621) else None','161 if item.id in (3358, 4643) else None','241 if item.id in (2090, 2256) else None','301 if item.id in (968, 995) else None','365 if item.id in (996, 1000, 1524, 1563) else None','251 if item.id in (1537, 2227) else None','391 if item.id in (949, 4690, 948) else None','101 if item.id == 5834 else None','341 if item.id in (2537, 2622) else None','415 if item.id in (2091, 3882, 2527) else None','199 if item.id == 2446 else None','595 if item.id in (2629, 5839) else None','502 if item.id == 2630 else None']for expression in discount_expressions:discount = eval(expression)if discount is not None:return discountreturn None