From 47069ef0236bff27ccca2d01a726ed2d0fa7c830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 11 Dec 2020 14:00:03 +0000 Subject: [PATCH] [FIX] stock: fix performance of forecasted when lot of locations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the DB with a warehouse with a lot of stock location. The forecasted widget return a traceback due to a memory error due to the `_get_domain_locations_new` (`_get_report_lines`->`read(['qty_available'])`->`_compute_quantities` ->`_compute_quantities_dict`->`_get_domain_locations`) how returns a extremely long domain (one expression by location in the context) to compute child location. But the locations (put in the context) contain already children locations because of `('id', 'child_of', warehouse.view_location_id.id)`. TO SOLVE Instead of adding location in the context (for fix 1aa6a323e04232d24175593718637c6dac295eb9), add the warehouse in the context before calling the `_get_report_lines` in the `_compute_forecast_information`. closes #61666 closes odoo/odoo#63377 X-original-commit: f8861e6a63fcd85295affdea4b525af753234b14 Signed-off-by: William Henrotin Signed-off-by: Rémy Voet --- addons/stock/models/stock_move.py | 4 ++-- addons/stock/report/report_stock_forecasted.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 363687d6f3d..54b398dae7b 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -431,8 +431,8 @@ class StockMove(models.Model): [('id', 'child_of', warehouse.view_location_id.id)], ['id'], )] - forecast_lines = self.env['report.stock.report_product_product_replenishment']\ - ._get_report_lines(None, product_variant_ids, wh_location_ids) + ForecastedReport = self.env['report.stock.report_product_product_replenishment'] + forecast_lines = ForecastedReport.with_context(warehouse=warehouse.id)._get_report_lines(None, product_variant_ids, wh_location_ids) for move in moves: lines = [l for l in forecast_lines if l["move_out"] == move._origin and l["replenishment_filled"] is True] if lines: diff --git a/addons/stock/report/report_stock_forecasted.py b/addons/stock/report/report_stock_forecasted.py index 88576a58035..47d7be945b1 100644 --- a/addons/stock/report/report_stock_forecasted.py +++ b/addons/stock/report/report_stock_forecasted.py @@ -144,7 +144,7 @@ class ReplenishmentReport(models.AbstractModel): ins_per_product = defaultdict(lambda: []) for in_ in ins: ins_per_product[in_.product_id.id].append([in_.product_qty, in_]) - currents = {c['id']: c['qty_available'] for c in outs.product_id.with_context(location=wh_location_ids).read(['qty_available'])} + currents = {c['id']: c['qty_available'] for c in outs.product_id.read(['qty_available'])} lines = [] for product in (ins | outs).product_id: