From bfee5cca535c4587eba32d631ffd2b0b909b4edd Mon Sep 17 00:00:00 2001 From: "David (dafr)" Date: Tue, 4 Apr 2023 09:32:09 +0000 Subject: [PATCH] [FIX] mrp_workorder: fix duration_percent out of range duration_percent field is a stored integer. In postgresql, integer are 4 Bytes long, which create a range of -2147483648 to +2147483647. With a small duration_expected, and a big duration, we can easily break these limits. OPW-3253333 closes odoo/odoo#117744 X-original-commit: 97892d04341a2cbbe07e4db6442a451b0cf0b164 Signed-off-by: William Henrotin (whe) Signed-off-by: David --- addons/mrp/models/mrp_workorder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index edbf3ac0674..2f671309c66 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -322,7 +322,7 @@ class MrpWorkorder(models.Model): order.duration = sum(order.time_ids.mapped('duration')) order.duration_unit = round(order.duration / max(order.qty_produced, 1), 2) # rounding 2 because it is a time if order.duration_expected: - order.duration_percent = 100 * (order.duration_expected - order.duration) / order.duration_expected + order.duration_percent = max(-2147483648, min(2147483647, 100 * (order.duration_expected - order.duration) / order.duration_expected)) else: order.duration_percent = 0