Subversion Repositories SmartDukaan

Rev

Rev 6083 | Rev 6087 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6081 amit.gupta 1
'''
2
Created on 06-Jul-2011
3
 
4
@author: Varun Gupta
5
'''
6
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
6085 rajveer 7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count
6081 amit.gupta 8
 
6083 amit.gupta 9
itemTuple = (7558)
6081 amit.gupta 10
def execute(cart, coupon_code, args):
11
 
12
    if 2 <= get_coupon_usage_count(coupon_code):
13
        raise PromotionException(112, 'This promotion is over.')
14
 
15
    if not cart.lines:
16
        return cart
17
 
18
    total_selling_price = 0
19
    total_discounted_price = 0
20
    cart_has_specified_item = False
21
    discount = 2000
22
    discounts = []
23
    for line in cart.lines:
24
        total_selling_price += line.actualPrice * line.quantity
25
        discount_value = 0
26
 
27
        if line.itemId == itemTuple:
28
            cart_has_specified_item = True
29
            line.discountedPrice = round(line.actualPrice - discount, 4)
30
            total_discounted_price += round(line.discountedPrice * line.quantity, 4)
31
            discount_value = discount
32
        else:
33
            total_discounted_price += round(line.actualPrice * line.quantity, 4)
34
 
35
        if discount_value > 0:
36
            discount = Discount()
37
            discount.discount = discount_value
38
            discount.quantity = line.quantity
39
            discount.cart_id = cart.id
40
            discount.item_id = line.itemId
41
 
42
            discounts.append(discount)
43
 
44
    if cart_has_specified_item is False:
45
        raise PromotionException(115, 'This coupon is applicable only for Samsung Note II N7100 16GB')
46
 
47
    cart.totalPrice = round(total_selling_price, 4)
48
    cart.discountedPrice = total_discounted_price
49
    return cart, discounts
50
 
51
def getDiscountOnItem(item):
52
    if item.id in itemTuple:
53
        return None 
54
    return None