| Line 8... |
Line 8... |
| 8 |
'''
|
8 |
'''
|
| 9 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
9 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException
|
| 10 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
|
10 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count_by_user
|
| 11 |
from shop2020.clients.CatalogClient import CatalogClient
|
11 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 12 |
from shop2020.thriftpy.model.v1.user.ttypes import Discount
|
12 |
from shop2020.thriftpy.model.v1.user.ttypes import Discount
|
| - |
|
13 |
from shop2020.clients.UserClient import UserClient
|
| - |
|
14 |
from shop2020.utils.Utils import to_py_date
|
| - |
|
15 |
import datetime
|
| 13 |
|
16 |
|
| 14 |
def execute(cart, coupon_code, args):
|
17 |
def execute(cart, coupon_code, args):
|
| 15 |
|
18 |
|
| 16 |
#Allow a user to use the coupon only 1 time
|
19 |
#Allow a user to use the coupon only 1 time
|
| 17 |
count_users_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
|
20 |
count_users_usage = get_coupon_usage_count_by_user(coupon_code, cart.userId)
|
| Line 20... |
Line 23... |
| 20 |
raise PromotionException(111, 'This promotion is over.')
|
23 |
raise PromotionException(111, 'This promotion is over.')
|
| 21 |
|
24 |
|
| 22 |
discounts = []
|
25 |
discounts = []
|
| 23 |
|
26 |
|
| 24 |
if cart.lines:
|
27 |
if cart.lines:
|
| - |
|
28 |
user_client = UserClient().get_client()
|
| - |
|
29 |
|
| - |
|
30 |
user_state = user_client.getUserState(cart.userId)
|
| - |
|
31 |
active_since = to_py_date(user_state.activeSince)
|
| - |
|
32 |
|
| - |
|
33 |
if datetime.date(2012, 5, 1) < datetime.date(active_since.year, active_since.month, active_since.day):
|
| - |
|
34 |
raise PromotionException(111, 'You are not eligible for this discount')
|
| - |
|
35 |
|
| 25 |
catalog_client = CatalogClient().get_client()
|
36 |
catalog_client = CatalogClient().get_client()
|
| 26 |
|
37 |
|
| 27 |
category_map = {}
|
38 |
category_map = {}
|
| 28 |
for category in catalog_client.getAllCategories():
|
39 |
for category in catalog_client.getAllCategories():
|
| 29 |
if category_map.has_key(category.parent_category_id):
|
40 |
if category_map.has_key(category.parent_category_id):
|