Subversion Repositories SmartDukaan

Rev

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

Rev 3514 Rev 3559
Line 7... Line 7...
7
Curve 3G 9300    Rs.250 off
7
Curve 3G 9300    Rs.250 off
8
Torch 2 9810    Rs.600 off
8
Torch 2 9810    Rs.600 off
9
Playbook 16 GB    Rs.1390 off
9
Playbook 16 GB    Rs.1390 off
10
Playbook 32 GB    Rs.1690 off
10
Playbook 32 GB    Rs.1690 off
11
'''
11
'''
12
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
12
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
13
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count
13
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count
14
 
14
 
15
def execute(cart, coupon_code, args):
15
def execute(cart, coupon_code, args):
16
    
16
    
17
    #Allow only first 100 users to use the coupon
17
    #Allow only first 100 users to use the coupon
18
    count_coupon_usage = get_coupon_usage_count(coupon_code)
18
    count_coupon_usage = get_coupon_usage_count(coupon_code)
19
    
19
    
20
    if count_coupon_usage >= 100:
20
    if count_coupon_usage >= 100:
21
        raise PromotionException(112, 'This promotion is over.')
21
        raise PromotionException(112, 'This promotion is over.')
22
    
22
    
-
 
23
    discounts = []
-
 
24
    
23
    if cart.lines:
25
    if cart.lines:
24
        total_selling_price = 0
26
        total_selling_price = 0
25
        total_discounted_price = 0
27
        total_discounted_price = 0
26
        
28
        
27
        has_qualified_model = False
29
        has_qualified_model = False
28
        
30
        
29
        for line in cart.lines:
31
        for line in cart.lines:
30
            
32
            
31
            line.discountedPrice = line.actualPrice
33
            line.discountedPrice = line.actualPrice
-
 
34
            discount_value = 0
32
            
35
            
33
            if line.itemId in (5, 6, 7, 8, 9, 1499):  #Curve 8520
36
            if line.itemId in (5, 6, 7, 8, 9, 1499):  #Curve 8520
34
                
37
                
35
                has_qualified_model = True
38
                has_qualified_model = True
36
                
39
                
37
                if line.actualPrice:
40
                if line.actualPrice:
38
                    line.discountedPrice = round(line.actualPrice  - 250)
41
                    line.discountedPrice = round(line.actualPrice  - 250)
-
 
42
                    discount_value = 250
39
            
43
            
40
            elif line.itemId in (10, 1560, 1561):  #Curve 3G 9300
44
            elif line.itemId in (10, 1560, 1561):  #Curve 3G 9300
41
                
45
                
42
                has_qualified_model = True
46
                has_qualified_model = True
43
                
47
                
44
                if line.actualPrice:
48
                if line.actualPrice:
45
                    line.discountedPrice = line.actualPrice - 250
49
                    line.discountedPrice = line.actualPrice - 250
-
 
50
                    discount_value = 250
46
            
51
            
47
            elif line.itemId == 2016:  #Torch 2 9810
52
            elif line.itemId == 2016:  #Torch 2 9810
48
                
53
                
49
                has_qualified_model = True
54
                has_qualified_model = True
50
                
55
                
51
                if line.actualPrice:
56
                if line.actualPrice:
52
                    line.discountedPrice = line.actualPrice - 600
57
                    line.discountedPrice = line.actualPrice - 600
-
 
58
                    discount_value = 600
53
             
59
             
54
            elif line.itemId == 1543:  #Playbook 16 GB
60
            elif line.itemId == 1543:  #Playbook 16 GB
55
                
61
                
56
                has_qualified_model = True
62
                has_qualified_model = True
57
                
63
                
58
                if line.actualPrice:
64
                if line.actualPrice:
59
                    line.discountedPrice = line.actualPrice - 1390
65
                    line.discountedPrice = line.actualPrice - 1390
-
 
66
                    discount_value = 1390
60
            
67
            
61
            elif line.itemId == 1550:  #Playbook 32 GB
68
            elif line.itemId == 1550:  #Playbook 32 GB
62
                
69
                
63
                has_qualified_model = True
70
                has_qualified_model = True
64
                
71
                
65
                if line.actualPrice:
72
                if line.actualPrice:
66
                    line.discountedPrice = line.actualPrice - 1690
73
                    line.discountedPrice = line.actualPrice - 1690
-
 
74
                    discount_value = 1690
67
            
75
            
68
            total_selling_price += line.actualPrice * line.quantity
76
            total_selling_price += line.actualPrice * line.quantity
69
            total_discounted_price += line.discountedPrice * line.quantity
77
            total_discounted_price += line.discountedPrice * line.quantity
70
        
78
        
-
 
79
            if discount_value > 0:
-
 
80
                discount = Discount()
-
 
81
                discount.cart_id = cart.id
-
 
82
                discount.item_id = line.itemId
-
 
83
                discount.discount = discount_value
-
 
84
                discount.quantity = line.quantity
-
 
85
                
-
 
86
                discounts.append(discount)
-
 
87
        
71
        if has_qualified_model is False:
88
        if has_qualified_model is False:
72
            raise PromotionException(115, 'This coupon is applicable only for selective Blackberry handsets.')
89
            raise PromotionException(115, 'This coupon is applicable only for selective Blackberry handsets.')
73
        
90
        
74
        cart.totalPrice = total_selling_price
91
        cart.totalPrice = total_selling_price
75
        cart.discountedPrice = total_discounted_price
92
        cart.discountedPrice = total_discounted_price
76
    
93
    
77
    return cart
94
    return cart, discounts