From d5319d565a4b40cc6fe5b7fa8f9abc507f09e752 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 14 Jul 2023 17:02:27 +0700 Subject: Add amount voucher on sale order and update api --- indoteknik_api/controllers/api_v1/sale_order.py | 5 ++++- indoteknik_custom/models/sale_order.py | 2 ++ indoteknik_custom/views/sale_order.xml | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index e036751e..713b3bff 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -342,8 +342,10 @@ class SaleOrder(controller.Controller): ('code', '=', params['value']['voucher']) ]) if voucher: - sale_order.voucher_id = voucher.id voucher_discount = voucher.calculate_discount(amount_untaxed) + sale_order.voucher_id = voucher.id + sale_order.amount_voucher_disc = voucher_discount + total_qty = sum(line.product_uom_qty for line in sale_order.order_line) voucher_discount_item = voucher_discount / total_qty for line in sale_order.order_line: @@ -351,6 +353,7 @@ class SaleOrder(controller.Controller): voucher_discount_line = voucher_discount_item / (1 - discount_decimal) price = line.price_unit - voucher_discount_line line.price_unit = price + line.amount_voucher_disc = voucher_discount_item * line.product_uom_qty return self.response({ 'id': sale_order.id, diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e54b9ae2..1bdc0cb6 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -87,6 +87,7 @@ class SaleOrder(models.Model): npwp = fields.Char(string="NPWP") purchase_total = fields.Monetary(string='Purchase Total', compute='_compute_purchase_total') voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher') + amount_voucher_disc = fields.Float(string='Voucher Discount') def _compute_purchase_total(self): for order in self: @@ -586,6 +587,7 @@ class SaleOrderLine(models.Model): line_no = fields.Integer('No', default=0, copy=False) note_procurement = fields.Char(string='Note', help="Harap diisi jika ada keterangan tambahan dari Procurement, agar dapat dimonitoring") vendor_subtotal = fields.Float(string='Vendor Subtotal', compute="_compute_vendor_subtotal") + amount_voucher_disc = fields.Float(string='Voucher Discount') def _compute_vendor_subtotal(self): for line in self: diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index b55fefff..7679f92d 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -71,12 +71,18 @@ + +