Skip to content
Snippets Groups Projects
Commit ec0206fd authored by Adrien Widart's avatar Adrien Widart
Browse files

[FIX] mrp: compare float thanks to `float_compare`


In some situations, the user can't redefine the quantity to produce of a
MO

To reproduce the issue:
(Use demo data. Enable debug mode)
1. In Decimal Accuracy, edit Product Unit of Measure:
    - Digits: 5
2. Create a MO:
    - Product: [FURN_7023] Wood Panel
    - Quantity To Produce: 1000
3. Produce 800
4. Update the Quantity To Produce: 800

Error: An error message is displayed: "You have already processed
800.00000. Please input a quantity higher than 800.00000"

Due to a floating point issue, the produced quantity is actually
800.0000000000001 which is greater than 800. This is the reason why the
`UserError` is raised

Some similar issues might be found with the other float comparisons in
`change_prod_qty`.

OPW-2689831

closes odoo/odoo#80388

Signed-off-by: default avatarArnold Moyaux <arm@odoo.com>
parent 89814281
Branches
Tags
No related merge requests found
......@@ -3,7 +3,7 @@
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import float_is_zero, float_round
from odoo.tools import float_is_zero, float_round, float_compare
class ChangeProductionQty(models.TransientModel):
......@@ -46,7 +46,7 @@ class ChangeProductionQty(models.TransientModel):
for wizard in self:
production = wizard.mo_id
produced = sum(production.move_finished_ids.filtered(lambda m: m.product_id == production.product_id).mapped('quantity_done'))
if wizard.product_qty < produced:
if float_compare(wizard.product_qty, produced, precision_digits=precision) < 0:
format_qty = '%.{precision}f'.format(precision=precision)
raise UserError(_("You have already processed %s. Please input a quantity higher than %s ") % (format_qty % produced, format_qty % produced))
old_production_qty = production.product_qty
......@@ -98,14 +98,14 @@ class ChangeProductionQty(models.TransientModel):
if production.product_id.tracking == 'serial':
quantity = 1.0 if not float_is_zero(quantity, precision_digits=precision) else 0.0
else:
quantity = quantity if (quantity > 0) else 0
quantity = quantity if float_compare(quantity, 0, precision_digits=precision) > 0 else 0
if float_is_zero(quantity, precision_digits=precision):
wo.finished_lot_id = False
wo._workorder_line_ids().unlink()
wo.qty_producing = quantity
if wo.qty_produced < production_qty and wo.state == 'done':
if float_compare(wo.qty_produced, production_qty, precision_digits=precision) < 0 and wo.state == 'done':
wo.state = 'progress'
if wo.qty_produced == production_qty and wo.state == 'progress':
if float_compare(wo.qty_produced, production_qty, precision_digits=precision) == 0 and wo.state == 'progress':
wo.state = 'done'
if wo.next_work_order_id.state == 'pending':
wo.next_work_order_id.state = 'ready'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment