summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-08-01 04:33:35 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-08-01 04:33:35 +0000
commit0cdfe713ecec45544caf6fb15c6e1a1c8e515141 (patch)
tree9759a230fbcb4f8b26ede8bc632ac344db3c9c93 /indoteknik_api/controllers/api_v1
parent61bbb1b7164378a31522312ca3a076d6d35141d3 (diff)
parentf8e0259289c728b11a373601e569f6e64ca803f8 (diff)
Merged in feature/voucher-cart (pull request #79)
Update voucher can't combined with other promotions
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py
index 4baa93b7..e6fdca68 100644
--- a/indoteknik_api/controllers/api_v1/voucher.py
+++ b/indoteknik_api/controllers/api_v1/voucher.py
@@ -31,9 +31,9 @@ class Voucher(controller.Controller):
apply_status = ''
products = checkout['products']
min_purchase_amount = voucher['min_purchase_amount']
- can_apply = True
+ can_apply = False
difference_to_apply = 0
-
+
manufacture_ids = voucher['manufacture_ids']
subtotal = 0
has_match_manufacture = False
@@ -44,17 +44,26 @@ class Voucher(controller.Controller):
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 product['has_flashsale']:
+ continue
+
+ purchase_amt = price * quantity
+ discount_amt = (price - price_discount) * quantity
+ subtotal += purchase_amt - discount_amt
+
+ has_flashsale_products = any(product['has_flashsale'] for product in products)
if not has_match_manufacture:
- can_apply = False
- apply_status = 'UM'
+ apply_status = 'UM' # Unqualified Manufacture
elif subtotal < min_purchase_amount:
- can_apply = False
- apply_status = 'MPA'
+ apply_status = 'MPA' # Minimum Purchase Amount
+ elif has_flashsale_products:
+ apply_status = 'HF' # Has Flashsale
+ else:
+ can_apply = True
+
+ if subtotal < min_purchase_amount:
difference_to_apply = min_purchase_amount - subtotal
obj_voucher = request.env['voucher'].browse(voucher['id'])
@@ -62,6 +71,7 @@ class Voucher(controller.Controller):
voucher['can_apply'] = can_apply
voucher['apply_status'] = apply_status
+ voucher['has_flashsale_products'] = has_flashsale_products
voucher['discount_voucher'] = discount_voucher
voucher['difference_to_apply'] = difference_to_apply