| Line 1... |
Line 1... |
| 1 |
'''
|
1 |
'''
|
| 2 |
Created on May 24, 2010
|
2 |
Created on May 24, 2010
|
| 3 |
@author: Varun Gupta
|
3 |
@author: Varun Gupta
|
| 4 |
'''
|
4 |
'''
|
| 5 |
from shop2020.clients.UserClient import UserClient
|
5 |
from elixir import session
|
| 6 |
from shop2020.clients.CatalogClient import CatalogClient
|
6 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 7 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
7 |
from shop2020.clients.UserClient import UserClient
|
| 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, \
|
| 10 |
RechargeVoucher
|
10 |
PromotionTracker, RechargeVoucher
|
| - |
|
11 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import \
|
| - |
|
12 |
get_coupon_usage_count, get_coupon_usage_count_by_user
|
| - |
|
13 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
| 11 |
from shop2020.utils.Utils import to_py_date
|
14 |
from shop2020.utils.Utils import to_py_date
|
| - |
|
15 |
from sqlalchemy.sql.expression import exists
|
| - |
|
16 |
from string import Template
|
| - |
|
17 |
import datetime
|
| - |
|
18 |
import traceback
|
| 12 |
import uuid
|
19 |
import uuid
|
| - |
|
20 |
from shop2020.model.v1.user.impl.Converters import to_t_coupon
|
| 13 |
|
21 |
|
| 14 |
from elixir import session
|
- |
|
| 15 |
import datetime, traceback
|
- |
|
| 16 |
from string import Template
|
- |
|
| 17 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
- |
|
| 18 |
|
22 |
|
| 19 |
def initialize(dbname = 'user', db_hostname="localhost"):
|
23 |
def initialize(dbname = 'user', db_hostname="localhost"):
|
| 20 |
Dataservice.initialize(dbname, db_hostname)
|
24 |
Dataservice.initialize(dbname, db_hostname)
|
| 21 |
|
25 |
|
| 22 |
def create_promotion(name, rule_execution_src, start_on, end_on):
|
26 |
def create_promotion(name, rule_execution_src, start_on, end_on):
|
| Line 234... |
Line 238... |
| 234 |
item_coupons_discounts.append((item_id, discount[0], discount[1]))
|
238 |
item_coupons_discounts.append((item_id, discount[0], discount[1]))
|
| 235 |
break
|
239 |
break
|
| 236 |
|
240 |
|
| 237 |
return item_coupons_discounts
|
241 |
return item_coupons_discounts
|
| 238 |
|
242 |
|
| - |
|
243 |
def get_active_gvs(promotion_id):
|
| - |
|
244 |
all_coupons = session.query(Coupon).filter(~exists().where(Coupon.coupon_code==PromotionTracker.coupon_code)).all()
|
| - |
|
245 |
return [to_t_coupon(coupon) for coupon in all_coupons]
|
| - |
|
246 |
|
| - |
|
247 |
def delete_coupon(coupon_code):
|
| - |
|
248 |
Coupon.query.filter_by(coupon_code = coupon_code).delete()
|
| - |
|
249 |
session.commit()
|
| - |
|
250 |
|
| 239 |
def add_voucher(t_voucher):
|
251 |
def add_voucher(t_voucher):
|
| 240 |
voucher = RechargeVoucher()
|
252 |
voucher = RechargeVoucher()
|
| 241 |
voucher.available = True
|
253 |
voucher.available = True
|
| 242 |
voucher.amount = t_voucher.amount
|
254 |
voucher.amount = t_voucher.amount
|
| 243 |
voucher.voucherCode = t_voucher.voucherCode
|
255 |
voucher.voucherCode = t_voucher.voucherCode
|