From fb1839fa17a3197d781b45dbfe755277b4816904 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Mon, 1 Jul 2019 09:51:53 +0000 Subject: [PATCH] [FIX] mrp: cancel move when click on Mark Done [FIX] mrp: Manufacturing cost analysis report Steps to reproduce the bug: - Create a finished product P with a manufacturing BOM B - Set two components on B C1 and C2 - Create a MO with P and process it(plan and produce it) - Unlock the MO and set the consumed qty of C1 to 0 - Lock and click on Mark as Done - Click on Cost Analysis Bug: C1 was displayed in the report with a qty = 1.0 Fine tuning of this commit: cb4afb263b50b2e7c6ecfc2a57bb3df0dfd0f881 opw:2010912 closes odoo/odoo#34642 Signed-off-by: Simon Goffin (sig) --- addons/mrp/models/mrp_production.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 7814c1d9133..edb9ddb8124 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -667,8 +667,6 @@ class MrpProduction(models.Model): moves_to_do = order.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel')) for move in moves_to_do.filtered(lambda m: m.product_qty == 0.0 and m.quantity_done > 0): move.product_uom_qty = move.quantity_done - for move in moves_to_do.filtered(lambda m: float_is_zero(m.quantity_done, precision_rounding=m.product_uom.rounding)): - move._action_cancel() moves_to_do._action_done() moves_to_do = order.move_raw_ids.filtered(lambda x: x.state == 'done') - moves_not_to_do order._cal_price(moves_to_do) @@ -695,6 +693,11 @@ class MrpProduction(models.Model): if wo.time_ids.filtered(lambda x: (not x.date_end) and (x.loss_type in ('productive', 'performance'))): raise UserError(_('Work order %s is still running') % wo.name) self._check_lots() + + # Cancel unfinished move + move_to_cancel = self.move_raw_ids.filtered(lambda m: m.state not in ('done', 'cancel') and float_is_zero(m.quantity_done, precision_rounding=m.product_uom.rounding)) + move_to_cancel._action_cancel() + self.post_inventory() # Moves without quantity done are not posted => set them as done instead of canceling. In # case the user edits the MO later on and sets some consumed quantity on those, we do not