Rev 5470 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 28-May-2012@author: Varun GuptaAllows first 300 users to use the couponChat 322 C3222 Discount: Rs.171Champ Duos E2652 Discount: Rs.155Champ 3.5G S3770 Discount: Rs.255Corby II S3850 Discount: Rs.361Chat 527 S5270 Discount: Rs.205Metro C3530 Discount: Rs.251Primo S5610 Discount: Rs.241Star II S5263 Discount: Rs.301Star II Duos C6712 Discount: Rs.251Wave 525 S5253 Discount: Rs.391Galaxy Y Color S5360s Discount: Rs.199Champ Megacam C3303i Discount: Rs.80Champ Deluxe C3312s Discount: Rs.191Metro C3520 Discount: Rs.40Star II Duos C6712 Discount: Rs.271E1200, E1205 Discount: Rs.61Guru FM E1220 Discount: Rs.51Omnia W I8350 Discount: Rs.701'''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 300 users to use the couponcount_coupon_usage = get_coupon_usage_count(coupon_code)if count_coupon_usage >= 300:raise PromotionException(112, 'This promotion is over.')if get_coupon_usage_count_by_user(coupon_code, user.userId) > 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 = 171elif line.itemId in (1012, 1452, 1453): #Metro C3530has_qualified_model = Trueif line.actualPrice:discount_value = 251elif line.itemId in (999, 988, 5702): #Champ Duos E2652has_qualified_model = Trueif line.actualPrice:discount_value = 155elif line.itemId in (2576, 2067): #Chat 527 S5270has_qualified_model = Trueif line.actualPrice:discount_value = 205elif line.itemId in (2073, 2621): #Champ 3.5G S3770has_qualified_model = Trueif line.actualPrice:discount_value = 255elif line.itemId in (2090, 2256): #Primo S5610has_qualified_model = Trueif line.actualPrice:discount_value = 241elif line.itemId in (968, 995): #Star II S5263has_qualified_model = Trueif line.actualPrice:discount_value = 301elif line.itemId in (996, 1000, 1524, 1563): #Corby II S3850has_qualified_model = Trueif line.actualPrice:discount_value = 361elif line.itemId in (1537, 2227): #Star II Duos C6712has_qualified_model = Trueif line.actualPrice:discount_value = 251elif line.itemId in (949, 4690, 948): #Wave 525 S5253has_qualified_model = Trueif line.actualPrice:discount_value = 391elif line.itemId == 2446: #Galaxy Y Color S5360shas_qualified_model = Trueif line.actualPrice:discount_value = 199elif line.itemId in (1001, 2226, 1004, 1011, 998): #Champ Megacam C3303ihas_qualified_model = Trueif line.actualPrice: discount_value = 80elif line.itemId == 4629: #Champ Deluxe C3312shas_qualified_model = Trueif line.actualPrice: discount_value = 191elif line.itemId in (2445, 4636): #Metro C3520has_qualified_model = Trueif line.actualPrice: discount_value = 40elif line.itemId in (1537, 2227): #Star II Duos C6712has_qualified_model = Trueif line.actualPrice: discount_value = 271elif line.itemId in (5700, 5701): #E1200, E1205has_qualified_model = Trueif line.actualPrice: discount_value = 61elif line.itemId == 2603: #Guru FM E1220has_qualified_model = Trueif line.actualPrice: discount_value = 51elif line.itemId == 2470: #Omnia W I8350has_qualified_model = Trueif line.actualPrice: discount_value = 701if discount_value > 0:discount = Discount()discount.cart_id = cart.iddiscount.item_id = line.itemIddiscount.discount = discount_valuediscount.quantity = line.quantitydiscounts.append(discount)line.discountedPrice = round(line.actualPrice - discount_value)total_selling_price += line.actualPrice * line.quantitytotal_discounted_price += line.discountedPrice * line.quantityif has_qualified_model is False:raise PromotionException(115, 'This coupon is applicable only for selective handsets.')cart.totalPrice = total_selling_pricecart.discountedPrice = total_discounted_pricereturn cart, discountsdef getDiscountOnItem(item):discount_expressions = ['171 if item.id in (1010, 1451) else None','251 if item.id in (1012, 1452, 1453) else None','155 if item.id in (999, 988, 5702) else None','205 if item.id in (2576, 2067) else None','255 if item.id in (2073, 2621) else None','241 if item.id in (2090, 2256) else None','301 if item.id in (968, 995) else None','361 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','199 if item.id == 2446 else None','80 if item.id in (1001, 2226, 1004, 1011, 998) else None','191 if item.id == 4629 else None','40 if item.id in (2445, 4636) else None','271 if item.id in (1537, 2227) else None','61 if item.id in (5700, 5701) else None','51 if item.id == 2603 else None','701 if item.id == 2470 else None']for expression in discount_expressions:discount = eval(expression)if discount is not None:return discountreturn None