| Line 7... |
Line 7... |
| 7 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
7 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
| 8 |
from shop2020.model.v1.user.impl import Dataservice
|
8 |
from shop2020.model.v1.user.impl import Dataservice
|
| 9 |
from shop2020.model.v1.user.impl.Dataservice import Promotion, Coupon, PromotionTracker,\
|
9 |
from shop2020.model.v1.user.impl.Dataservice import Promotion, Coupon, PromotionTracker,\
|
| 10 |
RechargeVoucher
|
10 |
RechargeVoucher
|
| 11 |
from shop2020.utils.Utils import to_py_date
|
11 |
from shop2020.utils.Utils import to_py_date
|
| - |
|
12 |
import uuid
|
| 12 |
|
13 |
|
| 13 |
from elixir import session
|
14 |
from elixir import session
|
| 14 |
import datetime, traceback
|
15 |
import datetime, traceback
|
| - |
|
16 |
from string import Template
|
| 15 |
|
17 |
|
| 16 |
def initialize(dbname = 'user', db_hostname="localhost"):
|
18 |
def initialize(dbname = 'user', db_hostname="localhost"):
|
| 17 |
Dataservice.initialize(dbname, db_hostname)
|
19 |
Dataservice.initialize(dbname, db_hostname)
|
| 18 |
|
20 |
|
| 19 |
def create_promotion(name, rule_execution_src, start_on, end_on):
|
21 |
def create_promotion(name, rule_execution_src, start_on, end_on):
|
| Line 35... |
Line 37... |
| 35 |
coupon.promotion = promotion
|
37 |
coupon.promotion = promotion
|
| 36 |
coupon.coupon_code = coupon_code
|
38 |
coupon.coupon_code = coupon_code
|
| 37 |
coupon.arguments = ""
|
39 |
coupon.arguments = ""
|
| 38 |
session.commit()
|
40 |
session.commit()
|
| 39 |
|
41 |
|
| - |
|
42 |
def create_coupon(promotionId, endOn, email, amount, usage):
|
| - |
|
43 |
if promotionId not in (16,26):
|
| - |
|
44 |
raise PromotionException(101, 'Only promotion ids 16 and 26 are expected')
|
| - |
|
45 |
promotion = Promotion.get_by(id = promotionId)
|
| - |
|
46 |
if promotion:
|
| - |
|
47 |
coupon_code = uuid.uuid4().hex[:10]
|
| - |
|
48 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| - |
|
49 |
while coupon is not None:
|
| - |
|
50 |
coupon_code = uuid.uuid4().hex[:10]
|
| - |
|
51 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| - |
|
52 |
s=Template('{"emails":["$email"],"discount":$amount,"usage_limit_for_user":$usage,"endOn":$endOn}')
|
| - |
|
53 |
coupon = Coupon()
|
| - |
|
54 |
coupon.promotion = promotion
|
| - |
|
55 |
coupon.coupon_code = coupon_code
|
| - |
|
56 |
coupon.arguments = s.substitute(email=email, amount=amount, usage=usage, endOn=endOn)
|
| - |
|
57 |
session.commit()
|
| - |
|
58 |
return coupon_code
|
| - |
|
59 |
else:
|
| - |
|
60 |
raise PromotionException(101, 'Could not find Promotion for id' + str(promotionId))
|
| - |
|
61 |
|
| 40 |
def apply_coupon(coupon_code, cart_id):
|
62 |
def apply_coupon(coupon_code, cart_id):
|
| 41 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
63 |
coupon = Coupon.get_by(coupon_code = coupon_code)
|
| 42 |
|
64 |
|
| 43 |
if coupon:
|
65 |
if coupon:
|
| 44 |
todate = datetime.datetime.now()
|
66 |
todate = datetime.datetime.now()
|