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