diff --git a/odex30_base/report_pdf_options/__init__.py b/odex30_base/report_pdf_options/__init__.py new file mode 100644 index 0000000..027f7d8 --- /dev/null +++ b/odex30_base/report_pdf_options/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# +from . import models diff --git a/odex30_base/report_pdf_options/__manifest__.py b/odex30_base/report_pdf_options/__manifest__.py new file mode 100644 index 0000000..a4f998a --- /dev/null +++ b/odex30_base/report_pdf_options/__manifest__.py @@ -0,0 +1,21 @@ +{ + 'name': 'Pdf report options', + 'version': '18.0.1.0.0', # تحديث الإصدار + 'summary': """shows a modal window with options for printing, downloading or opening pdf reports""", + 'description': """...""", + 'author': 'Luis Rodrigo Mejia Mateus, Odoo SA', + 'category': 'Odex30-Base', + 'images': ['images/main_1.png', 'images/main_screenshot.png'], + 'depends': ['web'], + 'data': [ + 'views/ir_actions_report.xml', + ], + 'assets': { + 'web.assets_backend': [ + 'report_pdf_options/static/src/js/qwebactionmanager.js', + ], + }, + 'installable': True, + 'auto_install': False, + 'license': 'LGPL-3' +} diff --git a/odex30_base/report_pdf_options/i18n/es_PE.po b/odex30_base/report_pdf_options/i18n/es_PE.po new file mode 100644 index 0000000..1057b73 --- /dev/null +++ b/odex30_base/report_pdf_options/i18n/es_PE.po @@ -0,0 +1,69 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * print_attachment_options +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-05-29 02:35+0000\n" +"PO-Revision-Date: 2019-05-28 21:41-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 2.2.3\n" + +#. module: print_attachment_options +#. openerp-web +#: code:addons/print_attachment_options/static/src/js/qwebactionmanager.js:134 +#, python-format +msgid "Close" +msgstr "Cerrar" + +#. module: print_attachment_options +#: model:ir.model.fields,field_description:print_attachment_options.field_ir_act_report_xml_default_print_option +msgid "Default printing option" +msgstr "Opción de impresión predeterminada" + +#. module: print_attachment_options +#. openerp-web +#: code:addons/print_attachment_options/static/src/xml/print_attachment_options.xml:12 +#: selection:ir.actions.report.xml,default_print_option:0 +#, python-format +msgid "Download" +msgstr "Descargar" + +#. module: print_attachment_options +#. openerp-web +#: code:addons/print_attachment_options/static/src/xml/print_attachment_options.xml:16 +#: selection:ir.actions.report.xml,default_print_option:0 +#, python-format +msgid "Open" +msgstr "Abrir" + +#. module: print_attachment_options +#. openerp-web +#: code:addons/print_attachment_options/static/src/xml/print_attachment_options.xml:8 +#: selection:ir.actions.report.xml,default_print_option:0 +#, python-format +msgid "Print" +msgstr "Imprimir" + +#. module: print_attachment_options +#. openerp-web +#: code:addons/print_attachment_options/static/src/js/qwebactionmanager.js:96 +#, python-format +msgid "Report" +msgstr "Reporte" + +#. module: print_attachment_options +#. openerp-web +#: code:addons/print_attachment_options/static/src/js/qwebactionmanager.js:131 +#, python-format +msgid "What do you want to do?" +msgstr "¿Qué quieres hacer?" + diff --git a/odex30_base/report_pdf_options/images/main_1.png b/odex30_base/report_pdf_options/images/main_1.png new file mode 100644 index 0000000..81a7c63 Binary files /dev/null and b/odex30_base/report_pdf_options/images/main_1.png differ diff --git a/odex30_base/report_pdf_options/images/main_screenshot.png b/odex30_base/report_pdf_options/images/main_screenshot.png new file mode 100644 index 0000000..2d270c2 Binary files /dev/null and b/odex30_base/report_pdf_options/images/main_screenshot.png differ diff --git a/odex30_base/report_pdf_options/models/__init__.py b/odex30_base/report_pdf_options/models/__init__.py new file mode 100644 index 0000000..bdf49f6 --- /dev/null +++ b/odex30_base/report_pdf_options/models/__init__.py @@ -0,0 +1 @@ +from . import ir_actions \ No newline at end of file diff --git a/odex30_base/report_pdf_options/models/ir_actions.py b/odex30_base/report_pdf_options/models/ir_actions.py new file mode 100644 index 0000000..cba40c6 --- /dev/null +++ b/odex30_base/report_pdf_options/models/ir_actions.py @@ -0,0 +1,13 @@ +# -*- 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') diff --git a/odex30_base/report_pdf_options/static/description/defaultoption.gif b/odex30_base/report_pdf_options/static/description/defaultoption.gif new file mode 100644 index 0000000..5a81248 Binary files /dev/null and b/odex30_base/report_pdf_options/static/description/defaultoption.gif differ diff --git a/odex30_base/report_pdf_options/static/description/index.html b/odex30_base/report_pdf_options/static/description/index.html new file mode 100644 index 0000000..8d2bfe5 --- /dev/null +++ b/odex30_base/report_pdf_options/static/description/index.html @@ -0,0 +1,41 @@ +
+
+
+

Report Print Options

+

Report direct print, download or open in new tab

+
+
+
+ +
+
+ +
+
+
+
+
+
+
+

Report Print Configuration

+

Set an option to perform by default

+
+
+
+ +
+
+
+
+
+
+
+

The default option is executed

+
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/odex30_base/report_pdf_options/static/description/printoptions.gif b/odex30_base/report_pdf_options/static/description/printoptions.gif new file mode 100644 index 0000000..bb1ed38 Binary files /dev/null and b/odex30_base/report_pdf_options/static/description/printoptions.gif differ diff --git a/odex30_base/report_pdf_options/static/description/printoptions2.gif b/odex30_base/report_pdf_options/static/description/printoptions2.gif new file mode 100644 index 0000000..5267dd4 Binary files /dev/null and b/odex30_base/report_pdf_options/static/description/printoptions2.gif differ diff --git a/odex30_base/report_pdf_options/static/description/setupoptions.gif b/odex30_base/report_pdf_options/static/description/setupoptions.gif new file mode 100644 index 0000000..a6a616b Binary files /dev/null and b/odex30_base/report_pdf_options/static/description/setupoptions.gif differ diff --git a/odex30_base/report_pdf_options/static/src/js/qwebactionmanager.js b/odex30_base/report_pdf_options/static/src/js/qwebactionmanager.js new file mode 100644 index 0000000..4ecd3b9 --- /dev/null +++ b/odex30_base/report_pdf_options/static/src/js/qwebactionmanager.js @@ -0,0 +1,103 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { Dialog } from "@web/core/dialog/dialog"; +import { Component, xml } from "@odoo/owl"; +import * as reportUtils from "@web/webclient/actions/reports/utils"; +import { rpc } from "@web/core/network/rpc"; + +class ReportOptionDialog extends Component { + static template = xml` + +
+
+ + + +
+
+ + + +
+ `; + static components = { Dialog }; + + onButtonClick(option) { + this.props.onSelect(option); + this.props.close(); + } +} + +const pdfOptionsHandler = async (action, options, env) => { + if (action.report_type !== 'qweb-pdf' || (options && options.download === false)) { + return false; + } + + const dialogService = env.services.dialog; + const notification = env.services.notification; + const { getReportUrl, downloadReport } = reportUtils; + + const userContext = env.services.user?.context || {}; + + const status = await rpc("/report/check_wkhtmltopdf"); + + if (status === 'install' || status === 'broken') { + notification.add(env._t("Wkhtmltopdf is not properly installed."), { type: 'warning' }); + } else if (status === 'upgrade') { + notification.add(env._t("For better reports, you should upgrade wkhtmltopdf."), { type: 'info' }); + } + + if (!["upgrade", "ok"].includes(status)) { + env.services.action.doAction(action, { additionalContext: { html_report: true } }); + return true; + } + + if (action.default_print_option) { + if (action.default_print_option === 'print') { + const url = getReportUrl(action, 'html', userContext); + + } else { + downloadReport(rpc, action, 'pdf', userContext); + } + return true; + } + + return new Promise((resolve) => { + const onSelect = (option) => { + if (option === 'print') { + const url = getReportUrl(action, 'html', userContext); + const printIframe = document.createElement("iframe"); + printIframe.style.display = "none"; + document.body.appendChild(printIframe); + printIframe.onload = () => { + printIframe.contentWindow.print(); + setTimeout(() => document.body.removeChild(printIframe), 1000); + }; + printIframe.src = url; + } else if (option === 'open') { + const url = getReportUrl(action, 'pdf', userContext); + window.open(url, '_blank'); + } else { + downloadReport(rpc, action, 'pdf', userContext); + } + resolve(true); + }; + + dialogService.add(ReportOptionDialog, { + onSelect: onSelect, + onClose: () => resolve(true), + }); + }); +}; + +registry.category("ir.actions.report handlers").add("pdf_options_handler", pdfOptionsHandler, { sequence: 1 }); diff --git a/odex30_base/report_pdf_options/views/ir_actions_report.xml b/odex30_base/report_pdf_options/views/ir_actions_report.xml new file mode 100644 index 0000000..70923d5 --- /dev/null +++ b/odex30_base/report_pdf_options/views/ir_actions_report.xml @@ -0,0 +1,17 @@ + + + + + ir.actions.report.inherit + ir.actions.report + + + + + + + + + + + \ No newline at end of file