[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.
This commit is contained in:
Arnold Moyaux
2019-02-14 10:19:21 +00:00
parent 8c769cb40c
commit b328ddda20
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -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):
+2 -2
View File
@@ -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: