[FIX] stock: fix performance of forecasted when lot of locations

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 <Whenrow@users.noreply.github.com>
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
This commit is contained in:
Rémy Voet (ryv)
2020-12-15 10:57:04 +00:00
parent 4816c7bf03
commit 47069ef023
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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:
@@ -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: