summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-21 11:06:58 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-21 11:06:58 +0700
commitda2389775171d288b96958651a45f07865a2e014 (patch)
treefe31280f59adf1718bd8e43e542bccd846d556a9 /indoteknik_api/controllers/api_v1
parent7489d3fba967e711cb0fdfd6d3cb5097751e883f (diff)
Update voucher use manufacture rules
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py
index 5cdafba4..96c52e1e 100644
--- a/indoteknik_api/controllers/api_v1/voucher.py
+++ b/indoteknik_api/controllers/api_v1/voucher.py
@@ -25,14 +25,36 @@ class Voucher(controller.Controller):
checkout = cart.get_user_checkout(user_id)
for voucher in vouchers:
- subtotal = checkout['subtotal']
+ apply_status = ''
+ products = checkout['products']
min_purchase_amount = voucher['min_purchase_amount']
max_discount_amount = voucher['max_discount_amount']
discount_type = voucher['discount_type']
discount_amount = voucher['discount_amount']
- can_apply = subtotal >= min_purchase_amount
+ can_apply = True
difference_to_apply = 0
- if not can_apply:
+
+ manufacture_ids = [x['id'] for x in voucher['manufactures']]
+ subtotal = 0
+ has_match_manufacture = False
+ for product in products:
+ price = product['price']['price']
+ price_discount = product['price']['price_discount']
+ quantity = product['quantity']
+ manufacture_id = product['manufacture']['id'] or False
+
+ if len(manufacture_ids) == 0 or manufacture_id in manufacture_ids:
+ purchase_amt = price * quantity
+ discount_amt = (price - price_discount) * quantity
+ subtotal += purchase_amt - discount_amt
+ has_match_manufacture = True
+
+ if not has_match_manufacture:
+ can_apply = False
+ apply_status = 'UM'
+ elif subtotal < min_purchase_amount:
+ can_apply = False
+ apply_status = 'MPA'
difference_to_apply = min_purchase_amount - subtotal
discount_voucher = 0
@@ -45,6 +67,7 @@ class Voucher(controller.Controller):
discount_voucher = max_discount_amount
voucher['can_apply'] = can_apply
+ voucher['apply_status'] = apply_status
voucher['discount_voucher'] = discount_voucher
voucher['difference_to_apply'] = difference_to_apply