Subversion Repositories SmartDukaan

Rev

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

Rev 6688 Rev 6730
Line 42... Line 42...
42
    coupon.promotion = promotion
42
    coupon.promotion = promotion
43
    coupon.coupon_code = coupon_code
43
    coupon.coupon_code = coupon_code
44
    coupon.arguments = ""
44
    coupon.arguments = ""
45
    session.commit()
45
    session.commit()
46
 
46
 
47
def create_coupon(promotionId, arguments, isCod, prefix=None):
47
def create_coupon(promotionId, couponCode, arguments, isCod, prefix=None):
48
    if promotionId not in (26,27,28):
48
    if promotionId not in (26,27,28):
49
        raise PromotionException(101, 'Only promotion ids 26 and 27 are expected')
49
        raise PromotionException(101, 'Only promotion ids 26 and 27 are expected')
50
    promotion = Promotion.get_by(id = promotionId)
50
    promotion = Promotion.get_by(id = promotionId)
51
    if promotion:     
51
    if promotion:
-
 
52
        if couponCode == '':
52
        coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
53
            coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
-
 
54
        else:
-
 
55
            coupon_code = couponCode
53
        coupon = Coupon.get_by(coupon_code = coupon_code)
56
        coupon = Coupon.get_by(coupon_code = coupon_code)
54
        while coupon is not None:
57
        while coupon is not None:
55
            coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
58
            coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
56
            coupon = Coupon.get_by(coupon_code = coupon_code)
59
            coupon = Coupon.get_by(coupon_code = coupon_code)
57
        coupon = Coupon()
60
        coupon = Coupon()
Line 80... Line 83...
80
            return {0:'This coupon is valid for purchases equal to or more than Rs.' + (args['minDiscountableVal'])}
83
            return {0:'This coupon is valid for purchases equal to or more than Rs.' + (args['minDiscountableVal'])}
81
    
84
    
82
        if 'couponType' not in args or args['couponType'] not in ('recharge','both'):
85
        if 'couponType' not in args or args['couponType'] not in ('recharge','both'):
83
            return {0:'Invalid Coupon'}
86
            return {0:'Invalid Coupon'}
84
        
87
        
-
 
88
        isUserSpecific = False
-
 
89
        
85
        if args['emails'] != '*':
90
        if args['emails'] != '*':
86
            user_client = UserClient().get_client()
91
            user_client = UserClient().get_client()
87
            user = user_client.getUserById(user_id)
92
            user = user_client.getUserById(user_id)
-
 
93
            isUserSpecific = True
88
            if user.email not in args['emails']:
94
            if user.email not in args['emails']:
89
                return {0:'Invalid coupon'}
95
                return {0:'Invalid coupon'}
90
            
96
            
91
        if 'startHour' in args and 'startMinute' in args and 'endHour' in args and 'endMinute' in args :
97
        if 'startHour' in args and 'startMinute' in args and 'endHour' in args and 'endMinute' in args :
92
            startHour = int(args['startHour'])
98
            startHour = int(args['startHour'])
Line 128... Line 134...
128
            return {0 : 'Invalid coupon'}
134
            return {0 : 'Invalid coupon'}
129
        
135
        
130
        if 'maxDiscount' in args and discount > int(args['maxDiscount']):
136
        if 'maxDiscount' in args and discount > int(args['maxDiscount']):
131
            return {int(args['maxDiscount']):"Coupon Applied"}
137
            return {int(args['maxDiscount']):"Coupon Applied"}
132
        
138
        
-
 
139
        if isUserSpecific :
-
 
140
            return {discount:'login'}
-
 
141
        
133
        return {discount:'Coupon Applied'}
142
        return {discount:'Coupon Applied'}
134
    else:
143
    else:
135
        return {0:'Invalid Coupon'}
144
        return {0:'Invalid Coupon'}
136
 
145
 
137
def apply_coupon(coupon_code, cart_id):
146
def apply_coupon(coupon_code, cart_id):