Subversion Repositories SmartDukaan

Rev

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

Rev 6469 Rev 6470
Line 1... Line 1...
1
'''
1
'''
2
Created on 06-Jul-2011
2
Created on 06-Jul-2011
3
 
3
 
4
@author: Varun Gupta
4
@author: Varun Gupta
5
'''
5
'''
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
-
 
8
from shop2020.clients.UserClient import UserClient
6
from shop2020.clients.UserClient import UserClient
-
 
7
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import \
-
 
8
    get_coupon_usage_count, get_coupon_usage_count_by_user
-
 
9
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
-
 
10
import datetime
9
 
11
 
10
def execute(cart, coupon_code, args):
12
def execute(cart, coupon_code, args):
11
    if 'items' not in args or 'handset_display_name' not in args:
13
    if 'items' not in args or 'handset_display_name' not in args:
12
        raise PromotionException(109, 'Error in rule arguments.')
14
        raise PromotionException(109, 'Error in rule arguments.')
13
        
15
        
-
 
16
    if 'end_on' in args and datetime.datetime.strptime(args['end_on'], '%Y%m%d') <= datetime.datetime.now():
-
 
17
        raise PromotionException(112, 'This promotion is expired.')
-
 
18
         
14
    if 'usage_limit' in args and args['usage_limit'] is not None:
19
    if 'usage_limit' in args and args['usage_limit'] is not None:
15
        if args['usage_limit'] <= get_coupon_usage_count(coupon_code):
20
        if args['usage_limit'] <= get_coupon_usage_count(coupon_code):
16
            raise PromotionException(112, 'This promotion is over.')
21
            raise PromotionException(112, 'This promotion is over.')
17
    
22
    
18
    user_client = UserClient().get_client()
23
    user_client = UserClient().get_client()
Line 34... Line 39...
34
        isPercentageDiscount = args['is_percentage_discount']
39
        isPercentageDiscount = args['is_percentage_discount']
35
    for line in cart.lines:
40
    for line in cart.lines:
36
        total_selling_price += line.actualPrice * line.quantity
41
        total_selling_price += line.actualPrice * line.quantity
37
        discount_value = 0
42
        discount_value = 0
38
        
43
        
39
        if line.itemId in args['items'] or (len(args['items'])==0 and args['min_amount'] < line.actualPrice):
44
        if line.itemId in args['items'] or (len(args['items'])==0 and args['min_amount'] <= line.actualPrice):
40
            cart_has_specified_item = True
45
            cart_has_specified_item = True
41
            if(len(args['items'])==0):
46
            if(len(args['items'])==0):
42
                discount_value = args['discount']
47
                discount_value = args['discount']
43
            else: 
48
            else: 
44
                discount_value = args['items'][line.itemId]
49
                discount_value = args['items'][line.itemId]