| Line 17... |
Line 17... |
| 17 |
import datetime
|
17 |
import datetime
|
| 18 |
import traceback
|
18 |
import traceback
|
| 19 |
import uuid
|
19 |
import uuid
|
| 20 |
from shop2020.model.v1.user.impl.Converters import to_t_coupon
|
20 |
from shop2020.model.v1.user.impl.Converters import to_t_coupon
|
| 21 |
from shop2020.model.v1.user.promotionrules import rule_specific_emi_discount_on_specific_items
|
21 |
from shop2020.model.v1.user.promotionrules import rule_specific_emi_discount_on_specific_items
|
| - |
|
22 |
import ast
|
| 22 |
|
23 |
|
| 23 |
|
24 |
|
| 24 |
def initialize(dbname = 'user', db_hostname="localhost"):
|
25 |
def initialize(dbname = 'user', db_hostname="localhost"):
|
| 25 |
Dataservice.initialize(dbname, db_hostname)
|
26 |
Dataservice.initialize(dbname, db_hostname)
|
| 26 |
|
27 |
|
| Line 53... |
Line 54... |
| 53 |
raise PromotionException(111, 'This promotion is still running. Promotion id' + str(promotion_id))
|
54 |
raise PromotionException(111, 'This promotion is still running. Promotion id' + str(promotion_id))
|
| 54 |
deletecount = Coupon.query.filter_by(promotion_id = promotion_id).delete()
|
55 |
deletecount = Coupon.query.filter_by(promotion_id = promotion_id).delete()
|
| 55 |
session.commit()
|
56 |
session.commit()
|
| 56 |
return deletecount
|
57 |
return deletecount
|
| 57 |
|
58 |
|
| 58 |
def create_coupon(promotionId, couponCode, arguments, isCod, prefix=None):
|
59 |
def create_coupon(promotionId, couponCategory, couponCode, arguments, isCod, prefix=None):
|
| 59 |
if promotionId not in (26,27,28):
|
60 |
if promotionId not in (26,27,28):
|
| 60 |
raise PromotionException(101, 'Only promotion ids 26 and 27 are expected')
|
61 |
raise PromotionException(101, 'Only promotion ids 26 and 27 are expected')
|
| 61 |
promotion = Promotion.get_by(id = promotionId)
|
62 |
promotion = Promotion.get_by(id = promotionId)
|
| 62 |
if promotion:
|
63 |
if promotion:
|
| 63 |
if couponCode == '':
|
64 |
if couponCode == '':
|
| Line 66... |
Line 67... |
| 66 |
coupon_code = couponCode
|
67 |
coupon_code = couponCode
|
| 67 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
68 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| 68 |
while coupon is not None:
|
69 |
while coupon is not None:
|
| 69 |
coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
|
70 |
coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
|
| 70 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
71 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| - |
|
72 |
|
| - |
|
73 |
arguments_map= ast.literal_eval(arguments)
|
| - |
|
74 |
if arguments_map.has_key('orderId'):
|
| - |
|
75 |
coupon_code = coupon_code +'#'+ str(arguments_map['orderId'])
|
| 71 |
coupon = Coupon()
|
76 |
coupon = Coupon()
|
| 72 |
coupon.promotion = promotion
|
77 |
coupon.promotion = promotion
|
| 73 |
coupon.coupon_code = coupon_code
|
78 |
coupon.coupon_code = coupon_code
|
| 74 |
coupon.arguments = arguments
|
79 |
coupon.arguments = arguments
|
| - |
|
80 |
coupon.coupon_category = couponCategory
|
| 75 |
session.commit()
|
81 |
session.commit()
|
| 76 |
return coupon_code
|
82 |
return coupon_code
|
| 77 |
else:
|
83 |
else:
|
| 78 |
raise PromotionException(101, 'Could not find Promotion for id' + str(promotionId))
|
84 |
raise PromotionException(101, 'Could not find Promotion for id' + str(promotionId))
|
| 79 |
|
85 |
|