From 5311f01e65b3d544d00e956e095e37331bf3a4f2 Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Thu, 30 Apr 2020 16:01:42 +0200 Subject: [PATCH] [REF] mrp: update MO according to "To Comsume" Previously, when we upate the "Quantity to Produce" on a MO, we update the components to consume according to the BOM we use. After this commit, we now update the components according their current number set on the MO. For example, if we have a MO to use x component A to produce y product B. When we update the number y to z, the number of A we want to consume will be updated from x to x / y * z, regardless of the setting on the BOM. If multiple components are used, all components will be updated according to this rule. Task: 2241471 --- addons/mrp/models/mrp_production.py | 19 ++++++++++++ addons/mrp/views/mrp_production_views.xml | 10 +++---- addons/mrp/wizard/change_production_qty.py | 35 +++++----------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 289454d6a3e..fc3fa98a9f5 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -861,6 +861,25 @@ class MrpProduction(models.Model): move = self.env['stock.move'].create(move_values) return move, 0, quantity + def _update_raw_moves(self, factor): + self.ensure_one() + update_info = [] + move_to_unlink = self.env['stock.move'] + for move in self.move_raw_ids.filtered(lambda m: m.state not in ('done', 'cancel')): + old_qty = move.product_uom_qty + new_qty = old_qty * factor + if new_qty > 0: + move.write({'product_uom_qty': new_qty}) + move._action_assign() + update_info.append((move, old_qty, new_qty)) + else: + if move.quantity_done > 0: + raise UserError(_('Lines need to be deleted, but can not as you still have some quantities to consume in them. ')) + move._action_cancel() + move_to_unlink |= move + move_to_unlink.unlink() + return update_info + def _get_ready_to_produce_state(self): """ returns 'assigned' if enough components are reserved in order to complete the first operation of the bom. If not returns 'waiting' diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index a972822f35d..f1d5a82f4d5 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -137,7 +137,11 @@ / - + +