Subversion Repositories SmartDukaan

Rev

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

Rev 8707 Rev 11741
Line 1... Line 1...
1
'''
1
'''
2
Created on: May 24, 2011
2
Created on: May 24, 2011
3
@author: Varun Gupta
3
@author: Varun Gupta
4
'''
4
'''
5
 
5
 
-
 
6
from shop2020.clients import CatalogClient
6
from shop2020.model.v1.user.impl import PromotionDataAccessors
7
from shop2020.model.v1.user.impl import PromotionDataAccessors
7
from shop2020.model.v1.user.impl.Converters import to_t_coupon, \
8
from shop2020.model.v1.user.impl.Converters import to_t_coupon, \
8
    to_t_item_coupon_discount, to_t_voucher, to_t_promotion
9
    to_t_item_coupon_discount, to_t_voucher, to_t_promotion
9
from shop2020.model.v1.user.impl.PromotionDataAccessors import initialize, \
10
from shop2020.model.v1.user.impl.PromotionDataAccessors import initialize, \
10
    create_promotion, generate_coupons_for_promotion, apply_coupon, \
11
    create_promotion, generate_coupons_for_promotion, apply_coupon, \
Line 60... Line 61...
60
            isGiftVoucher = promotion_type == 1
61
            isGiftVoucher = promotion_type == 1
61
        finally:
62
        finally:
62
            PromotionDataAccessors.close_session()
63
            PromotionDataAccessors.close_session()
63
            return isGiftVoucher
64
            return isGiftVoucher
64
    
65
    
65
    def isCodApplicable(self, coupon_code):
66
    def isCodApplicable(self, cart):
66
        isCod = True
67
        isCod = True
-
 
68
        coupon_code = cart.coupon_code
67
        try:
69
        try:
68
            coupon = get_coupon(coupon_code)
70
            coupon = get_coupon(coupon_code)
69
            if coupon.arguments:
71
            if coupon.arguments:
70
                args = eval(coupon.arguments)
72
                args = eval(coupon.arguments)
71
                if 'isCod' in args:
73
                if 'isCod' in args:
72
                    isCod = args['isCod']
74
                    isCod = args['isCod']
-
 
75
            else:
-
 
76
                #We have private deal coupon
-
 
77
                if cart.lines is not None:
-
 
78
                    itemIds = []
-
 
79
                    [itemIds.append(line.itemId) for line in cart.lines]
-
 
80
                    catalog_client = CatalogClient().get_client()
-
 
81
                    privateDeals= catalog_client.getAllActivePrivateDeals(itemIds,0)
-
 
82
                    for privateDeal in privateDeals.values():
-
 
83
                        if not privateDeal.isCod:
-
 
84
                            return False
73
        finally:
85
        finally:
74
            PromotionDataAccessors.close_session()
86
            PromotionDataAccessors.close_session()
75
            return isCod
87
            return isCod
76
    
88
    
77
    def getPromotionById(self, promotionId):
89
    def getPromotionById(self, promotionId):