diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-08-04 03:59:33 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-08-04 03:59:33 +0000 |
| commit | 6d17228cd6c789fe4460e28807d5b39fb1bbe9b7 (patch) | |
| tree | a4c961062c026e1005ebdc82547903c3f30c0a06 /indoteknik_api/controllers/api_v1/voucher.py | |
| parent | cc182dd9963fb8985661ca1b64a53e7f11f095c5 (diff) | |
| parent | bcc35009da39e9ee8b5e181006d3690316b83c59 (diff) | |
Merged in development (pull request #82)
Development
Diffstat (limited to 'indoteknik_api/controllers/api_v1/voucher.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/voucher.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 4baa93b7..f82e1aef 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 @@ -43,18 +43,25 @@ class Voucher(controller.Controller): 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 + if len(manufacture_ids) == 0 or (not product['has_flashsale'] and manufacture_id in manufacture_ids): 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 + 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 +69,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 |
