From 43d1550ec51a2729cadf6c7d9c36c929733d3067 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Thu, 30 Nov 2023 21:16:00 +0100 Subject: [PATCH] [FIX] purchase_stock: AVCO computation - support line discount --- addons/purchase_stock/models/stock_move.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/purchase_stock/models/stock_move.py b/addons/purchase_stock/models/stock_move.py index d399ef17256aa..ab7a964c9754e 100644 --- a/addons/purchase_stock/models/stock_move.py +++ b/addons/purchase_stock/models/stock_move.py @@ -60,11 +60,14 @@ def _get_price_unit(self): for invoice_line in line.sudo().invoice_lines: if invoice_line.move_id.state != 'posted': continue - if invoice_line.tax_ids: - invoiced_value += invoice_line.tax_ids.with_context(round=False).compute_all( - invoice_line.price_unit, currency=invoice_line.currency_id, quantity=invoice_line.quantity)['total_void'] - else: - invoiced_value += invoice_line.price_unit * invoice_line.quantity + # FIX je@bcim.be - Use discounted untaxed sub-total in price unit used for avco computation + # Current odoo computation is missing the line discount + invoiced_value += invoice_line.price_subtotal + #if invoice_line.tax_ids: + # invoiced_value += invoice_line.tax_ids.with_context(round=False).compute_all( + # invoice_line.price_unit, currency=invoice_line.currency_id, quantity=invoice_line.quantity)['total_void'] + #else: + # invoiced_value += invoice_line.price_unit * invoice_line.quantity invoiced_qty += invoice_line.product_uom_id._compute_quantity(invoice_line.quantity, line.product_id.uom_id) # TODO currency check remaining_value = invoiced_value - receipt_value