Subversion Repositories SmartDukaan

Rev

Rev 3559 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3535 varun.gupt 1
'''
2
Created on 01-Oct-2011
3
 
4
@author: Varun Gupta
5
 
6
Max uses: 100
7
 
8
BB Playbook 16GB     1090 off
9
BB Playbook 64GB     1690 off
10
HTC P510e Flyer     500 off
11
Motorola Xoom WiFi 3G     1700 off
12
Samsung P7500 Galaxy Tab     2501 off
13
Spice Mi-720 Tab     1000 off
14
'''
15
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
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
18
 
19
def execute(cart, coupon_code, args):
20
 
21
    #Allow only first 100 users to use the coupon
22
    count_coupon_usage = get_coupon_usage_count(coupon_code)
23
 
24
    if count_coupon_usage >= 100:
25
        raise PromotionException(112, 'This promotion is over.')
26
 
27
    if cart.lines:
28
        total_selling_price = 0
29
        total_discounted_price = 0
30
 
31
        has_qualified_model = False
32
 
33
        for line in cart.lines:
34
 
35
            line.discountedPrice = line.actualPrice
36
 
37
            if line.itemId == 1543:  #Playbook 16GB
38
 
39
                has_qualified_model = True
40
 
41
                if line.actualPrice:
42
                    line.discountedPrice = line.actualPrice - 1090
43
 
44
            elif line.itemId == 1550:   #Playbook 64GB
45
 
46
                has_qualified_model = True
47
 
48
                if line.actualPrice:
49
                    line.discountedPrice = line.actualPrice - 1690
50
 
51
            elif line.itemId == 1551:   #HTC Flyer P510e
52
 
53
                has_qualified_model = True
54
 
55
                if line.actualPrice:
56
                    line.discountedPrice = line.actualPrice - 500
57
 
58
            elif line.itemId == 1552:   #Motorola Xoom WiFi 3G
59
 
60
                has_qualified_model = True
61
 
62
                if line.actualPrice:
63
                    line.discountedPrice = line.actualPrice - 1700
64
 
65
            elif line.itemId == 2005:   #Samsung P7500 Galaxy Tab
66
 
67
                has_qualified_model = True
68
 
69
                if line.actualPrice:
70
                    line.discountedPrice = line.actualPrice - 2501
71
 
72
            elif line.itemId == 2022:   #Spice Mi-720 Tab
73
 
74
                has_qualified_model = True
75
 
76
                if line.actualPrice:
77
                    line.discountedPrice = line.actualPrice - 1000
78
 
79
            total_selling_price += line.actualPrice * line.quantity
80
            total_discounted_price += line.discountedPrice + (line.actualPrice * (line.quantity - 1))
81
 
82
        if has_qualified_model is False:
83
            raise PromotionException(115, 'This coupon is applicable only for selective tablets.')
84
 
85
        cart.totalPrice = total_selling_price
86
        cart.discountedPrice = total_discounted_price
87
 
88
    return cart