| 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, endOn, email, amount, isCod, usage):
|
47 |
def create_coupon(promotionId, endOn, email, amount, isCod, usage, prefix=None):
|
| 48 |
if promotionId not in (26,27):
|
48 |
if promotionId not in (26,27):
|
| 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 |
coupon_code = uuid.uuid4().hex[:10]
|
52 |
coupon_code = uuid.uuid4().hex[:10] if prefix is None else prefix + uuid.uuid4().hex[:10]
|
| 53 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
53 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| 54 |
while coupon is not None:
|
54 |
while coupon is not None:
|
| 55 |
coupon_code = uuid.uuid4().hex[:10]
|
55 |
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)
|
56 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| 57 |
s=Template('{"emails":["$email"],"discount":$amount,"usage_limit_for_user":$usage,"endOn":$endOn, "isCod":$isCod}')
|
57 |
s=Template('{"emails":["$email"],"discount":$amount,"usage_limit_for_user":$usage,"endOn":$endOn, "isCod":$isCod}')
|
| 58 |
coupon = Coupon()
|
58 |
coupon = Coupon()
|
| 59 |
coupon.promotion = promotion
|
59 |
coupon.promotion = promotion
|
| 60 |
coupon.coupon_code = coupon_code
|
60 |
coupon.coupon_code = coupon_code
|