Subversion Repositories SmartDukaan

Rev

Rev 5501 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 27-June-2012
@author: Varun Gupta

Samsung Galaxy Ace S5830i    Rs.401 off
Samsung Galaxy Ace Duos S6802    Rs.401 off
HTC One V T320e    Rs.512 off
HTC Desire C A320e    Rs.762 off
'''
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
from shop2020.thriftpy.model.v1.user.ttypes import Discount

def execute(cart, coupon_code, args):
    discounts = []
    
    if cart.lines:
        total_selling_price = 0
        total_discounted_price = 0
        
        has_qualified_model = False
        
        for line in cart.lines:
            
            line.discountedPrice = line.actualPrice
            discount_value = 0
            
            if line.itemId in (6829, 7243, 7298):  #Samsung Galaxy Ace Duos S6802 & Galaxy Ace S5830i
                
                has_qualified_model = True
                
                if line.actualPrice:
                    line.discountedPrice = round(line.actualPrice - 401)
                    discount_value = 401
            
            elif line.itemId == 4645:  #HTC One V T320e
                
                has_qualified_model = True
                
                if line.actualPrice:
                    line.discountedPrice = round(line.actualPrice - 512)
                    discount_value = 512
            
            elif line.itemId in (6747, 7127):  #HTC Desire C A320e
                
                has_qualified_model = True
                
                if line.actualPrice:
                    line.discountedPrice = round(line.actualPrice - 762)
                    discount_value = 762
            
            total_selling_price += line.actualPrice * line.quantity
            total_discounted_price += line.discountedPrice * line.quantity
            
            if discount_value > 0:
                discount = Discount()
                discount.cart_id = cart.id
                discount.item_id = line.itemId
                discount.discount = discount_value
                discount.quantity = line.quantity
                
                discounts.append(discount)
        
        if has_qualified_model is False:
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
        
        cart.totalPrice = total_selling_price
        cart.discountedPrice = total_discounted_price
    
    return cart, discounts


def getDiscountOnItem(item):
    return None