Subversion Repositories SmartDukaan

Rev

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