Subversion Repositories SmartDukaan

Rev

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

Rev 4475 Rev 4941
Line 1... Line 1...
1
'''
1
'''
2
Created on 06-Dec-2011
2
Created on 06-Dec-2011
3
 
3
 
4
@author: varungupta
4
@author: varungupta
5
 
-
 
6
raghvendra.saboo@gmail.com will get Rs.200 off on one transaction
-
 
7
michaelananth.ravichandran@tcs.com will get Rs.200 off on one transaction
-
 
8
nc41@indiatimes.com will get Rs.200 off on one transaction
-
 
9
'''
5
'''
10
 
6
 
11
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
7
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
12
from shop2020.clients.UserClient import UserClient
8
from shop2020.clients.UserClient import UserClient
13
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
9
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
14
from shop2020.thriftpy.model.v1.user.ttypes import Discount
-
 
15
 
10
 
16
def execute(cart, coupon_code, args):
11
def execute(cart, coupon_code, args):
17
    
12
    
18
    user_client = UserClient().get_client()
13
    user_client = UserClient().get_client()
19
    user = user_client.getUserById(cart.userId)
14
    user = user_client.getUserById(cart.userId)
20
    
15
    
21
    email = user.email.lower().strip()
16
    email = user.email.lower().strip()
22
    
17
    
23
    if email in ('raghvendra.saboo@gmail.com', 'michaelananth.ravichandran@tcs.com', 'nc41@indiatimes.com'):
18
    if email in args['emails']:
24
        discount_value = 200
19
        discount_value = args['discount']
25
    else:
20
    else:
26
        raise PromotionException(111, 'You are not allowed to use this coupon')
21
        raise PromotionException(111, 'You are not allowed to use this coupon')
27
    
22
    
28
    #Allow only first 1000 users to use the coupon
-
 
29
    count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
23
    count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
30
    
24
    
31
    if count_coupon_usage > 0:
25
    if count_coupon_usage >= args['usage_limit_for_user']:
32
        raise PromotionException(112, 'You have already used the coupon.')
26
        raise PromotionException(112, 'Your usage limit for this coupon is exhausted.')
33
    
27
    
34
    discounts = []
28
    discounts = []
35
    
29
    
36
    if cart.lines:
30
    if cart.lines:
37
        total_selling_price = 0
31
        total_selling_price = 0