Subversion Repositories SmartDukaan

Rev

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
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
'''
3559 varun.gupt 12
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
3299 varun.gupt 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
 
3559 varun.gupt 23
    discounts = []
24
 
3299 varun.gupt 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
3559 varun.gupt 34
            discount_value = 0
3299 varun.gupt 35
 
3301 varun.gupt 36
            if line.itemId in (5, 6, 7, 8, 9, 1499):  #Curve 8520
3299 varun.gupt 37
 
38
                has_qualified_model = True
39
 
40
                if line.actualPrice:
41
                    line.discountedPrice = round(line.actualPrice  - 250)
3559 varun.gupt 42
                    discount_value = 250
3299 varun.gupt 43
 
44
            elif line.itemId in (10, 1560, 1561):  #Curve 3G 9300
45
 
46
                has_qualified_model = True
47
 
48
                if line.actualPrice:
49
                    line.discountedPrice = line.actualPrice - 250
3559 varun.gupt 50
                    discount_value = 250
3299 varun.gupt 51
 
52
            elif line.itemId == 2016:  #Torch 2 9810
53
 
54
                has_qualified_model = True
55
 
56
                if line.actualPrice:
57
                    line.discountedPrice = line.actualPrice - 600
3559 varun.gupt 58
                    discount_value = 600
3514 varun.gupt 59
 
3299 varun.gupt 60
            elif line.itemId == 1543:  #Playbook 16 GB
61
 
62
                has_qualified_model = True
63
 
64
                if line.actualPrice:
65
                    line.discountedPrice = line.actualPrice - 1390
3559 varun.gupt 66
                    discount_value = 1390
3299 varun.gupt 67
 
68
            elif line.itemId == 1550:  #Playbook 32 GB
69
 
70
                has_qualified_model = True
71
 
72
                if line.actualPrice:
73
                    line.discountedPrice = line.actualPrice - 1690
3559 varun.gupt 74
                    discount_value = 1690
3299 varun.gupt 75
 
76
            total_selling_price += line.actualPrice * line.quantity
77
            total_discounted_price += line.discountedPrice * line.quantity
78
 
3559 varun.gupt 79
            if discount_value > 0:
80
                discount = Discount()
81
                discount.cart_id = cart.id
82
                discount.item_id = line.itemId
83
                discount.discount = discount_value
84
                discount.quantity = line.quantity
85
 
86
                discounts.append(discount)
87
 
3299 varun.gupt 88
        if has_qualified_model is False:
3401 varun.gupt 89
            raise PromotionException(115, 'This coupon is applicable only for selective Blackberry handsets.')
3299 varun.gupt 90
 
91
        cart.totalPrice = total_selling_price
92
        cart.discountedPrice = total_discounted_price
93
 
3559 varun.gupt 94
    return cart, discounts