diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index be287f1..61af227 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -28,7 +28,7 @@ ], "assets": { "web.assets_backend": [ - "/base_report_to_printer/static/src/js/qweb_action_manager.js", + "/base_report_to_printer/static/src/js/qweb_action_manager.esm.js", ], }, "installable": True, diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 9ff6204..1878344 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -4,10 +4,9 @@ # Copyright (C) 2011 Domsense srl () # Copyright (C) 2013-2014 Camptocamp () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import time from odoo import _, api, exceptions, fields, models -from odoo.tools import safe_eval +from odoo.tools.safe_eval import safe_eval, time class IrActionsReport(models.Model): diff --git a/base_report_to_printer/models/res_users.py b/base_report_to_printer/models/res_users.py index c7e1c31..cb088ed 100644 --- a/base_report_to_printer/models/res_users.py +++ b/base_report_to_printer/models/res_users.py @@ -24,11 +24,16 @@ class ResUsers(models.Model): comodel_name="printing.printer", string="Default Printer" ) - @api.model - def _register_hook(self): - super()._register_hook() - self.SELF_WRITEABLE_FIELDS.extend(["printing_action", "printing_printer_id"]) - self.SELF_READABLE_FIELDS.extend(["printing_action", "printing_printer_id"]) + @property + def SELF_READABLE_FIELDS(self): + return super().SELF_READABLE_FIELDS + ["printing_action", "printing_printer_id"] + + @property + def SELF_WRITEABLE_FIELDS(self): + return super().SELF_WRITEABLE_FIELDS + [ + "printing_action", + "printing_printer_id", + ] printer_tray_id = fields.Many2one( comodel_name="printing.tray", diff --git a/base_report_to_printer/readme/CONTRIBUTORS.rst b/base_report_to_printer/readme/CONTRIBUTORS.rst index 75647ea..7085b17 100644 --- a/base_report_to_printer/readme/CONTRIBUTORS.rst +++ b/base_report_to_printer/readme/CONTRIBUTORS.rst @@ -11,3 +11,4 @@ * Graeme Gellatly * Rod Schouteden * Alexandre Fayolle +* Matias Peralta diff --git a/base_report_to_printer/static/src/js/qweb_action_manager.esm.js b/base_report_to_printer/static/src/js/qweb_action_manager.esm.js new file mode 100644 index 0000000..f3216cb --- /dev/null +++ b/base_report_to_printer/static/src/js/qweb_action_manager.esm.js @@ -0,0 +1,31 @@ +/** @odoo-module */ +import {registry} from "@web/core/registry"; + +async function cupsReportActionHandler(action, options, env) { + if (action.report_type === "qweb-pdf") { + const orm = env.services.orm; + + const print_action = await orm.call( + "ir.actions.report", + "print_action_for_report_name", + [action.report_name] + ); + if (print_action && print_action.action === "server") { + const result = await orm.call("ir.actions.report", "print_document", [ + action.id, + action.context.active_ids, + action.data, + ]); + if (result) { + env.services.notification.add(env._t("Successfully sent to printer!")); + } else { + env.services.notification.add(env._t("Could not sent to printer!")); + } + return true; + } + } +} + +registry + .category("ir.actions.report handlers") + .add("cups_report_action_handler", cupsReportActionHandler); diff --git a/base_report_to_printer/static/src/js/qweb_action_manager.js b/base_report_to_printer/static/src/js/qweb_action_manager.js deleted file mode 100644 index 0113bc8..0000000 --- a/base_report_to_printer/static/src/js/qweb_action_manager.js +++ /dev/null @@ -1,57 +0,0 @@ -odoo.define("base_report_to_printer.print", function (require) { - "use strict"; - - var ActionManager = require("web.ActionManager"); - var core = require("web.core"); - var _t = core._t; - - ActionManager.include({ - _triggerDownload: function (action, options, type) { - var self = this; - var _super = this._super; - if (type === "pdf") { - this._rpc({ - model: "ir.actions.report", - method: "print_action_for_report_name", - args: [action.report_name], - }).then(function (print_action) { - if (print_action && print_action.action === "server") { - self._rpc({ - model: "ir.actions.report", - method: "print_document", - args: [action.id, action.context.active_ids], - kwargs: {data: action.data || {}}, - context: action.context || {}, - }).then( - function () { - self.do_notify( - _t("Report"), - _.str.sprintf( - _t("Document sent to the printer %s"), - print_action.printer_name - ) - ); - }, - function () { - self.do_notify( - _t("Report"), - _.str.sprintf( - _t( - "Error when sending the document " + - "to the printer " - ), - print_action.printer_name - ) - ); - } - ); - } else { - return _super.apply(self, [action, options, type]); - } - }); - } else { - return _super.apply(self, [action, options, type]); - } - }, - }); -});