From dd93d36b4c7cec4e1681d69e296a7cff559386a0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 2 Jul 2025 11:48:35 +0700 Subject: search invoice marketplace and add discount on order line purchase and add biaya lain lain on purchase --- fixco_custom/models/purchase_order_line.py | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 fixco_custom/models/purchase_order_line.py (limited to 'fixco_custom/models/purchase_order_line.py') diff --git a/fixco_custom/models/purchase_order_line.py b/fixco_custom/models/purchase_order_line.py new file mode 100644 index 0000000..8cac3d1 --- /dev/null +++ b/fixco_custom/models/purchase_order_line.py @@ -0,0 +1,38 @@ +from odoo import models, fields, api + +class PurchaseOrderLine(models.Model): + _inherit = 'purchase.order.line' + + discount = fields.Float( + string='Discount (%)', + digits='Discount', + default=0.0 + ) + discount_amount = fields.Float( + string='Discount Amount', + compute='_compute_discount_amount' + ) + + @api.depends('price_unit', 'product_qty', 'discount') + def _compute_discount_amount(self): + for line in self: + discount = line.discount or 0.0 + line.discount_amount = (line.price_unit * line.product_qty * discount) / 100.0 + + def _prepare_compute_all_values(self): + res = super(PurchaseOrderLine, self)._prepare_compute_all_values() + price_unit = res['price_unit'] * (1 - (self.discount or 0.0) / 100.0) + res.update({ + 'price_unit': price_unit, + }) + return res + + @api.depends('product_qty', 'price_unit', 'taxes_id', 'discount') + def _compute_amount(self): + return super(PurchaseOrderLine, self)._compute_amount() + + def write(self, values): + res = super().write(values) + if 'discount' in values: + self._compute_amount() + return res \ No newline at end of file -- cgit v1.2.3