From c9f62d0b8bede8a1faa09925310337663723eb7d Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Wed, 1 Feb 2023 15:07:07 +0000 Subject: [PATCH] [FIX] purchase_stock: compare the quantities with float_compare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product “P1” - Create a PO with 7000 unit of P1 - Receive for example “3,483.43” - Create a backorder - Create a bill for received product - Try to confirm the second picking Problem: Traceback is triggered, because the reaming quantity is 0 and we use it in the division: https://github.com/odoo/odoo/blob/16.0/addons/purchase_stock/models/stock_move.py#L57 In this use case we compare “3483.43” and ”3483.4300000003” but in fact `”line.qty_invoiced == received_qyt”` so we should not go through this part of the code: https://github.com/odoo/odoo/blob/16.0/addons/purchase_stock/models/stock_move.py#L40 So as we used `float_round` in the calculation of `qty_invoiced`, we have to use `float_compare` when comparing it with another value https://github.com/odoo/odoo/blob/383947646f5652804bd6bbc764380a890e6f4a8d/addons/stock/models/stock_move.py#L1168 opw-3162603 closes odoo/odoo#111840 X-original-commit: 5899abdea4a622d11f0e7472b489616e08b74523 Signed-off-by: Djamel Touati (otd) --- addons/purchase_stock/models/stock_move.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/purchase_stock/models/stock_move.py b/addons/purchase_stock/models/stock_move.py index 90882dc8864..992f3a07901 100644 --- a/addons/purchase_stock/models/stock_move.py +++ b/addons/purchase_stock/models/stock_move.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, Command, fields, models, _ -from odoo.tools.float_utils import float_round, float_is_zero +from odoo.tools.float_utils import float_round, float_is_zero, float_compare from odoo.exceptions import UserError @@ -42,7 +42,7 @@ class StockMove(models.Model): received_qty = line.qty_received if self.state == 'done': received_qty -= self.product_uom._compute_quantity(self.quantity_done, line.product_uom) - if line.qty_invoiced > received_qty: + if float_compare(line.qty_invoiced, received_qty, precision_rounding=line.product_uom.rounding) > 0: move_layer = line.move_ids.stock_valuation_layer_ids invoiced_layer = line.invoice_lines.stock_valuation_layer_ids receipt_value = sum(move_layer.mapped('value')) + sum(invoiced_layer.mapped('value'))