[MIG] base_report_to_printer: Finish migration to 15.0

This commit is contained in:
matiasperalta1
2022-08-25 11:11:14 -03:00
committed by trisdoan
parent b21121de86
commit f077a8186b
6 changed files with 44 additions and 65 deletions

View File

@@ -28,7 +28,7 @@
], ],
"assets": { "assets": {
"web.assets_backend": [ "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, "installable": True,

View File

@@ -4,10 +4,9 @@
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) # Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>) # Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import time
from odoo import _, api, exceptions, fields, models 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): class IrActionsReport(models.Model):

View File

@@ -24,11 +24,16 @@ class ResUsers(models.Model):
comodel_name="printing.printer", string="Default Printer" comodel_name="printing.printer", string="Default Printer"
) )
@api.model @property
def _register_hook(self): def SELF_READABLE_FIELDS(self):
super()._register_hook() return super().SELF_READABLE_FIELDS + ["printing_action", "printing_printer_id"]
self.SELF_WRITEABLE_FIELDS.extend(["printing_action", "printing_printer_id"])
self.SELF_READABLE_FIELDS.extend(["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( printer_tray_id = fields.Many2one(
comodel_name="printing.tray", comodel_name="printing.tray",

View File

@@ -11,3 +11,4 @@
* Graeme Gellatly <graeme@o4sb.com> * Graeme Gellatly <graeme@o4sb.com>
* Rod Schouteden <rod@schout-it.be> * Rod Schouteden <rod@schout-it.be>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com> * Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
* Matias Peralta <mnp@adhoc.com.ar>

View File

@@ -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);

View File

@@ -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]);
}
},
});
});