Subversion Repositories SmartDukaan

Rev

Rev 4187 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4187 Rev 4291
Line 7... Line 7...
7
'''
7
'''
8
Created on 24-Oct-2011
8
Created on 24-Oct-2011
9
 
9
 
10
@author: Varun Gupta
10
@author: Varun Gupta
11
 
11
 
12
raghvendra.saboo@gmail.com will get Rs.250 off on one transaction.
12
raghvendra.saboo@gmail.com will get Rs.200 off on one transaction.
-
 
13
nishantgandhi@yahoo.com will get Rs.500 off on one transaction.
13
'''
14
'''
14
 
15
 
15
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
16
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
16
from shop2020.clients.UserClient import UserClient
17
from shop2020.clients.UserClient import UserClient
17
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
18
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
Line 20... Line 21...
20
def execute(cart, coupon_code, args):
21
def execute(cart, coupon_code, args):
21
    
22
    
22
    user_client = UserClient().get_client()
23
    user_client = UserClient().get_client()
23
    user = user_client.getUserById(cart.userId)
24
    user = user_client.getUserById(cart.userId)
24
    
25
    
-
 
26
    email = user.email.lower().strip()
-
 
27
    
25
    if not user.email.lower().strip() in ('raghvendra.saboo@gmail.com'):
28
    if email == 'raghvendra.saboo@gmail.com':
-
 
29
        discount_value = 200
-
 
30
    elif email == 'nishantgandhi@yahoo.com':
-
 
31
        discount_value = 500
-
 
32
    else:
26
        raise PromotionException(111, 'You are not allowed to use this coupon')
33
        raise PromotionException(111, 'You are not allowed to use this coupon')
27
    
34
    
28
    #Allow only first 1000 users to use the coupon
35
    #Allow only first 1000 users to use the coupon
29
    count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
36
    count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
30
    
37
    
Line 38... Line 45...
38
        total_discounted_price = 0
45
        total_discounted_price = 0
39
        has_used_coupon = False
46
        has_used_coupon = False
40
        
47
        
41
        for line in cart.lines:
48
        for line in cart.lines:
42
            line.discountedPrice = line.actualPrice
49
            line.discountedPrice = line.actualPrice
43
            discount_value = 0
-
 
44
            
50
            
45
            if has_used_coupon:
51
            if has_used_coupon:
46
                break
52
                break
47
            
53
            
48
            if line.actualPrice < 5000:
-
 
49
                line.discountedPrice = line.actualPrice - 200
54
            line.discountedPrice = line.actualPrice - discount_value
50
                discount_value = 200
-
 
51
            else:
-
 
52
                line.discountedPrice = line.actualPrice - 500
-
 
53
                discount_value = 500
-
 
54
            
55
            
55
            has_used_coupon = True
56
            has_used_coupon = True
56
            
57
            
57
            total_selling_price += line.actualPrice * line.quantity
58
            total_selling_price += line.actualPrice * line.quantity
58
            total_discounted_price += line.discountedPrice * line.quantity
59
            total_discounted_price += line.discountedPrice * line.quantity