Subversion Repositories SmartDukaan

Rev

Rev 5132 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5132 Rev 5331
Line 13... Line 13...
13
from shop2020.clients.UserClient import UserClient
13
from shop2020.clients.UserClient import UserClient
14
from shop2020.utils.Utils import to_py_date
14
from shop2020.utils.Utils import to_py_date
15
import datetime
15
import datetime
16
 
16
 
17
def execute(cart, coupon_code, args):
17
def execute(cart, coupon_code, args):
18
    
18
    user_client = UserClient().get_client()
-
 
19
    user = user_client.getUserByCartId(cart.id)
19
    #Allow a user to use the coupon only 1 time
20
    #Allow a user to use the coupon only 1 time
20
    count_users_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
21
    count_users_usage = get_coupon_usage_count_by_user(coupon_code, user.id)
21
    
22
    
22
    if count_users_usage > 0:
23
    if count_users_usage > 0:
23
        raise PromotionException(111, 'This promotion is over.')
24
        raise PromotionException(111, 'This promotion is over.')
24
    
25
    
25
    discounts = []
26
    discounts = []
26
    
27
    
27
    if cart.lines:
28
    if cart.lines:
28
        user_client = UserClient().get_client()
-
 
29
        
-
 
30
        user_state = user_client.getUserState(cart.userId)
-
 
31
        active_since = to_py_date(user_state.activeSince)
29
        active_since = to_py_date(user.activeSince)
32
        
30
        
33
        if datetime.date(2012, 5, 7) < datetime.date(active_since.year, active_since.month, active_since.day):
31
        if datetime.date(2012, 5, 7) < datetime.date(active_since.year, active_since.month, active_since.day):
34
            raise PromotionException(111, 'You are not eligible for this discount')
32
            raise PromotionException(111, 'You are not eligible for this discount')
35
        
33
        
36
        catalog_client = CatalogClient().get_client()
34
        catalog_client = CatalogClient().get_client()