Rev 4856 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 06-Jul-2011@author: Varun Gupta'''from shop2020.thriftpy.model.v1.user.ttypes import PromotionExceptionfrom shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_userdef execute(cart, coupon_code, args):if 'items' not in args or 'discount' not in args or 'handset_display_name' not in args:raise PromotionException(109, 'Error in rule arguments.')if 'usage_limit' in args and args['usage_limit'] is not None:if args['usage_limit'] <= get_coupon_usage_count(coupon_code):raise PromotionException(112, 'This promotion is over.')if 'usage_limit_for_user' in args and args['usage_limit_for_user'] is not None:if args['usage_limit_for_user'] <= get_coupon_usage_count_by_user(coupon_code):raise PromotionException(111, 'You have already used this coupon maximum possible times.')if not cart.lines:#TODO: Cart has no lines.return carttotal_selling_price = 0total_discounted_price = 0cart_has_specified_item = Falsefor line in cart.lines:total_selling_price += line.actualPrice * line.quantityif line.itemId in args['items']:cart_has_specified_item = Trueline.discountedPrice = round(line.actualPrice - args['discount'], 4)total_discounted_price += round(line.discountedPrice * line.quantity, 4)else:total_discounted_price += round(line.actualPrice * line.quantity, 4)if cart_has_specified_item is False:raise PromotionException(115, 'This coupon is applicable only for ' + args['handset_display_name'])cart.totalPrice = round(total_selling_price, 4)cart.discountedPrice = total_discounted_pricereturn cart