Subversion Repositories SmartDukaan

Rev

Rev 5500 | Go to most recent revision | 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
Max Uses: 200
3417 varun.gupt 6
 
5499 varun.gupt 7
Samsung Galaxy Ace S5830i    Rs.401 off
8
Samsung Galaxy Ace Duos S6802    Rs.401 off
9
HTC One V T320e    Rs.512 off
10
HTC Desire C A320e    Rs.762 off
3249 varun.gupt 11
'''
12
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
5501 varun.gupt 13
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count
3554 varun.gupt 14
from shop2020.thriftpy.model.v1.user.ttypes import Discount
5331 rajveer 15
from shop2020.clients.UserClient import UserClient
3249 varun.gupt 16
 
17
def execute(cart, coupon_code, args):
5331 rajveer 18
    user_client = UserClient().get_client()
19
    user = user_client.getUserByCartId(cart.id)
3249 varun.gupt 20
 
4505 varun.gupt 21
    #Allow only first 2000 users to use the coupon
3249 varun.gupt 22
    count_coupon_usage = get_coupon_usage_count(coupon_code)
23
 
5499 varun.gupt 24
    if count_coupon_usage >= 200:
3249 varun.gupt 25
        raise PromotionException(112, 'This promotion is over.')
26
 
3554 varun.gupt 27
    discounts = []
28
 
3249 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
3554 varun.gupt 38
            discount_value = 0
3249 varun.gupt 39
 
5499 varun.gupt 40
            if line.itemId in (6829, 7243, 7298):  #Samsung Galaxy Ace Duos S6802 & Galaxy Ace S5830i
3249 varun.gupt 41
 
4799 varun.gupt 42
                has_qualified_model = True
43
 
44
                if line.actualPrice:
5499 varun.gupt 45
                    line.discountedPrice = round(line.actualPrice - 401)
46
                    discount_value = 401
4799 varun.gupt 47
 
5499 varun.gupt 48
            elif line.itemId == 4645:  #HTC One V T320e
4799 varun.gupt 49
 
5499 varun.gupt 50
                has_qualified_model = True
3454 varun.gupt 51
 
5499 varun.gupt 52
                if line.actualPrice:
53
                    line.discountedPrice = round(line.actualPrice - 512)
54
                    discount_value = 512
3249 varun.gupt 55
 
5499 varun.gupt 56
            elif line.itemId in (6747, 7127):  #HTC Desire C A320e
57
 
58
                has_qualified_model = True
59
 
60
                if line.actualPrice:
61
                    line.discountedPrice = round(line.actualPrice - 762)
62
                    discount_value = 762
63
 
3249 varun.gupt 64
            total_selling_price += line.actualPrice * line.quantity
5499 varun.gupt 65
            total_discounted_price += line.discountedPrice * line.quantity
3554 varun.gupt 66
 
67
            if discount_value > 0:
68
                discount = Discount()
69
                discount.cart_id = cart.id
70
                discount.item_id = line.itemId
71
                discount.discount = discount_value
5499 varun.gupt 72
                discount.quantity = line.quantity
3554 varun.gupt 73
 
74
                discounts.append(discount)
3249 varun.gupt 75
 
76
        if has_qualified_model is False:
3401 varun.gupt 77
            raise PromotionException(115, 'This coupon is applicable only for selective handsets.')
3249 varun.gupt 78
 
79
        cart.totalPrice = total_selling_price
80
        cart.discountedPrice = total_discounted_price
81
 
4189 varun.gupt 82
    return cart, discounts
83
 
4799 varun.gupt 84
 
4189 varun.gupt 85
def getDiscountOnItem(item):
86
    return None