From b328ddda2089792e43eef44058e1f5a31e00354a Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 30 Jan 2019 15:14:52 +0000 Subject: [PATCH] [IMP] mrp: MO confirm and create raw moves in batch Production order are created in batch. Confirm them and create their componenets moves in batch also. Adapt _get_moves_raw_values method in order to be multi. action_confirm was already multi. --- addons/mrp/models/mrp_production.py | 10 +++++----- addons/mrp/models/stock_rule.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 469da045f9d..ba2afbc20dc 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -502,12 +502,12 @@ class MrpProduction(models.Model): return move def _get_moves_raw_values(self): - self.ensure_one() moves = [] - factor = self.product_uom_id._compute_quantity(self.product_qty, self.bom_id.product_uom_id) / self.bom_id.product_qty - boms, lines = self.bom_id.explode(self.product_id, factor, picking_type=self.bom_id.picking_type_id) - for bom_line, line_data in lines: - moves.append(self._get_move_raw_values(bom_line, line_data)) + for production in self: + factor = production.product_uom_id._compute_quantity(production.product_qty, production.bom_id.product_uom_id) / production.bom_id.product_qty + boms, lines = production.bom_id.explode(production.product_id, factor, picking_type=production.bom_id.picking_type_id) + for bom_line, line_data in lines: + moves.append(production._get_move_raw_values(bom_line, line_data)) return moves def _get_move_raw_values(self, bom_line, line_data): diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index 8beba4a3f0f..4efbb4464ce 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -44,10 +44,10 @@ class StockRule(models.Model): for company_id, productions_values in productions_values_by_company.items(): # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) productions = self.env['mrp.production'].sudo().with_context(force_company=company_id).create(productions_values) + self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) + productions.action_confirm() for production in productions: - self.env['stock.move'].sudo().create(production._get_moves_raw_values()) - production.action_confirm() origin_production = production.move_dest_ids and production.move_dest_ids[0].raw_material_production_id or False orderpoint = production.orderpoint_id if orderpoint: