Rev 3256 | Rev 3384 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 06-Sept-2011@author: Varun Gupta'''from shop2020.thriftpy.model.v1.user.ttypes import PromotionExceptionfrom shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_countfrom shop2020.clients.CatalogClient import CatalogClientfrom shop2020.thriftpy.model.v1.catalog.ttypes import Itemdef execute(cart, coupon_code, args):#Allow only first 1000 users to use the couponcount_coupon_usage = get_coupon_usage_count(coupon_code)if count_coupon_usage >= 1000:raise PromotionException(112, 'This promotion is over.')if cart.lines:total_selling_price = 0total_discounted_price = 0has_qualified_model = Falsefor line in cart.lines:'''Blackberry 9900 Bold 4 32490 OFF Rs.2000 30490Samsung i9100 Galaxy S II 29900 OFF Rs.1000 28900Spice QT-58 Blueberry Mini 2849 OFF 20% 2279Spice QT-61 Blueberry Exp 3261 OFF 20% 2609Nokia All Models Below Rs.5000 SP OFF Rs.200/-Nokia All Models Above Rs.5001 SP OFF Rs.500/-'''line.discountedPrice = line.actualPriceif line.itemId in (159, 160, 161, 1557, 1558): #Spice QT-58/61has_qualified_model = Trueif line.actualPrice:line.discountedPrice = round(line.actualPrice * 0.8)elif line.itemId == 1591: #Blackberry 9900 Bold 4has_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 2000elif line.itemId == 1502: #Galaxy SIIhas_qualified_model = Trueif line.actualPrice:line.discountedPrice = line.actualPrice - 1000else:print 'Can be Nokia'catalog_client = CatalogClient().get_client()item = catalog_client.getItem(line.itemId)print 'Item: %d, Brand: *%s*' % (line.itemId, item.brand.lower())if item.brand.lower() == 'nokia':has_qualified_model = Trueprint 'Brand matched'discount_value = 200 if line.actualPrice < 5001 else 500line.discountedPrice = line.actualPrice - discount_valueelse:print 'Brand not matched'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 selected handsets.')cart.totalPrice = total_selling_pricecart.discountedPrice = total_discounted_pricereturn cart