Rev 5500 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 27-June-2012@author: Varun GuptaMax Uses: 200Samsung Galaxy Ace S5830i Rs.401 offSamsung Galaxy Ace Duos S6802 Rs.401 offHTC One V T320e Rs.512 offHTC Desire C A320e Rs.762 off'''from shop2020.thriftpy.model.v1.user.ttypes import PromotionExceptionfrom shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_countfrom shop2020.thriftpy.model.v1.user.ttypes import Discountfrom shop2020.clients.UserClient import UserClientdef execute(cart, coupon_code, args):user_client = UserClient().get_client()user = user_client.getUserByCartId(cart.id)#Allow only first 2000 users to use the couponcount_coupon_usage = get_coupon_usage_count(coupon_code)if count_coupon_usage >= 200: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 (6829, 7243, 7298): #Samsung Galaxy Ace Duos S6802 & Galaxy Ace S5830ihas_qualified_model = Trueif line.actualPrice:line.discountedPrice = round(line.actualPrice - 401)discount_value = 401elif line.itemId == 4645: #HTC One V T320ehas_qualified_model = Trueif line.actualPrice:line.discountedPrice = round(line.actualPrice - 512)discount_value = 512elif line.itemId in (6747, 7127): #HTC Desire C A320ehas_qualified_model = Trueif line.actualPrice:line.discountedPrice = round(line.actualPrice - 762)discount_value = 762total_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 handsets.')cart.totalPrice = total_selling_pricecart.discountedPrice = total_discounted_pricereturn cart, discountsdef getDiscountOnItem(item):return None