Rev 2121 | Rev 2151 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 08-Jun-2011@author: varungupta'''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):#Allow a user to use the coupon only once.count_users_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)if count_users_usage > 0:raise PromotionException(111, 'You have already used this Coupon.')#Allow only first 100 users to use the couponcount_coupon_usage = get_coupon_usage_count(coupon_code)if count_coupon_usage >= 100:raise PromotionException(112, 'This promotion is over.')if cart.lines:total_selling_price = 0for line in cart.lines:#Disabling Coupon for Samsung Galaxy SIIif line.itemId == 1502:raise PromotionException(115, 'This coupon is not applicable for Samsung Galaxy S II')if line.actualPrice:total_selling_price += line.actualPrice * line.quantity#MAX Discount 1500if total_selling_price * 0.05 >= 1500:discount_perc = 1500 / total_selling_priceelif total_selling_price >= 5000:discount_perc = 0.05else:discount_perc = 0.03cart.totalPrice = round(total_selling_price, 2)cart.discountedPrice = round((1 - discount_perc) * total_selling_price, 2)for line in cart.lines:if line.actualPrice:line.discountedPrice = round((1 - discount_perc) * line.actualPrice, 2)print "The final price, after discount is " + str(cart.discountedPrice)return cart