diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-07-02 11:48:35 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-07-02 11:48:35 +0700 |
| commit | dd93d36b4c7cec4e1681d69e296a7cff559386a0 (patch) | |
| tree | 247cf5e739b60592d630b8d86ed6a2be0863dc85 /fixco_custom/models/purchase_order_line.py | |
| parent | 9c17104f86f116782f0ed36f82d7c3de7130d363 (diff) | |
search invoice marketplace and add discount on order line purchase and add biaya lain lain on purchase
Diffstat (limited to 'fixco_custom/models/purchase_order_line.py')
| -rw-r--r-- | fixco_custom/models/purchase_order_line.py | 38 |
1 files changed, 38 insertions, 0 deletions
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 |
