From 972d8a11086a2419d7f432e3320c5bb4074b87d7 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Fri, 4 May 2018 11:02:49 +0200 Subject: [PATCH] [FIX] mrp: tracked by product with routing Use case to reproduce: - Create a BOM with a byproduct tracked and a routing - Mark the last workorder as done - by products move line are not created With the wizard produce (MO without routing) move lines are created. Thus there is an inconsistency. It happpens because workorders and produce button do not use the same function. commit 1a09bcc6221e1856ece4d176205f2aaa1a205a3a already fix it for production wizard however it forgets workorders process. opw-1838707 --- addons/mrp/models/mrp_workorder.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index f7db1a6e8c3..c617427cd1f 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -284,6 +284,18 @@ class MrpWorkorder(models.Model): self.final_lot_id = self.env['stock.production.lot'].search([('use_next_on_work_order_id', '=', self.id)], order='create_date, id', limit=1) + def _get_byproduct_move_line(self, by_product_move, quantity): + return { + 'move_id': by_product_move.id, + 'product_id': by_product_move.product_id.id, + 'product_uom_qty': quantity, + 'product_uom_id': by_product_move.product_uom.id, + 'qty_done': quantity, + 'workorder_id': self.id, + 'location_id': by_product_move.location_id.id, + 'location_dest_id': by_product_move.location_dest_id.id, + } + @api.multi def record_production(self): self.ensure_one() @@ -361,8 +373,14 @@ class MrpWorkorder(models.Model): if not self.next_work_order_id: for by_product_move in self.production_id.move_finished_ids.filtered(lambda x: (x.product_id.id != self.production_id.product_id.id) and (x.state not in ('done', 'cancel'))): - if by_product_move.has_tracking == 'none': - by_product_move.quantity_done += self.qty_producing * by_product_move.unit_factor + if by_product_move.has_tracking != 'serial': + values = self._get_byproduct_move_line(by_product_move, self.qty_producing * by_product_move.unit_factor) + self.env['stock.move.line'].create(values) + elif by_product_move.has_tracking == 'serial': + qty_todo = by_product_move.product_uom._compute_quantity(self.qty_producing * by_product_move.unit_factor, by_product_move.product_id.uom_id) + for i in range(0, int(float_round(qty_todo, precision_digits=0))): + values = self._get_byproduct_move_line(by_product_move, 1) + self.env['stock.move.line'].create(values) # Update workorder quantity produced self.qty_produced += self.qty_producing