| Line 37... |
Line 37... |
| 37 |
coupon.promotion = promotion
|
37 |
coupon.promotion = promotion
|
| 38 |
coupon.coupon_code = coupon_code
|
38 |
coupon.coupon_code = coupon_code
|
| 39 |
coupon.arguments = ""
|
39 |
coupon.arguments = ""
|
| 40 |
session.commit()
|
40 |
session.commit()
|
| 41 |
|
41 |
|
| 42 |
def create_coupon(promotionId, endOn, email, amount, usage):
|
42 |
def create_coupon(promotionId, endOn, email, amount, isCod, usage):
|
| 43 |
if promotionId not in (16,26):
|
43 |
if promotionId not in (16,26):
|
| 44 |
raise PromotionException(101, 'Only promotion ids 16 and 26 are expected')
|
44 |
raise PromotionException(101, 'Only promotion ids 16 and 26 are expected')
|
| 45 |
promotion = Promotion.get_by(id = promotionId)
|
45 |
promotion = Promotion.get_by(id = promotionId)
|
| 46 |
if promotion:
|
46 |
if promotion:
|
| 47 |
coupon_code = uuid.uuid4().hex[:10]
|
47 |
coupon_code = uuid.uuid4().hex[:10]
|
| 48 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
48 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| 49 |
while coupon is not None:
|
49 |
while coupon is not None:
|
| 50 |
coupon_code = uuid.uuid4().hex[:10]
|
50 |
coupon_code = uuid.uuid4().hex[:10]
|
| 51 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
51 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| 52 |
s=Template('{"emails":["$email"],"discount":$amount,"usage_limit_for_user":$usage,"endOn":$endOn}')
|
52 |
s=Template('{"emails":["$email"],"discount":$amount,"usage_limit_for_user":$usage,"endOn":$endOn, "isCod":$isCod}')
|
| 53 |
coupon = Coupon()
|
53 |
coupon = Coupon()
|
| 54 |
coupon.promotion = promotion
|
54 |
coupon.promotion = promotion
|
| 55 |
coupon.coupon_code = coupon_code
|
55 |
coupon.coupon_code = coupon_code
|
| 56 |
coupon.arguments = s.substitute(email=email, amount=amount, usage=usage, endOn=endOn)
|
56 |
coupon.arguments = s.substitute(email=email, amount=amount, usage=usage, endOn=endOn, isCod=isCod)
|
| 57 |
session.commit()
|
57 |
session.commit()
|
| 58 |
return coupon_code
|
58 |
return coupon_code
|
| 59 |
else:
|
59 |
else:
|
| 60 |
raise PromotionException(101, 'Could not find Promotion for id' + str(promotionId))
|
60 |
raise PromotionException(101, 'Could not find Promotion for id' + str(promotionId))
|
| 61 |
|
61 |
|