Subversion Repositories SmartDukaan

Rev

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

Rev 6009 Rev 6250
Line 2... Line 2...
2
Created on 06-Dec-2011
2
Created on 06-Dec-2011
3
 
3
 
4
@author: varungupta
4
@author: varungupta
5
'''
5
'''
6
 
6
 
7
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
-
 
8
from shop2020.clients.UserClient import UserClient
7
from shop2020.clients.UserClient import UserClient
9
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
8
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import \
-
 
9
    get_coupon_usage_count_by_user
-
 
10
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
-
 
11
from shop2020.utils.Utils import to_py_date
-
 
12
import datetime
10
 
13
 
11
def execute(cart, coupon_code, args):
14
def execute(cart, coupon_code, args):
12
    
15
    
13
    user_client = UserClient().get_client()
16
    user_client = UserClient().get_client()
14
    user = user_client.getUserByCartId(cart.id)
17
    user = user_client.getUserByCartId(cart.id)
Line 18... Line 21...
18
    if email in args['emails']:
21
    if email in args['emails']:
19
        discount_value = args['discount']
22
        discount_value = args['discount']
20
    else:
23
    else:
21
        raise PromotionException(111, 'You are not allowed to use this coupon')
24
        raise PromotionException(111, 'You are not allowed to use this coupon')
22
    
25
    
-
 
26
    todate = datetime.datetime.now()
-
 
27
    if args['endOn'] and todate > to_py_date(args['endOn']):
-
 
28
        raise PromotionException(113, 'This coupon is expired.')
-
 
29
    
23
    count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, user.userId)
30
    count_coupon_usage = get_coupon_usage_count_by_user(coupon_code, user.userId)
24
    
31
    
25
    if count_coupon_usage >= args['usage_limit_for_user']:
32
    if count_coupon_usage >= args['usage_limit_for_user']:
26
        raise PromotionException(112, 'Your usage limit for this coupon is exhausted.')
33
        raise PromotionException(112, 'Your usage limit for this coupon is exhausted.')
27
    
34