Subversion Repositories SmartDukaan

Rev

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

Rev 4856 Rev 4859
Line 3... Line 3...
3
 
3
 
4
@author: Varun Gupta
4
@author: Varun Gupta
5
'''
5
'''
6
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
6
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
-
 
8
from shop2020.model.v1.user.impl.Dataservice import Discount
8
 
9
 
9
def execute(cart, coupon_code, args):
10
def execute(cart, coupon_code, args):
10
    if 'items' not in args or 'discount' not in args or 'handset_display_name' not in args:
11
    if 'items' not in args or 'discount' not in args or 'handset_display_name' not in args:
11
        raise PromotionException(109, 'Error in rule arguments.')
12
        raise PromotionException(109, 'Error in rule arguments.')
12
        
13
        
Line 23... Line 24...
23
        return cart
24
        return cart
24
    
25
    
25
    total_selling_price = 0
26
    total_selling_price = 0
26
    total_discounted_price = 0
27
    total_discounted_price = 0
27
    cart_has_specified_item = False
28
    cart_has_specified_item = False
-
 
29
    discounts = []
28
    
30
    
29
    for line in cart.lines:
31
    for line in cart.lines:
30
        total_selling_price += line.actualPrice * line.quantity
32
        total_selling_price += line.actualPrice * line.quantity
-
 
33
        discount_value = 0
31
        
34
        
32
        if line.itemId in args['items']:
35
        if line.itemId in args['items']:
33
            cart_has_specified_item = True
36
            cart_has_specified_item = True
34
            line.discountedPrice = round(line.actualPrice - args['discount'], 4)
37
            line.discountedPrice = round(line.actualPrice - args['discount'], 4)
35
            total_discounted_price += round(line.discountedPrice * line.quantity, 4)
38
            total_discounted_price += round(line.discountedPrice * line.quantity, 4)
-
 
39
            discount_value = args['discount']
36
        else:
40
        else:
37
            total_discounted_price += round(line.actualPrice * line.quantity, 4)
41
            total_discounted_price += round(line.actualPrice * line.quantity, 4)
-
 
42
        
-
 
43
        if discount_value > 0:
-
 
44
            discount = Discount()
-
 
45
            discount.discount = discount_value
-
 
46
            discount.quantity = line.quantity
-
 
47
            discount.cart_id = cart.id
-
 
48
            discount.item_id = line.itemId
-
 
49
            
-
 
50
            discounts.append(discount)
38
    
51
    
39
    if cart_has_specified_item is False:
52
    if cart_has_specified_item is False:
40
        raise PromotionException(115, 'This coupon is applicable only for ' + args['handset_display_name'])
53
        raise PromotionException(115, 'This coupon is applicable only for ' + args['handset_display_name'])
41
    
54
    
42
    cart.totalPrice = round(total_selling_price, 4)
55
    cart.totalPrice = round(total_selling_price, 4)
43
    cart.discountedPrice = total_discounted_price
56
    cart.discountedPrice = total_discounted_price
44
    return cart
-
 
45
57
    return cart, discount
-
 
58
46
59