From 0ad863ba2452a97b25558c905970277be66a7652 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Fri, 3 Mar 2023 12:21:02 +0000 Subject: [PATCH] [FIX] stock: display forecast for the current warehouse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create two warehouses in the same company - Create a storable product “P1”: - Add 10 units in each warehouse - Click on the forecasted widget Problem: The quantity on hand is 20 instead of 10 while the current warehouse set in the filter is "WH1", because the warehouse has not been added in the context, so we calculate all the quantities available in all the locations of the current company: https://github.com/odoo/odoo/blob/c05815ae6b8bd7afceb760395af09c707c89c485/addons/stock/report/stock_forecasted.py#L164 https://github.com/odoo/odoo/blob/3ee5d7a0fbccae5f742e1aba8d3d24f8bab3cbdd/addons/stock/models/product.py#L275 for the filter, the default one is added in the context here: https://github.com/odoo/odoo/blob/16.0/addons/stock/static/src/stock_forecasted/forecasted_warehouse_filter.js#L19 opw-3194872 closes odoo/odoo#115255 X-original-commit: 10ea5d0cfb08b733322d0274e191a20f7f53cd78 Signed-off-by: William Henrotin (whe) --- .../src/stock_forecasted/forecasted_warehouse_filter.js | 9 ++------- .../static/src/stock_forecasted/stock_forecasted.js | 6 ++++++ .../static/src/stock_forecasted/stock_forecasted.xml | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/stock/static/src/stock_forecasted/forecasted_warehouse_filter.js b/addons/stock/static/src/stock_forecasted/forecasted_warehouse_filter.js index 1922b9e2ba7..7d2d5f64d99 100644 --- a/addons/stock/static/src/stock_forecasted/forecasted_warehouse_filter.js +++ b/addons/stock/static/src/stock_forecasted/forecasted_warehouse_filter.js @@ -9,16 +9,11 @@ export class ForecastedWarehouseFilter extends Component { setup() { this.orm = useService("orm"); this.context = this.props.action.context; + this.warehouses = this.props.warehouses; onWillStart(this.onWillStart) } async onWillStart() { - this.warehouses = await this.orm.searchRead('stock.warehouse', [],['id', 'name', 'code']); - - if (!this.context.warehouse) { - this.props.setWarehouseInContext(this.warehouses[0].id); - } - this.displayWarehouseFilter = (this.warehouses.length > 1); } @@ -35,4 +30,4 @@ export class ForecastedWarehouseFilter extends Component { ForecastedWarehouseFilter.template = 'stock.ForecastedWarehouseFilter'; ForecastedWarehouseFilter.components = {Dropdown, DropdownItem}; -ForecastedWarehouseFilter.props = {action: Object, setWarehouseInContext : Function}; +ForecastedWarehouseFilter.props = {action: Object, setWarehouseInContext : Function, warehouses: Array}; diff --git a/addons/stock/static/src/stock_forecasted/stock_forecasted.js b/addons/stock/static/src/stock_forecasted/stock_forecasted.js index 7eed0c255f5..13892f24d44 100644 --- a/addons/stock/static/src/stock_forecasted/stock_forecasted.js +++ b/addons/stock/static/src/stock_forecasted/stock_forecasted.js @@ -26,6 +26,7 @@ export class StockForecasted extends Component { this.context.active_id = this.props.action.params.active_id; this.reloadReport(); } + this.warehouses = useState([]); onWillStart(this._getReportValues); } @@ -34,6 +35,11 @@ export class StockForecasted extends Component { await this._getResModel(); const isTemplate = !this.resModel || this.resModel === 'product.template'; this.reportModelName = `stock.forecasted_product_${isTemplate ? "template" : "product"}`; + this.warehouses.splice(0, this.warehouses.length); + this.warehouses.push(...await this.orm.searchRead('stock.warehouse', [],['id', 'name', 'code'])); + if (!this.context.warehouse) { + this.updateWarehouse(this.warehouses[0].id); + } const reportValues = await this.orm.call(this.reportModelName, "get_report_values", [], { context: this.context, docids: [this.productId], diff --git a/addons/stock/static/src/stock_forecasted/stock_forecasted.xml b/addons/stock/static/src/stock_forecasted/stock_forecasted.xml index 0be6e766d00..1651474cd2a 100644 --- a/addons/stock/static/src/stock_forecasted/stock_forecasted.xml +++ b/addons/stock/static/src/stock_forecasted/stock_forecasted.xml @@ -7,7 +7,7 @@