mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[MIG] base_report_to_printer: Finish migration to 15.0
This commit is contained in:
@@ -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);
|
||||
@@ -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]);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user