Subversion Repositories SmartDukaan

Rev

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

Rev 5044 Rev 5331
Line 3... Line 3...
3
 
3
 
4
@author: Varun Gupta
4
@author: Varun Gupta
5
'''
5
'''
6
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
6
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
-
 
8
from shop2020.clients.UserClient import UserClient
8
 
9
 
9
def execute(cart, coupon_code, args):
10
def execute(cart, coupon_code, args):
10
    if 'items' not in args or 'discount' not in args or 'handset_display_name' not in args:
11
    if 'items' not in args or 'discount' not in args or 'handset_display_name' not in args:
11
        raise PromotionException(109, 'Error in rule arguments.')
12
        raise PromotionException(109, 'Error in rule arguments.')
12
        
13
        
13
    if 'usage_limit' in args and args['usage_limit'] is not None:
14
    if 'usage_limit' in args and args['usage_limit'] is not None:
14
        if args['usage_limit'] <= get_coupon_usage_count(coupon_code):
15
        if args['usage_limit'] <= get_coupon_usage_count(coupon_code):
15
            raise PromotionException(112, 'This promotion is over.')
16
            raise PromotionException(112, 'This promotion is over.')
16
    
17
    
-
 
18
    user_client = UserClient().get_client()
-
 
19
    user = user_client.getUserByCartId(cart.id)
-
 
20
 
17
    if 'usage_limit_for_user' in args and args['usage_limit_for_user'] is not None:
21
    if 'usage_limit_for_user' in args and args['usage_limit_for_user'] is not None:
18
        if args['usage_limit_for_user'] <= get_coupon_usage_count_by_user(coupon_code, cart.userId):
22
        if args['usage_limit_for_user'] <= get_coupon_usage_count_by_user(coupon_code, user.id):
19
            raise PromotionException(111, 'You have already used this coupon maximum possible times.')
23
            raise PromotionException(111, 'You have already used this coupon maximum possible times.')
20
    
24
    
21
    if not cart.lines:
25
    if not cart.lines:
22
        return cart
26
        return cart
23
    
27