[FIX] purchase_stock: compare the quantities with float_compare

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) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2023-02-03 16:32:18 +01:00
parent 84302a21b3
commit c9f62d0b8b
+2 -2
View File
@@ -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'))