[ADD] app report_pdf_options

pull/432/head
Kuzey Aydın 1 year ago
parent 077a1808a2
commit f1ff947a69

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
#
from . import models

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
{
'name': 'Pdf report options',
'summary': """shows a modal window with options for printing, downloading or opening pdf reports""",
'description': """
Choose one of the following options when printing a pdf report:
- print. print the pdf report directly with the browser
- download. download the pdf report on your computer
- open. open the pdf report in a new tab
You can also set a default options for each report
""",
'author': 'Luis Rodrigo Mejia Mateus',
'category': 'Productivity',
'images': ['images/main_1.png', 'images/main_screenshot.png'],
'depends': ['web'],
'data': [
'views/ir_actions_report.xml',
],
'installable': True,
'auto_install': False,
'license': 'LGPL-3',
'assets': {
'web.assets_backend': [
'report_pdf_options/static/src/js/PdfOptionsModal.js',
'report_pdf_options/static/src/js/qwebactionmanager.js',
'report_pdf_options/static/src/**/*.xml'
]
}
}

@ -0,0 +1,87 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * report_pdf_options
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-18 04:38+0000\n"
"PO-Revision-Date: 2021-09-17 23:44-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"Language: es_PE\n"
"X-Generator: Poedit 3.0\n"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/js/qwebactionmanager.js:0
#, python-format
msgid "Close"
msgstr "Cerrar"
#. module: report_pdf_options
#: model:ir.model.fields,field_description:report_pdf_options.field_ir_actions_report__default_print_option
msgid "Default printing option"
msgstr "Opción de impresión por defecto"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/xml/report_pdf_options.xml:0
#: model:ir.model.fields.selection,name:report_pdf_options.selection__ir_actions_report__default_print_option__download
#, python-format
msgid "Download"
msgstr "Descargar"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/xml/report_pdf_options.xml:0
#: model:ir.model.fields.selection,name:report_pdf_options.selection__ir_actions_report__default_print_option__open
#, python-format
msgid "Open"
msgstr "Abrir"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/xml/report_pdf_options.xml:0
#: model:ir.model.fields.selection,name:report_pdf_options.selection__ir_actions_report__default_print_option__print
#, python-format
msgid "Print"
msgstr "Imprimir"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/js/qwebactionmanager.js:0
#, python-format
msgid "Report"
msgstr "Reporte"
#. module: report_pdf_options
#: model:ir.model,name:report_pdf_options.model_ir_actions_report
msgid "Report Action"
msgstr "Acción de informe"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/js/qwebactionmanager.js:0
#, python-format
msgid "What do you want to do?"
msgstr "Que acción quiere ejecutar?"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/xml/report_pdf_options.xml:0
#, python-format
msgid "report"
msgstr "reporte"
#. module: report_pdf_options
#. openerp-web
#: code:addons/report_pdf_options/static/src/xml/report_pdf_options.xml:0
#, python-format
msgid "set a default option for this"
msgstr "Establecer una opción por defecto para este"

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

@ -0,0 +1 @@
from . import ir_actions

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
class IrActionsReportXml(models.Model):
_inherit = 'ir.actions.report'
default_print_option = fields.Selection(selection=[
('print', 'Print'),
('download', 'Download'),
('open', 'Open')
], string='Default printing option')
def _get_readable_fields(self):
data = super()._get_readable_fields()
data.add('default_print_option')
return data
def report_action(self, docids, data=None, config=True):
data = super(IrActionsReportXml, self).report_action(docids, data, config)
data['id'] = self.id
data['default_print_option'] = self.default_print_option
return data

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

@ -0,0 +1,41 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Report Print Options</h2>
<h3 class="oe_slogan">Report direct print, download or open in new tab</h3>
</div>
<div class="oe_span12">
<div class="oe_demo oe_pictue oe_screenshot">
<img src="printoptions.gif">
</div>
<div class="oe_demo oe_pictue oe_screenshot">
<img src="printoptions2.gif">
</div>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Report Print Configuration</h2>
<h3 class="oe_slogan">Set an option to perform by default</h3>
</div>
<div class="oe_span12">
<div class="oe_demo oe_pictue oe_screenshot">
<img src="setupoptions.gif">
</div>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">The default option is executed</h2>
</div>
<div class="oe_span12">
<div class="oe_demo oe_pictue oe_screenshot">
<img src="defaultoption.gif">
</div>
</div>
</div>
</section>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

@ -0,0 +1,17 @@
/** @odoo-module */
import { _t } from "@web/core/l10n/translation";
import { Dialog } from "@web/core/dialog/dialog";
import { Component } from "@odoo/owl";
export class PdfOptionsModal extends Component {
setup() {
this.title = _t("What do you want to do?");
}
executePdfAction(option) {
this.props.onSelectOption(option);
}
}
PdfOptionsModal.template = "report_pdf_options.ButtonOptions";
PdfOptionsModal.components = { Dialog };

