From 2541db92f05223d03acfb2826521feb1843752f0 Mon Sep 17 00:00:00 2001 From: sbbaro Date: Wed, 27 Feb 2019 13:14:04 +0000 Subject: [PATCH] [FIX] purchase: ameliorate the performance of _create_stock_moves When confirming purchase orders with a lot of lines the performance is very slow (sometimes reaches the memory limit). Creating the stock moves in only a multiple create ameliorates the performance. opw 1929276 closes odoo/odoo#31471 --- addons/purchase_stock/models/purchase.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 5d923719ebb..b14a2d8073c 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -347,12 +347,11 @@ class PurchaseOrderLine(models.Model): @api.multi def _create_stock_moves(self, picking): - moves = self.env['stock.move'] - done = self.env['stock.move'].browse() + values = [] for line in self: for val in line._prepare_stock_moves(picking): - done += moves.create(val) - return done + values.append(val) + return self.env['stock.move'].create(values) def _update_received_qty(self): for line in self: