From 8f4b86bf82a1b8af247d6e0d1fb81fc0f52ff010 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 27 Apr 2023 09:12:31 +0000 Subject: [PATCH] [FIX] stock: allow "Print" of MRP reception report During the OWL refactoring of the reception report, the "Print" button was hardcoded to only work for pickings. Unfortunately this means the button did NOT work when the report was opened for a MO. This is due to the report printing being dependent on the report's context values which can either be `default_picking_ids` or `default_production_ids` (and this is by design to avoid additional file extensions to handle both cases). When this button was used in the previous legacy_web_report's client_action, the entire action's context + data used to be passed as part of the Print action: https://github.com/odoo/odoo/blob/30fcb2e60fed17a473353b21bac4916e9ab77b10/addons/stock/static/src/legacy_web_report/client_action.js#L109-L119 The `data` and `context` is then stringified and added into the reportURL: https://github.com/odoo/odoo/blob/30fcb2e60fed17a473353b21bac4916e9ab77b10/addons/web/static/src/webclient/actions/action_service.js#L1042-L1050 But passing of the data isn't necessary in this case, and most of the context's content is not needed since the backend is still receiving + apply the current user's context thanks to the action_service: https://github.com/odoo/odoo/blob/30fcb2e60fed17a473353b21bac4916e9ab77b10/addons/web/static/src/webclient/actions/action_service.js#L1079 always providing it to the backend https://github.com/odoo/odoo/blob/30fcb2e60fed17a473353b21bac4916e9ab77b10/addons/web/controllers/report.py#L87 Therefore, to avoid an extra long report URL of all of the report's data/context, this fix has been designed to capture only the necessary context value and manually build the print URL accordingly. Noticed during task: 3046178 closes odoo/odoo#120935 X-original-commit: 5d66b73cddce1aae2c52f0a0ec8f9885be67b7ae Signed-off-by: Steve Van Essche Signed-off-by: Tiffany Chang --- .../reception_report_main/stock_reception_report_main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/stock/static/src/components/reception_report_main/stock_reception_report_main.js b/addons/stock/static/src/components/reception_report_main/stock_reception_report_main.js index ba87ce877eb..d017274736a 100644 --- a/addons/stock/static/src/components/reception_report_main/stock_reception_report_main.js +++ b/addons/stock/static/src/components/reception_report_main/stock_reception_report_main.js @@ -16,6 +16,8 @@ export class ReceptionReportMain extends Component { this.ormService = useService("orm"); this.actionService = useService("action"); this.reportName = "stock.report_reception"; + const defaultDocIds = Object.entries(this.context).find(([k,v]) => k.startsWith("default_")); + this.contextDefaultDoc = { field: defaultDocIds[0], ids: defaultDocIds[1] }; this.state = useState({ sourcesToLines: {}, }); @@ -29,7 +31,7 @@ export class ReceptionReportMain extends Component { async getReportData() { const args = [ - this.context.default_picking_ids, + this.contextDefaultDoc.ids, { context: this.context, report_type: "html" }, ]; return this.ormService.call( @@ -78,7 +80,7 @@ export class ReceptionReportMain extends Component { return this.actionService.doAction({ type: "ir.actions.report", report_type: "qweb-pdf", - report_name: `${this.reportName}/${this.context.default_picking_ids.join(",")}`, + report_name: `${this.reportName}/?context={"${this.contextDefaultDoc.field}": ${JSON.stringify(this.contextDefaultDoc.ids)}}`, report_file: this.reportName, }); }