Blame | Last modification | View Log | RSS feed
'''Created on 06-Jul-2011@author: Varun Gupta'''from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discountfrom shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_userfrom shop2020.clients.UserClient import UserClientitemTuple = {3880 : 230, 2082 : 230, 2083 : 230, 7297 : 230, 7548 : 230, \7813:639, 7841:639, 7848:639, 7849:639, \6803: 306, 6748: 306, \2273: 399, 7768: 399}def execute(cart, coupon_code, args):if 50 <= get_coupon_usage_count(coupon_code):raise PromotionException(112, 'This promotion is over.')user_client = UserClient().get_client()user = user_client.getUserByCartId(cart.id)if 2 <= get_coupon_usage_count_by_user(coupon_code, user.userId):raise PromotionException(111, 'You have already used this coupon maximum possible times.')if not cart.lines:return carttotal_selling_price = 0total_discounted_price = 0cart_has_specified_item = Falsediscounts = []for line in cart.lines:total_selling_price += line.actualPrice * line.quantitydiscount_value = 0discount = itemTuple.get(line.itemId)if discount:cart_has_specified_item = Trueline.discountedPrice = round(line.actualPrice - discount, 4)total_discounted_price += round(line.discountedPrice * line.quantity, 4)discount_value = discountelse:total_discounted_price += round(line.actualPrice * line.quantity, 4)if discount_value > 0:discount1 = Discount()discount1.discount = discount_valuediscount1.quantity = line.quantitydiscount1.cart_id = cart.iddiscount1.item_id = line.itemIddiscounts.append(discount1)if cart_has_specified_item is False:raise PromotionException(115, 'This coupon is only applicable on specific items')cart.totalPrice = round(total_selling_price, 4)cart.discountedPrice = total_discounted_pricereturn cart, discountsdef getDiscountOnItem(item):if item.id in itemTuple:return 1000return None