From 298ccf560a8e60ba76d58ec4ede77e3ad353bf5b Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Fri, 16 Oct 2020 07:00:30 +0000 Subject: [PATCH] [FIX] stock: refresh forecast report Before this commit, refresh the forecast report can lead to error if this report refer to a product variant (`product.product`). As it lost to which model the report is supposed to refer, it take the one by default (`product.template`) which can lead to error (display a traceback if the ID doesn't exist or display the report for another product if the ID exists). How to reproduce: Open the Forecasted Report for a `product.product` (from the stat button or from the `sale.order.line` widget for example) then refresh the page. task-2362313 issue #59924 closes odoo/odoo#62668 X-original-commit: 5b07432af890794742697641a593fc649630316f Signed-off-by: William Henrotin --- addons/stock/static/src/js/report_stock_forecasted.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/stock/static/src/js/report_stock_forecasted.js b/addons/stock/static/src/js/report_stock_forecasted.js index 4ad8bff2710..df2ff1a02bf 100644 --- a/addons/stock/static/src/js/report_stock_forecasted.js +++ b/addons/stock/static/src/js/report_stock_forecasted.js @@ -28,7 +28,7 @@ const ReplenishReport = clientAction.extend({ this._super.apply(this, arguments); this.context = action.context; this.productId = this.context.active_id; - this.resModel = this.context.active_model || 'product.template'; + this.resModel = this.context.active_model || this.context.params.active_model || 'product.template'; const isTemplate = this.resModel === 'product.template'; this.actionMethod = `action_product_${isTemplate ? 'tmpl_' : ''}forecast_report`; const reportName = `report_product_${isTemplate ? 'template' : 'product'}_replenishment`; @@ -81,6 +81,11 @@ const ReplenishReport = clientAction.extend({ in_DOM: true, callbacks: [{ widget: graphController }], }); + // Hack to put the res_model on the url. This way, the report always know on with res_model it refers. + if (location.href.indexOf('active_model') === -1) { + const url = window.location.href + `&active_model=${this.resModel}`; + window.history.pushState({}, "", url); + } }, /**