[FIX] mrp: display correct quantity following production warehouse

Steps to reproduce:
- Enable multi-warehouse
- Add different quantities for a component on two different warehouse
- Create a MO on each warehouse using that component
- Open Overview for each MO

Issue:
Both Overview display the sum of both warehouses quantities in "Free to
use / On Hand" column, which is incorrect.

By forcing the context to contain the warehouse_id, the quantities
fetched on the products will correspond to the quantities in each
warehouses.
Note: It's necessary to update the context of the fetched production as
most computation is done from this record, and its own context isn't
modified by the addition of `warehouse` to the context of `self`.

Task-3251506

Part-of: odoo/odoo#114536
This commit is contained in:
clesgow
2023-10-20 14:59:09 +00:00
parent 9fb0409e6d
commit ea6b120524
@@ -52,6 +52,9 @@ class ReportMoOverview(models.AbstractModel):
def _get_report_data(self, production_id):
production = self.env['mrp.production'].browse(production_id)
# Necessary to fetch the right quantities for multi-warehouse
production = production.with_context(warehouse=production.warehouse_id.id)
components = self._get_components_data(production, level=1, current_index='')
operations = self._get_operations_data(production, level=1, current_index='')
initial_mo_cost = sum(component.get('summary', {}).get('mo_cost', 0.0) for component in components)\