Rev 6682 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 06-Dec-2011@author: varungupta'''from 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 PromotionException, Discountfrom shop2020.utils.Utils import to_py_dateimport datetimedef execute(cart, coupon_code, args):minPrice = 5000user_client = UserClient().get_client()user = user_client.getUserByCartId(cart.id)email = user.email.lower().strip()if args['couponType'] is not None and args['couponType'] != 'physical' and args['couponType'] != 'both':raise PromotionException(111, 'This coupon is not valid')if args['emails'] == '*' or email in args['emails']:discount_value = args['discount']else:raise PromotionException(111, 'You are not entitled to use this Gift Voucher')todate = datetime.datetime.now()if 'endOn' in args and todate > to_py_date(args['endOn']):raise PromotionException(113, 'This voucher is expired.')count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, user.userId)if count_coupon_usage >= args['usage_limit_for_user']:raise PromotionException(112, 'This Gift Voucher is used.')discounts = []if cart.lines:productFound = Falsefor line in cart.lines:if (not productFound and line.actualPrice >= minPrice):discount = Discount()discount.cart_id = cart.iddiscount.item_id = line.itemIddiscount.quantity = 1discount.discount = discount_valuediscounts.append(discount)productFound = Trueif productFound:cart.discountedPrice = cart.totalPrice - discount_valueelse:raise PromotionException(114, 'Your cart should have at least one item with selling price above Rs.' + str(minPrice)+ '.')return cart, discountsdef getDiscountOnItem(item):return None