Rev 4405 | Rev 4941 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 06-Dec-2011@author: varunguptaraghvendra.saboo@gmail.com will get Rs.200 off on one transactionmichaelananth.ravichandran@tcs.com will get Rs.200 off on one transactionnc41@indiatimes.com will get Rs.200 off on one transaction'''from shop2020.thriftpy.model.v1.user.ttypes import PromotionExceptionfrom shop2020.clients.UserClient import UserClientfrom shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_userfrom shop2020.thriftpy.model.v1.user.ttypes import Discountdef execute(cart, coupon_code, args):user_client = UserClient().get_client()user = user_client.getUserById(cart.userId)email = user.email.lower().strip()if email in ('raghvendra.saboo@gmail.com', 'michaelananth.ravichandran@tcs.com', 'nc41@indiatimes.com'):discount_value = 200else:raise PromotionException(111, 'You are not allowed to use this coupon')#Allow only first 1000 users to use the couponcount_coupon_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)if count_coupon_usage > 0:raise PromotionException(112, 'You have already used the coupon.')discounts = []if cart.lines:total_selling_price = 0total_discounted_price = 0has_used_coupon = Falsefor line in cart.lines:line.discountedPrice = line.actualPriceif has_used_coupon:breakline.discountedPrice = line.actualPrice - discount_valuehas_used_coupon = Truetotal_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 = 1discounts.append(discount)cart.totalPrice = total_selling_pricecart.discountedPrice = total_discounted_pricereturn cart, discounts