Subversion Repositories SmartDukaan

Rev

Rev 6538 | Rev 7781 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6538 Rev 6903
Line 46... Line 46...
46
        
46
        
47
    
47
    
48
    isPercentageDiscount = False
48
    isPercentageDiscount = False
49
    if 'is_percentage_discount' in args:
49
    if 'is_percentage_discount' in args:
50
        isPercentageDiscount = args['is_percentage_discount']
50
        isPercentageDiscount = args['is_percentage_discount']
51
    
-
 
52
 
51
 
53
    total_selling_price = 0
-
 
54
    total_discounted_price = 0
52
    total_discounts = 0
55
    cart_has_specified_item = False
53
    cart_has_specified_item = False
56
    discounts = []
54
    discounts = []
57
 
55
 
58
    for line in cart.lines:
56
    for line in cart.lines:
59
        total_selling_price += line.actualPrice * line.quantity
-
 
60
        discount_value = 0
57
        discount_value = 0
61
        
58
        
62
        if min_amount is not None and line.actualPrice < min_amount:
59
        if min_amount is not None and line.actualPrice < min_amount:
63
            total_discounted_price += round(line.actualPrice * line.quantity, 4)
-
 
64
            continue
60
            continue
65
 
61
 
66
        if 'items' in args:
62
        if 'items' in args:
67
            if line.itemId in args['items'] :
63
            if line.itemId in args['items'] :
68
                if type(args['items'])==dict: 
64
                if type(args['items'])==dict: 
Line 70... Line 66...
70
                    cart_has_specified_item = True
66
                    cart_has_specified_item = True
71
                elif discountJ is not None:
67
                elif discountJ is not None:
72
                    discount_value = discountJ
68
                    discount_value = discountJ
73
                    cart_has_specified_item = True
69
                    cart_has_specified_item = True
74
            else:
70
            else:
75
                total_discounted_price += round(line.actualPrice * line.quantity, 4)
-
 
76
                continue
71
                continue
77
        elif 'categories' in args:
72
        elif 'categories' in args:
78
            catalog_client = CatalogClient().get_client()
73
            catalog_client = CatalogClient().get_client()
79
            category = catalog_client.getItem(line.itemId).category
74
            category = catalog_client.getItem(line.itemId).category
80
            if category in args['categories']:
75
            if category in args['categories']:
Line 83... Line 78...
83
                    cart_has_specified_item = True
78
                    cart_has_specified_item = True
84
                elif discountJ is not None:
79
                elif discountJ is not None:
85
                    discount_value = discountJ 
80
                    discount_value = discountJ 
86
                    cart_has_specified_item = True
81
                    cart_has_specified_item = True
87
            else:
82
            else:
88
                total_discounted_price += round(line.actualPrice * line.quantity, 4)
-
 
89
                continue
83
                continue
90
        elif discountJ is not None:
84
        elif discountJ is not None:
91
            discount_value = discountJ 
85
            discount_value = discountJ 
92
            cart_has_specified_item = True
86
            cart_has_specified_item = True
93
        else :
87
        else :
94
            total_discounted_price += round(line.actualPrice * line.quantity, 4) 
-
 
95
            continue
88
            continue
96
    
89
    
97
        if isPercentageDiscount:
90
        if isPercentageDiscount:
98
            discount_value = round((line.actualPrice*discount_value)/100, 4)
91
            discount_value = round((line.actualPrice*discount_value)/100, 4)
99
        if max_discount is not None:
92
        if max_discount is not None:
100
            discount_value = min(max_discount, discount_value)
93
            discount_value = min(max_discount, discount_value)
101
            
94
            
102
        line.discountedPrice = round(line.actualPrice - discount_value, 4)
95
        line.discountedPrice = round(line.actualPrice - discount_value, 4)
103
        total_discounted_price += round(line.discountedPrice * line.quantity, 4)
96
        total_discounts += round(discount_value * line.quantity, 4)
104
        if discount_value > 0:
97
        if discount_value > 0:
105
            discount = Discount()
98
            discount = Discount()
106
            discount.discount = discount_value
99
            discount.discount = discount_value
107
            discount.quantity = line.quantity
100
            discount.quantity = line.quantity
108
            discount.cart_id = cart.id
101
            discount.cart_id = cart.id
Line 111... Line 104...
111
            discounts.append(discount)
104
            discounts.append(discount)
112
    
105
    
113
    if cart_has_specified_item is False:
106
    if cart_has_specified_item is False:
114
        raise PromotionException(115, 'This coupon is applicable only for ' + args['handset_display_name'])
107
        raise PromotionException(115, 'This coupon is applicable only for ' + args['handset_display_name'])
115
    
108
    
116
    cart.totalPrice = round(total_selling_price, 4)
-
 
117
    cart.discountedPrice = total_discounted_price
109
    cart.discountedPrice = cart.totalPrice - total_discounts
118
    return cart, discounts
110
    return cart, discounts
119
 
111
 
120
def getDiscountOnItem(item):
112
def getDiscountOnItem(item):
121
    return None
113
    return None
122
114