| Line 6... |
Line 6... |
| 6 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
|
6 |
from shop2020.thriftpy.model.v1.user.ttypes import PromotionException, Discount
|
| 7 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
7 |
from shop2020.model.v1.user.impl.PromotionRuleDataUtilities import get_coupon_usage_count, get_coupon_usage_count_by_user
|
| 8 |
from shop2020.clients.UserClient import UserClient
|
8 |
from shop2020.clients.UserClient import UserClient
|
| 9 |
|
9 |
|
| 10 |
def execute(cart, coupon_code, args):
|
10 |
def execute(cart, coupon_code, args):
|
| 11 |
if 'items' not in args or 'discount' not in args or 'handset_display_name' not in args:
|
11 |
if 'items' not in args or 'handset_display_name' not in args:
|
| 12 |
raise PromotionException(109, 'Error in rule arguments.')
|
12 |
raise PromotionException(109, 'Error in rule arguments.')
|
| 13 |
|
13 |
|
| 14 |
if 'usage_limit' in args and args['usage_limit'] is not None:
|
14 |
if 'usage_limit' in args and args['usage_limit'] is not None:
|
| 15 |
if args['usage_limit'] <= get_coupon_usage_count(coupon_code):
|
15 |
if args['usage_limit'] <= get_coupon_usage_count(coupon_code):
|
| 16 |
raise PromotionException(112, 'This promotion is over.')
|
16 |
raise PromotionException(112, 'This promotion is over.')
|
| Line 22... |
Line 22... |
| 22 |
if args['usage_limit_for_user'] <= get_coupon_usage_count_by_user(coupon_code, user.userId):
|
22 |
if args['usage_limit_for_user'] <= get_coupon_usage_count_by_user(coupon_code, user.userId):
|
| 23 |
raise PromotionException(111, 'You have already used this coupon maximum possible times.')
|
23 |
raise PromotionException(111, 'You have already used this coupon maximum possible times.')
|
| 24 |
|
24 |
|
| 25 |
if not cart.lines:
|
25 |
if not cart.lines:
|
| 26 |
return cart
|
26 |
return cart
|
| 27 |
|
27 |
isPercentageDiscount = False
|
| 28 |
total_selling_price = 0
|
28 |
total_selling_price = 0
|
| 29 |
total_discounted_price = 0
|
29 |
total_discounted_price = 0
|
| 30 |
cart_has_specified_item = False
|
30 |
cart_has_specified_item = False
|
| 31 |
discounts = []
|
31 |
discounts = []
|
| 32 |
|
32 |
|
| - |
|
33 |
if 'is_percentage_discount' in args:
|
| - |
|
34 |
isPercentageDiscount = args['is_percentage_discount']
|
| 33 |
for line in cart.lines:
|
35 |
for line in cart.lines:
|
| 34 |
total_selling_price += line.actualPrice * line.quantity
|
36 |
total_selling_price += line.actualPrice * line.quantity
|
| 35 |
discount_value = 0
|
37 |
discount_value = 0
|
| 36 |
|
38 |
|
| 37 |
if line.itemId in args['items']:
|
39 |
if line.itemId in args['items']:
|
| 38 |
cart_has_specified_item = True
|
40 |
cart_has_specified_item = True
|
| - |
|
41 |
discount_value = args['items'][line.itemId]
|
| - |
|
42 |
if isPercentageDiscount:
|
| - |
|
43 |
discount_value = (line.actualPrice*discount_value)/100
|
| - |
|
44 |
|
| 39 |
line.discountedPrice = round(line.actualPrice - args['discount'], 4)
|
45 |
line.discountedPrice = round(line.actualPrice - discount_value, 4)
|
| 40 |
total_discounted_price += round(line.discountedPrice * line.quantity, 4)
|
46 |
total_discounted_price += round(line.discountedPrice * line.quantity, 4)
|
| 41 |
discount_value = args['discount']
|
- |
|
| 42 |
else:
|
47 |
else:
|
| 43 |
total_discounted_price += round(line.actualPrice * line.quantity, 4)
|
48 |
total_discounted_price += round(line.actualPrice * line.quantity, 4)
|
| 44 |
|
49 |
|
| 45 |
if discount_value > 0:
|
50 |
if discount_value > 0:
|
| 46 |
discount = Discount()
|
51 |
discount = Discount()
|