From 8daa1b6f6a2d51faa9a1b61781ba2f7c40ae4121 Mon Sep 17 00:00:00 2001 From: ronozoro Date: Thu, 14 Nov 2024 01:22:18 -0800 Subject: [PATCH] fix billed amount --- .../models/purchase_order.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/odex25_purchase/purchase_requisition_custom/models/purchase_order.py b/odex25_purchase/purchase_requisition_custom/models/purchase_order.py index 51c708a4f..cade830a8 100644 --- a/odex25_purchase/purchase_requisition_custom/models/purchase_order.py +++ b/odex25_purchase/purchase_requisition_custom/models/purchase_order.py @@ -8,6 +8,23 @@ from dateutil.relativedelta import relativedelta class PurchaseOrderCustom(models.Model): _inherit = "purchase.order" + billed_amount = fields.Float(store=True, compute='_compute_amount') + remaining_amount = fields.Float(store=True, compute='_compute_amount') + + @api.depends('invoice_ids','invoice_count') + def _compute_amount(self): + for order in self: + billed_amount = 0.0 + for invoice in order.invoice_ids: + billed_amount += invoice.amount_total + + currency = order.currency_id or order.partner_id.property_purchase_currency_id or \ + self.env.company.currency_id + order.update({ + 'billed_amount': currency.round(billed_amount), + 'remaining_amount': order.amount_total - billed_amount, + }) + def copy(self, default=None): data = super(PurchaseOrderCustom, self).copy(default) data.email_to_vendor = False