diff --git a/report_fillpdf/__manifest__.py b/report_fillpdf/__manifest__.py index 78e061542f..5871aa9af2 100644 --- a/report_fillpdf/__manifest__.py +++ b/report_fillpdf/__manifest__.py @@ -7,13 +7,13 @@ "author": "Creu Blanca," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/reporting-engine", "category": "Reporting", - "version": "11.0.1.0.1", + "version": "14.0.1.0.1", "license": "AGPL-3", "external_dependencies": { "python": [ "fdfgen", ], - "bin": [ + "deb": [ "pdftk", ], }, diff --git a/report_fillpdf/models/ir_report.py b/report_fillpdf/models/ir_report.py index 677bc362ce..8340d416ff 100644 --- a/report_fillpdf/models/ir_report.py +++ b/report_fillpdf/models/ir_report.py @@ -8,7 +8,9 @@ class ReportAction(models.Model): _inherit = "ir.actions.report" - report_type = fields.Selection(selection_add=[("fillpdf", "PDF Filler")]) + report_type = fields.Selection( + selection_add=[("fillpdf", "PDF Filler")], ondelete={"fillpdf": "set default"} + ) @api.model def render_fillpdf(self, docids, data): diff --git a/report_fillpdf/static/src/js/report/action_manager_report.js b/report_fillpdf/static/src/js/report/action_manager_report.js new file mode 100644 index 0000000000..efbc5f891e --- /dev/null +++ b/report_fillpdf/static/src/js/report/action_manager_report.js @@ -0,0 +1,98 @@ +// © 2017 Creu Blanca +// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). +odoo.define("report_fillpdf.report", function (require) { + "use strict"; + + var core = require("web.core"); + var ActionManager = require("web.ActionManager"); + var framework = require("web.framework"); + var session = require("web.session"); + var _t = core._t; + + ActionManager.include({ + _downloadReportfillpdf: function (url, actions) { + var self = this; + framework.blockUI(); + var type = "fillpdf"; + var cloned_action = _.clone(actions); + var new_url = url; + + if ( + _.isUndefined(cloned_action.data) || + _.isNull(cloned_action.data) || + (_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data)) + ) { + if (cloned_action.context.active_ids) { + new_url += "/" + cloned_action.context.active_ids.join(","); + } + } else { + new_url += + "?options=" + + encodeURIComponent(JSON.stringify(cloned_action.data)); + new_url += + "&context=" + + encodeURIComponent(JSON.stringify(cloned_action.context)); + } + + return new Promise(function (resolve, reject) { + var blocked = !session.get_file({ + url: new_url, + data: { + data: JSON.stringify([new_url, type]), + }, + success: resolve, + error: (error) => { + self.call("crash_manager", "rpc_error", error); + reject(); + }, + complete: framework.unblockUI, + }); + if (blocked) { + // AAB: this check should be done in get_file service directly, + // should not be the concern of the caller (and that way, get_file + // could return a deferred) + var message = _t( + "A popup window with your report was blocked. You " + + "may need to change your browser settings to allow " + + "popup windows for this page." + ); + this.do_warn(_t("Warning"), message, true); + } + }); + }, + + _triggerDownload: function (action, options, type) { + var self = this; + var reportUrls = this._makeReportUrls(action); + if (type === "fillpdf") { + return this._downloadReportfillpdf(reportUrls[type], action).then( + function () { + if (action.close_on_report_download) { + var closeAction = {type: "ir.actions.act_window_close"}; + return self.doAction( + closeAction, + _.pick(options, "on_close") + ); + } + return options.on_close(); + } + ); + } + return this._super.apply(this, arguments); + }, + + _makeReportUrls: function (action) { + var reportUrls = this._super.apply(this, arguments); + reportUrls.fillpdf = "/report/fillpdf/" + action.report_name; + return reportUrls; + }, + + _executeReportAction: function (action, options) { + var self = this; + if (action.report_type === "fillpdf") { + return self._triggerDownload(action, options, "fillpdf"); + } + return this._super.apply(this, arguments); + }, + }); +}); diff --git a/report_fillpdf/static/src/js/report/qwebactionmanager.js b/report_fillpdf/static/src/js/report/qwebactionmanager.js deleted file mode 100644 index 176ed4b0f6..0000000000 --- a/report_fillpdf/static/src/js/report/qwebactionmanager.js +++ /dev/null @@ -1,49 +0,0 @@ -// © 2017 Creu Blanca -// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). -odoo.define("report_fillpdf.report", function (require) { - "use strict"; - - var ActionManager = require("web.ActionManager"); - var crash_manager = require("web.crash_manager"); - var framework = require("web.framework"); - - ActionManager.include({ - ir_actions_report: function (action, options) { - var self = this; - var cloned_action = _.clone(action); - if (cloned_action.report_type === "fillpdf") { - framework.blockUI(); - var report_fillpdf_url = "report/fillpdf/" + cloned_action.report_name; - if (cloned_action.context.active_ids) { - report_fillpdf_url += - "/" + cloned_action.context.active_ids.join(","); - } else { - report_fillpdf_url += - "?options=" + - encodeURIComponent(JSON.stringify(cloned_action.data)); - report_fillpdf_url += - "&context=" + - encodeURIComponent(JSON.stringify(cloned_action.context)); - } - self.getSession().get_file({ - url: report_fillpdf_url, - data: { - data: JSON.stringify([ - report_fillpdf_url, - cloned_action.report_type, - ]), - }, - error: crash_manager.rpc_error.bind(crash_manager), - success: function () { - if (cloned_action && options && !cloned_action.dialog) { - options.on_close(); - } - }, - }); - framework.unblockUI(); - return; - } - return self._super(action, options); - }, - }); -}); diff --git a/report_fillpdf/tests/test_report.py b/report_fillpdf/tests/test_report.py index 36601c1b40..5ff16c55b2 100644 --- a/report_fillpdf/tests/test_report.py +++ b/report_fillpdf/tests/test_report.py @@ -11,4 +11,4 @@ def test_report(self): report = report_object._get_report_from_name(report_name) docs = self.env["res.company"].search([], limit=1).partner_id self.assertEqual(report.report_type, "fillpdf") - report.render(docs.ids, {}) + report._render(docs.ids, {}) diff --git a/report_fillpdf/views/webclient_templates.xml b/report_fillpdf/views/webclient_templates.xml index 72050a2701..2fd7f1324e 100644 --- a/report_fillpdf/views/webclient_templates.xml +++ b/report_fillpdf/views/webclient_templates.xml @@ -8,9 +8,8 @@