@ -0,0 +1,133 @@
/** @odoo-module **/
import { _t } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { PdfOptionsModal } from "./PdfOptionsModal";
function getWKHTMLTOPDF_MESSAGES(status) {
const link = '<br><br><a href="http://wkhtmltopdf.org/" target="_blank">wkhtmltopdf.org</a>'; // FIXME missing markup
const _status = {
broken:
_t(
"Your installation of Wkhtmltopdf seems to be broken. The report will be shown in html."
) + link,
install:
_t("Unable to find Wkhtmltopdf on this system. The report will be shown in html.") +
link,
upgrade:
_t(
"You should upgrade your version of Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as support for table-breaking between pages."
) + link,
workers: _t(
"You need to start Odoo with at least two workers to print a pdf version of the reports."
),
};
return _status[status];
}
let iframeForReport;
function printPdf(url, callback) {
let iframe = iframeForReport;
if (!iframe) {
iframe = iframeForReport = document.createElement('iframe');
iframe.className = 'pdfIframe'
document.body.appendChild(iframe);
iframe.style.display = 'none';
iframe.onload = function () {
setTimeout(function () {
iframe.focus();
iframe.contentWindow.print();
URL.revokeObjectURL(url)
callback();
}, 1);
};
}
iframe.src = url;
}
function getReportUrl(action, type) {
let url = `/report/${type}/${action.report_name}`;
const actionContext = action.context || {};
if (action.data && JSON.stringify(action.data) !== "{}") {
// build a query string with `action.data` (it's the place where reports
// using a wizard to customize the output traditionally put their options)
const options = encodeURIComponent(JSON.stringify(action.data));
const context = encodeURIComponent(JSON.stringify(actionContext));
url += `?options=${options}&context=${context}`;
} else {
if (actionContext.active_ids) {
url += `/${actionContext.active_ids.join(",")}`;
}
if (type === "html") {
const context = encodeURIComponent(JSON.stringify(env.services.user.context));
url += `?context=${context}`;
}
}
return url;
}
let wkhtmltopdfStateProm;
registry
.category("ir.actions.report handlers")
.add("pdf_report_options_handler", async function (action, options, env) {
let { default_print_option, report_type } = action;
if (report_type !== "qweb-pdf" || default_print_option === "download")
return false;
if (!default_print_option) {
let removeDialog;
default_print_option = await new Promise(resolve => {
removeDialog = env.services.dialog.add(
PdfOptionsModal,
{
onSelectOption: (option) => {
return resolve(option);
}
},
{
onClose: () => {
resolve("close");
}
}
);
});
removeDialog();
if (default_print_option === "close")
return true;
if (default_print_option === "download")
return false;
}
// check the state of wkhtmltopdf before proceeding
if (!wkhtmltopdfStateProm) {
wkhtmltopdfStateProm = await env.services.rpc("/report/check_wkhtmltopdf");
}
const state = wkhtmltopdfStateProm;
// display a notification according to wkhtmltopdf's state
const message = getWKHTMLTOPDF_MESSAGES(state)
if (message) {
env.services.notification.add(message, {
sticky: true,
title: _t("Report"),
});
}
if (["upgrade", "ok"].includes(state)) {
// trigger the download of the PDF report
//return _triggerDownload(action, options, "pdf");
const url = getReportUrl(action, "pdf");
if (default_print_option === "print") {
env.services.ui.block();
printPdf(url, () => {
env.services.ui.unblock();
});
}
if (default_print_option === "open") {
window.open(url);
}
return true;
} else {
// open the report in the client action if generating the PDF is not possible
return _executeReportClientAction(action, options);
}
})

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<templates xml:space="preserve">
<t t-name="report_pdf_options.ButtonOptions">
<Dialog size="'sm'" title="title">
<div style="text-align:center;">
<div class="btn-group" role="group">
<button class="btn btn-info" t-on-click="() => this.executePdfAction('print')">
<i class="fa fa-print me-2"/>
<span>Print</span>
</button>
<button class="btn btn-info" t-on-click="() => this.executePdfAction('download')">
<i class="fa fa-download me-2"/>
<span>Download</span>
</button>
<button class="btn btn-info" t-on-click="() => this.executePdfAction('open')">
<i class="fa fa-file-text me-2"/>
<span>Open</span>
</button>
</div>
</div>
</Dialog>
</t>
</templates>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="act_report_view_inherit" model="ir.ui.view">
<field name="name">ir.actions.report.inherit</field>
<field name="model">ir.actions.report</field>
<field name="inherit_id" ref="base.act_report_xml_view"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='advanced']" position="inside">
<group>
<field name="default_print_option" invisible="report_type != 'qweb-pdf'"/>
</group>
</xpath>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save