summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-07-25 04:24:24 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-07-25 04:24:24 +0000
commite933a05e9b03e489b581f27d1aa304774aafc320 (patch)
tree4c0e32918e1ddf4e7a3e9116d3abb186ad417c7f /indoteknik_api/controllers/api_v1
parent940054dbc1dffca75bfb81e478d5538f762009c6 (diff)
parentd454b715e7c7c31836cd525d9470b0eb3b1e7376 (diff)
Merged in feature/voucher-cart (pull request #67)
Feature/voucher cart
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py12
-rw-r--r--indoteknik_api/controllers/api_v1/voucher.py13
2 files changed, 8 insertions, 17 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 6c878197..208789af 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -355,13 +355,13 @@ class SaleOrder(controller.Controller):
manufacture_id = line.product_id.x_manufacture.id or False
if len(manufacture_ids) > 0 and manufacture_id not in manufacture_ids:
continue
- voucher_discount_line = line.price_subtotal / amount_untaxed * voucher_discount
- line.amount_voucher_disc = voucher_discount_line
+ voucher_disc_line = line.price_subtotal / amount_untaxed * voucher_discount
+ line.amount_voucher_disc = voucher_disc_line
- discount_decimal = line.discount / 100
- voucher_discount_item = voucher_discount_line / line.product_uom_qty
- voucher_disc_before_line_disc = voucher_discount_item / (1 - discount_decimal)
- line.price_unit -= voucher_disc_before_line_disc
+ voucher_disc_item = voucher_disc_line / line.product_uom_qty
+ voucher_disc_subtotal = line.price_subtotal - voucher_disc_item
+
+ line.discount = (line.price_unit - voucher_disc_subtotal) / line.price_unit * 100
cart_ids = [x['cart_id'] for x in products]
user_cart.browse(cart_ids).unlink()
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