[FIX] stock_account: prevent error if warehouse location not found.

An error occurs when the user attempts to access a forecast report for the
replenishment product but does not receive the warehouse location ID
(archive/delete).

Steps to reproduce: (without demo data)
- Install "stock_account"  module
- Inventory -> Operation -> Procurement -> Replenishment
- Create a new Replenishment product
- Configuration -> warehouse -> Archive warehouse records
- Go to a product made in the replenishment and click on forecast report

Traceback : "IndexError
list index out of range"

This commit will help to open a forecast report if the warehouse location is not
found.

sentry-4998176742

closes odoo/odoo#158017

Signed-off-by: Adrien Widart (awt) <awt@odoo.com>
This commit is contained in:
aamo-odoo
2024-03-19 09:24:21 +00:00
parent 2176cadebd
commit 49bec71d12
@@ -11,7 +11,7 @@ class StockForecasted(models.AbstractModel):
def _get_report_header(self, product_template_ids, product_ids, wh_location_ids):
""" Overrides to computes the valuations of the stock. """
res = super()._get_report_header(product_template_ids, product_ids, wh_location_ids)
if not self.user_has_groups('stock.group_stock_manager'):
if not self.user_has_groups('stock.group_stock_manager') or not wh_location_ids:
return res
domain = self._product_domain(product_template_ids, product_ids)
company = self.env['stock.location'].browse(wh_location_ids[0]).company_id