Subversion Repositories SmartDukaan

Rev

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

Rev 3535 Rev 3559
Line 10... Line 10...
10
HTC P510e Flyer     500 off
10
HTC P510e Flyer     500 off
11
Motorola Xoom WiFi 3G     1700 off
11
Motorola Xoom WiFi 3G     1700 off
12
Samsung P7500 Galaxy Tab     2501 off
12
Samsung P7500 Galaxy Tab     2501 off
13
Spice Mi-720 Tab     1000 off
13
Spice Mi-720 Tab     1000 off
14
'''
14
'''
15
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
15
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
16
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
16
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
17
from shop2020.clients.CatalogClient import CatalogClient
17
from shop2020.clients.CatalogClient import CatalogClient
18
 
18
 
19
def execute(cart, coupon_code, args):
19
def execute(cart, coupon_code, args):
20
    
20
    
Line 22... Line 22...
22
    count_coupon_usage = get_coupon_usage_count(coupon_code)
22
    count_coupon_usage = get_coupon_usage_count(coupon_code)
23
    
23
    
24
    if count_coupon_usage >= 100:
24
    if count_coupon_usage >= 100:
25
        raise PromotionException(112, 'This promotion is over.')
25
        raise PromotionException(112, 'This promotion is over.')
26
    
26
    
-
 
27
    discounts = []
-
 
28
    
27
    if cart.lines:
29
    if cart.lines:
28
        total_selling_price = 0
30
        total_selling_price = 0
29
        total_discounted_price = 0
31
        total_discounted_price = 0
30
        
32
        
31
        has_qualified_model = False
33
        has_qualified_model = False
32
        
34
        
33
        for line in cart.lines:
35
        for line in cart.lines:
34
            
36
            
35
            line.discountedPrice = line.actualPrice
37
            line.discountedPrice = line.actualPrice
-
 
38
            discount_value = 0
36
            
39
            
37
            if line.itemId == 1543:  #Playbook 16GB
40
            if line.itemId == 1543:  #Playbook 16GB
38
                
41
                
39
                has_qualified_model = True
42
                has_qualified_model = True
40
                
43
                
41
                if line.actualPrice:
44
                if line.actualPrice:
42
                    line.discountedPrice = line.actualPrice - 1090
45
                    line.discountedPrice = line.actualPrice - 1090
-
 
46
                    discount_value = 1090
43
            
47
            
44
            elif line.itemId == 1550:   #Playbook 64GB
48
            elif line.itemId == 1550:   #Playbook 64GB
45
                
49
                
46
                has_qualified_model = True
50
                has_qualified_model = True
47
                
51
                
48
                if line.actualPrice:
52
                if line.actualPrice:
49
                    line.discountedPrice = line.actualPrice - 1690
53
                    line.discountedPrice = line.actualPrice - 1690
-
 
54
                    discount_value = 1690
50
            
55
            
51
            elif line.itemId == 1551:   #HTC Flyer P510e
56
            elif line.itemId == 1551:   #HTC Flyer P510e
52
                
57
                
53
                has_qualified_model = True
58
                has_qualified_model = True
54
                
59
                
55
                if line.actualPrice:
60
                if line.actualPrice:
56
                    line.discountedPrice = line.actualPrice - 500
61
                    line.discountedPrice = line.actualPrice - 500
-
 
62
                    discount_value = 500
57
            
63
            
58
            elif line.itemId == 1552:   #Motorola Xoom WiFi 3G
64
            elif line.itemId == 1552:   #Motorola Xoom WiFi 3G
59
                
65
                
60
                has_qualified_model = True
66
                has_qualified_model = True
61
                
67
                
62
                if line.actualPrice:
68
                if line.actualPrice:
63
                    line.discountedPrice = line.actualPrice - 1700
69
                    line.discountedPrice = line.actualPrice - 1700
-
 
70
                    discount_value = 1700
64
            
71
            
65
            elif line.itemId == 2005:   #Samsung P7500 Galaxy Tab
72
            elif line.itemId == 2005:   #Samsung P7500 Galaxy Tab
66
                
73
                
67
                has_qualified_model = True
74
                has_qualified_model = True
68
                
75
                
69
                if line.actualPrice:
76
                if line.actualPrice:
70
                    line.discountedPrice = line.actualPrice - 2501
77
                    line.discountedPrice = line.actualPrice - 2501
-
 
78
                    discount_value = 2501
71
            
79
            
72
            elif line.itemId == 2022:   #Spice Mi-720 Tab
80
            elif line.itemId == 2022:   #Spice Mi-720 Tab
73
                
81
                
74
                has_qualified_model = True
82
                has_qualified_model = True
75
                
83
                
76
                if line.actualPrice:
84
                if line.actualPrice:
77
                    line.discountedPrice = line.actualPrice - 1000
85
                    line.discountedPrice = line.actualPrice - 1000
-
 
86
                    discount_value = 1000
78
            
87
            
79
            total_selling_price += line.actualPrice * line.quantity
88
            total_selling_price += line.actualPrice * line.quantity
80
            total_discounted_price += line.discountedPrice + (line.actualPrice * (line.quantity - 1))
89
            total_discounted_price += line.discountedPrice * line.quantity
-
 
90
        
-
 
91
            if discount_value > 0:
-
 
92
                discount = Discount()
-
 
93
                discount.cart_id = cart.id
-
 
94
                discount.item_id = line.itemId
-
 
95
                discount.discount = discount_value
-
 
96
                discount.quantity = line.quantity
-
 
97
                
-
 
98
                discounts.append(discount)
81
        
99
        
82
        if has_qualified_model is False:
100
        if has_qualified_model is False:
83
            raise PromotionException(115, 'This coupon is applicable only for selective tablets.')
101
            raise PromotionException(115, 'This coupon is applicable only for selective tablets.')
84
        
102
        
85
        cart.totalPrice = total_selling_price
103
        cart.totalPrice = total_selling_price
86
        cart.discountedPrice = total_discounted_price
104
        cart.discountedPrice = total_discounted_price
87
    
105
    
88
    return cart
-
 
89
106
    return cart, discounts
-
 
107
90
108