From 24a16f5db58c4dfe955f97da0a432e128ff548bd Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 9 Sep 2016 15:40:36 +0200 Subject: [PATCH] [FIX] mrp, mrp_byproduct: updating the quantity of production orders fixes When updating quantity, it should take use a similar method as for generating the moves, but with the quantity already produced (and posted) deduced. The parameters for these method needed to be changed. When all the moves are posted, we should create the necessary extra moves. If the quantity is put back to the quantity posted, it might also need to delete moves. In byproduct, it should take into account the subproduct factor. When the quantity produced on the work orders has reached the quantity to do, it should not allow anymore to use the "Done" button on work orders, but rather use the Finish button instead. With the Update button on the manufacturing order it is possible to do more. --- addons/mrp/models/mrp_bom.py | 4 ++ addons/mrp/models/mrp_production.py | 19 ++++--- addons/mrp/views/mrp_workorder_views.xml | 2 +- addons/mrp/wizard/change_production_qty.py | 45 ++++++++++------- addons/mrp_byproduct/models/mrp_production.py | 50 ++++++++++--------- addons/mrp_byproduct/models/stock_move.py | 2 +- .../wizard/change_production_qty.py | 21 ++++---- addons/stock/models/stock_move.py | 1 + 8 files changed, 83 insertions(+), 61 deletions(-) diff --git a/addons/mrp/models/mrp_bom.py b/addons/mrp/models/mrp_bom.py index 91ee51bd9f1..f38cb346007 100644 --- a/addons/mrp/models/mrp_bom.py +++ b/addons/mrp/models/mrp_bom.py @@ -111,6 +111,10 @@ class MrpBom(models.Model): return self.search(domain, order='sequence, product_id', limit=1) def explode(self, product, quantity, picking_type=False): + """ + Explodes the BoM and creates two lists with all the information you need: bom_done and line_done + Quantity should be passed in the UoM of the BoM (don't divide by its quantity) + """ boms_done = [(self, {'qty': quantity, 'product': product, 'original_qty': quantity, 'parent_line': False})] lines_done = [] templates_done = product.product_tmpl_id diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index df3b72a6e91..7ff5bbba781 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -311,8 +311,7 @@ class MrpProduction(models.Model): source_location = self.bom_id.routing_id.location_id else: source_location = self.location_src_id - original_quantity = self.env['product.uom']._compute_qty(self.product_uom_id.id, self.product_qty, self.bom_id.product_uom_id.id) - + original_quantity = self.product_qty - self.qty_produced data = { 'name': self.name, 'date': self.date_planned_start, @@ -354,14 +353,21 @@ class MrpProduction(models.Model): move.procure_method = 'make_to_order' @api.multi - def _update_raw_move(self, bom_line, quantity, **kw): + def _update_raw_move(self, bom_line, line_data): + quantity = line_data['qty'] self.ensure_one() move = self.move_raw_ids.filtered(lambda x: x.bom_line_id.id == bom_line.id and x.state not in ('done', 'cancel')) if move: - move.write({'product_uom_qty': quantity}) + if quantity > 0: + move[0].write({'product_uom_qty': quantity}) + else: + if move[0].quantity_done > 0: + raise UserError(_('Lines need to be deleted, but can not as you still have some quantities to consume in them. ')) + move[0].action_cancel() + move[0].unlink() return move else: - self._generate_raw_move(bom_line, quantity) + self._generate_raw_move(bom_line, line_data) @api.multi def action_assign(self): @@ -398,8 +404,7 @@ class MrpProduction(models.Model): workorders = self.env['mrp.workorder'] qty = bom_data['qty'] - use_serial = any(product.tracking == 'serial' for product in self.mapped('move_finished_ids.product_id')) - if use_serial: + if self.product_id.tracking == 'serial': quantity = 1.0 else: quantity = self.product_qty - sum(self.move_finished_ids.mapped('quantity_done')) diff --git a/addons/mrp/views/mrp_workorder_views.xml b/addons/mrp/views/mrp_workorder_views.xml index b52fa0b2ff1..f2df2dd66f0 100644 --- a/addons/mrp/views/mrp_workorder_views.xml +++ b/addons/mrp/views/mrp_workorder_views.xml @@ -100,7 +100,7 @@