Subversion Repositories SmartDukaan

Rev

Rev 3535 | Rev 3713 | Go to most recent revision | Details | Compare with Previous | 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
'''
3559 varun.gupt 15
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
3535 varun.gupt 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
 
3559 varun.gupt 27
    discounts = []
28
 
3535 varun.gupt 29
    if cart.lines:
30
        total_selling_price = 0
31
        total_discounted_price = 0
32
 
33
        has_qualified_model = False
34
 
35
        for line in cart.lines:
36
 
37
            line.discountedPrice = line.actualPrice
3559 varun.gupt 38
            discount_value = 0
3535 varun.gupt 39
 
40
            if line.itemId == 1543:  #Playbook 16GB
41
 
42
                has_qualified_model = True
43
 
44
                if line.actualPrice:
45
                    line.discountedPrice = line.actualPrice - 1090
3559 varun.gupt 46
                    discount_value = 1090
3535 varun.gupt 47
 
48
            elif line.itemId == 1550:   #Playbook 64GB
49
 
50
                has_qualified_model = True
51
 
52
                if line.actualPrice:
53
                    line.discountedPrice = line.actualPrice - 1690
3559 varun.gupt 54
                    discount_value = 1690
3535 varun.gupt 55
 
56
            elif line.itemId == 1551:   #HTC Flyer P510e
57
 
58
                has_qualified_model = True
59
 
60
                if line.actualPrice:
61
                    line.discountedPrice = line.actualPrice - 500
3559 varun.gupt 62
                    discount_value = 500
3535 varun.gupt 63
 
64
            elif line.itemId == 1552:   #Motorola Xoom WiFi 3G
65
 
66
                has_qualified_model = True
67
 
68
                if line.actualPrice:
69
                    line.discountedPrice = line.actualPrice - 1700
3559 varun.gupt 70
                    discount_value = 1700
3535 varun.gupt 71
 
72
            elif line.itemId == 2005:   #Samsung P7500 Galaxy Tab
73
 
74
                has_qualified_model = True
75
 
76
                if line.actualPrice:
77
                    line.discountedPrice = line.actualPrice - 2501
3559 varun.gupt 78
                    discount_value = 2501
3535 varun.gupt 79
 
80
            elif line.itemId == 2022:   #Spice Mi-720 Tab
81
 
82
                has_qualified_model = True
83
 
84
                if line.actualPrice:
85
                    line.discountedPrice = line.actualPrice - 1000
3559 varun.gupt 86
                    discount_value = 1000
3535 varun.gupt 87
 
88
            total_selling_price += line.actualPrice * line.quantity
3559 varun.gupt 89
            total_discounted_price += line.discountedPrice * line.quantity
3535 varun.gupt 90
 
3559 varun.gupt 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)
99
 
3535 varun.gupt 100
        if has_qualified_model is False:
101
            raise PromotionException(115, 'This coupon is applicable only for selective tablets.')
102
 
103
        cart.totalPrice = total_selling_price
104
        cart.discountedPrice = total_discounted_price
105
 
3559 varun.gupt 106
    return cart, discounts