Subversion Repositories SmartDukaan

Rev

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

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