| Line 69... |
Line 69... |
| 69 |
|
69 |
|
| 70 |
if coupon:
|
70 |
if coupon:
|
| 71 |
|
71 |
|
| 72 |
args = eval(coupon.arguments) if coupon.arguments is not None else {}
|
72 |
args = eval(coupon.arguments) if coupon.arguments is not None else {}
|
| 73 |
|
73 |
|
| - |
|
74 |
if 'percent' in args :
|
| - |
|
75 |
percentDiscount = args['percent']
|
| - |
|
76 |
else :
|
| - |
|
77 |
return {0 : 'Currently this coupon is unavailable'}
|
| - |
|
78 |
|
| 74 |
if 'minDiscountableVal' in args and total_amount < int(args['minDiscountableVal']):
|
79 |
if 'minDiscountableVal' in args and total_amount < int(args['minDiscountableVal']):
|
| 75 |
return {0:'This coupon is valid for recharges equal to or more than Rs.' + (args['minDiscountableVal'])}
|
80 |
return {0:'This coupon is valid for recharges equal to or more than Rs.' + (args['minDiscountableVal'])}
|
| 76 |
|
81 |
|
| 77 |
if 'couponType' in args and (args['couponType']) == 'RECHARGE':
|
82 |
if 'couponType' in args and (args['couponType']) == 'RECHARGE':
|
| 78 |
discount = round(total_amount * 0.1)
|
83 |
discount = round(total_amount * percentDiscount)
|
| 79 |
else :
|
84 |
else :
|
| 80 |
return {0:'Invalid Coupon'}
|
85 |
return {0:'Invalid Coupon'}
|
| 81 |
|
86 |
|
| 82 |
todate = datetime.datetime.now()
|
87 |
todate = datetime.datetime.now()
|
| 83 |
if 'endOn' in args and todate > to_py_date(args['endOn']) :
|
88 |
if 'endOn' in args and todate > to_py_date(args['endOn']) :
|
| Line 108... |
Line 113... |
| 108 |
starttime = datetime.time(startHour, startMinute, 0)
|
113 |
starttime = datetime.time(startHour, startMinute, 0)
|
| 109 |
endtime = datetime.time(endHour, endMinute, 0)
|
114 |
endtime = datetime.time(endHour, endMinute, 0)
|
| 110 |
if (curtime < starttime or curtime > endtime):
|
115 |
if (curtime < starttime or curtime > endtime):
|
| 111 |
return {0:'Currently this coupon is unavailable'}
|
116 |
return {0:'Currently this coupon is unavailable'}
|
| 112 |
|
117 |
|
| - |
|
118 |
if 'userLimit' in args :
|
| - |
|
119 |
userLimit = args['userLimit']
|
| - |
|
120 |
else :
|
| - |
|
121 |
return {0 : 'Currently this coupon is unavailable'}
|
| - |
|
122 |
|
| 113 |
count_coupon_usage_by_user = get_coupon_usage_count_by_user(coupon_code, user_id)
|
123 |
count_coupon_usage_by_user = get_coupon_usage_count_by_user(coupon_code, user_id)
|
| 114 |
if count_coupon_usage_by_user >=2:
|
124 |
if count_coupon_usage_by_user >= userLimit:
|
| 115 |
return {0:'This coupon is applicable only twice per user'}
|
125 |
return {0:'This coupon is applicable only ' + str(userLimit) + ' times per user'}
|
| - |
|
126 |
|
| - |
|
127 |
if 'globalLimit' in args :
|
| - |
|
128 |
globalLimit = args['globalLimit']
|
| - |
|
129 |
else :
|
| - |
|
130 |
return {0 : 'Currently this coupon is unavailable'}
|
| 116 |
|
131 |
|
| 117 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
132 |
count_coupon_usage = get_coupon_usage_count(coupon_code)
|
| 118 |
if count_coupon_usage >= 1000:
|
133 |
if count_coupon_usage >= globalLimit:
|
| 119 |
return {0:'This promotion is over.'}
|
134 |
return {0:'This promotion is over.'}
|
| 120 |
|
135 |
|
| 121 |
if 'maxDiscount' in args and discount > int(args['maxDiscount']):
|
136 |
if 'maxDiscount' in args and discount > int(args['maxDiscount']):
|
| 122 |
return {int(args['maxDiscount']):"Coupon Applied"}
|
137 |
return {int(args['maxDiscount']):"Coupon Applied"}
|
| 123 |
|
138 |
|