Subversion Repositories SmartDukaan

Rev

Rev 5501 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3249 varun.gupt 1
'''
5499 varun.gupt 2
Created on 27-June-2012
3249 varun.gupt 3
@author: Varun Gupta
3384 varun.gupt 4
 
5499 varun.gupt 5
Samsung Galaxy Ace S5830i    Rs.401 off
6
Samsung Galaxy Ace Duos S6802    Rs.401 off
7
HTC One V T320e    Rs.512 off
8
HTC Desire C A320e    Rs.762 off
3249 varun.gupt 9
'''
10
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
3554 varun.gupt 11
from shop2020.thriftpy.model.v1.user.ttypes import Discount
3249 varun.gupt 12
 
13
def execute(cart, coupon_code, args):
3554 varun.gupt 14
    discounts = []
15
 
3249 varun.gupt 16
    if cart.lines:
17
        total_selling_price = 0
18
        total_discounted_price = 0
19
 
20
        has_qualified_model = False
21
 
22
        for line in cart.lines:
23
 
24
            line.discountedPrice = line.actualPrice
3554 varun.gupt 25
            discount_value = 0
3249 varun.gupt 26
 
5499 varun.gupt 27
            if line.itemId in (6829, 7243, 7298):  #Samsung Galaxy Ace Duos S6802 & Galaxy Ace S5830i
3249 varun.gupt 28
 
4799 varun.gupt 29
                has_qualified_model = True
30
 
31
                if line.actualPrice:
5499 varun.gupt 32
                    line.discountedPrice = round(line.actualPrice - 401)
33
                    discount_value = 401
4799 varun.gupt 34
 
5499 varun.gupt 35
            elif line.itemId == 4645:  #HTC One V T320e
4799 varun.gupt 36
 
5499 varun.gupt 37
                has_qualified_model = True
3454 varun.gupt 38
 
5499 varun.gupt 39
                if line.actualPrice:
40
                    line.discountedPrice = round(line.actualPrice - 512)
41
                    discount_value = 512
3249 varun.gupt 42
 
5499 varun.gupt 43
            elif line.itemId in (6747, 7127):  #HTC Desire C A320e
44
 
45
                has_qualified_model = True
46
 
47
                if line.actualPrice:
48
                    line.discountedPrice = round(line.actualPrice - 762)
49
                    discount_value = 762
50
 
3249 varun.gupt 51
            total_selling_price += line.actualPrice * line.quantity
5499 varun.gupt 52
            total_discounted_price += line.discountedPrice * line.quantity
3554 varun.gupt 53
 
54
            if discount_value > 0:
55
                discount = Discount()
56
                discount.cart_id = cart.id
57
                discount.item_id = line.itemId
58
                discount.discount = discount_value
5499 varun.gupt 59
                discount.quantity = line.quantity
3554 varun.gupt 60
 
61
                discounts.append(discount)
3249 varun.gupt 62
 
63
        if has_qualified_model is False:
3401 varun.gupt 64
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
3249 varun.gupt 65
 
66
        cart.totalPrice = total_selling_price
67
        cart.discountedPrice = total_discounted_price
68
 
4189 varun.gupt 69
    return cart, discounts
70
 
4799 varun.gupt 71
 
4189 varun.gupt 72
def getDiscountOnItem(item):
73
    return None