[MIG] base_report_to_printer: Finish migration to 15.0

This commit is contained in:
matiasperalta1
2022-08-25 11:11:14 -03:00
parent 9384082e96
commit c2bf59d2e8
6 changed files with 44 additions and 65 deletions

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