Rev 4190 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 01-Oct-2011@author: Varun GuptaMax uses: 100Apple 16GB iPad 2 Wi-Fi+3G Rs.900 offApple 32GB iPad 2 Wi-Fi+3G Rs.900 offApple 64GB iPad 2 Wi-Fi+3G Rs.900 offBlackBerry playbook 32gb Rs.250 offBlackBerry playbook 64gb Rs.2500 offHTC P510e Flyer Rs.500 offMotorola MZ601 Xoom Rs.2000 offSamsung N7000 Galaxy Note Rs.2500 offSamsung P7300 Tablet 8.9" Rs.1500 offSamsung P7500 Galaxy Tab 750 Rs.1800 offSpice Mi-720 Tab Rs.1200 off'''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_userdef execute(cart, coupon_code, args):#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.')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 [2177, 2178, 2179, 2180, 2181, 2182]: #iPad 16GB, iPad 32GB, iPad 64GBhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 900discount_value = 900elif line.itemId == 2199: #BlackBerry PlayBook 32GBhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 250discount_value = 250elif line.itemId == 1550: #BlackBerry PlayBook 64GBhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 2500discount_value = 2500elif line.itemId == 1551: #HTC P510e Flyerhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 500discount_value = 500elif line.itemId == 1552: #Motorola MZ601 Xoomhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 2000discount_value = 2000elif line.itemId == 2215: #Samsung N7000 Galaxy Notehas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 2500discount_value = 2500elif line.itemId == 2230: #Samsung P7300 Galaxy Tabhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 1500discount_value = 1500elif line.itemId in (2005, 2194): #Samsung P7500 Galaxy Tabhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 1700discount_value = 1700elif line.itemId == 2022: #Spice Mi-720 Tabhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 1200discount_value = 1200total_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 tablets.')cart.totalPrice = total_selling_pricecart.discountedPrice = total_discounted_pricereturn cart, discountsdef getDiscountOnItem(item):discount_expressions = ['900 if item.id in [2177, 2178, 2179, 2180, 2181, 2182] else None','250 if item.id == 2199 else None','2500 if item.id == 1550 else None','500 if item.id == 1551 else None','2000 if item.id == 1552 else None','2500 if item.id == 2215 else None','1500 if item.id == 2230 else None','1700 if item.id == 2005 else None','1200 if item.id == 2022 else None']for expression in discount_expressions:discount = eval(expression)if discount is not None:return discountreturn None