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:
@@ -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,
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
|
||||
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
|
||||
# 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):
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
* Graeme Gellatly <graeme@o4sb.com>
|
||||
* Rod Schouteden <rod@schout-it.be>
|
||||
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
|
||||
* Matias Peralta <mnp@adhoc.com.ar>
|
||||
|
||||
@@ -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