From 8835b3fe7aebbcc2a239e6f2394dee02ed7c1bf2 Mon Sep 17 00:00:00 2001 From: "Simon Genin (ges)" Date: Wed, 29 Mar 2023 09:21:51 +0000 Subject: [PATCH] [IMP] web: export download file function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, there is a download function exported that expects data and a url. You would provide a controller url and some data to send, and the result would be downloaded. However, it may be useful to sometimes trigger a download on the spot if there is no need to reach for a controller. Like having some json data and download it. The code already existed, so this function is now exported as `downloadFile`. closes odoo/odoo#118227 X-original-commit: cd9a5d491715247636d95c9f768ffc42616f4b47 Related: odoo/enterprise#39564 Signed-off-by: Lucas Lefèvre (lul) --- .../web/static/src/core/network/download.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/core/network/download.js b/addons/web/static/src/core/network/download.js index 3a8c5d5dcaf..ea79ab19462 100644 --- a/addons/web/static/src/core/network/download.js +++ b/addons/web/static/src/core/network/download.js @@ -446,11 +446,30 @@ function _download(data, filename, mimetype) { /* eslint-enable */ // ----------------------------------------------------------------------------- -// Exported download function +// Exported download functions // ----------------------------------------------------------------------------- /** - * Download a file + * Download data as a file + * + * @param {Object} data + * @param {String} filename + * @param {String} mimetype + * @returns {Boolean} + * + * Note: the actual implementation is certainly unconventional, but sadly + * necessary to be able to test code using the download function + */ +export function downloadFile(data, filename, mimetype) { + return downloadFile._download(data, filename, mimetype) +} +downloadFile._download = _download; + +/** + * Download a file from form or server url + * + * This function is meant to call a controller with some data + * and download the response. * * Note: the actual implementation is certainly unconventional, but sadly * necessary to be able to test code using the download function