summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-25 11:23:03 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-25 11:23:03 +0700
commit03665a9e38b90379aa1a43391aaaa352c125e0cb (patch)
tree0cce6df98749fd28bc3306f255596134dbe8992f /indoteknik_api/controllers/api_v1
parente24789e8df500f47e6d1df28e3c656874709eb70 (diff)
Refactor get voucher API
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py
index a6a88cad..4baa93b7 100644
--- a/indoteknik_api/controllers/api_v1/voucher.py
+++ b/indoteknik_api/controllers/api_v1/voucher.py
@@ -31,9 +31,6 @@ class Voucher(controller.Controller):
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 = True
difference_to_apply = 0
@@ -60,14 +57,8 @@ class Voucher(controller.Controller):
apply_status = 'MPA'
difference_to_apply = min_purchase_amount - subtotal
- discount_voucher = 0
- if discount_type == 'fixed_price':
- discount_voucher = discount_amount
- if discount_type == 'percentage':
- discount_voucher = subtotal * discount_amount / 100
-
- if max_discount_amount > 0 and discount_voucher > max_discount_amount:
- discount_voucher = max_discount_amount
+ obj_voucher = request.env['voucher'].browse(voucher['id'])
+ discount_voucher = obj_voucher.calculate_discount(subtotal)
voucher['can_apply'] = can_apply
voucher['apply_status'] = apply_status