diff --git a/report_pdf_options/__init__.py b/report_pdf_options/__init__.py new file mode 100644 index 000000000..027f7d8a8 --- /dev/null +++ b/report_pdf_options/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# +from . import models diff --git a/report_pdf_options/__manifest__.py b/report_pdf_options/__manifest__.py new file mode 100644 index 000000000..9e23905c5 --- /dev/null +++ b/report_pdf_options/__manifest__.py @@ -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' + ] + } +} diff --git a/report_pdf_options/i18n/es_PE.po b/report_pdf_options/i18n/es_PE.po new file mode 100644 index 000000000..3c73ffea6 --- /dev/null +++ b/report_pdf_options/i18n/es_PE.po @@ -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" diff --git a/report_pdf_options/images/main_1.png b/report_pdf_options/images/main_1.png new file mode 100644 index 000000000..81a7c6337 Binary files /dev/null and b/report_pdf_options/images/main_1.png differ diff --git a/report_pdf_options/images/main_screenshot.png b/report_pdf_options/images/main_screenshot.png new file mode 100644 index 000000000..2d270c229 Binary files /dev/null and b/report_pdf_options/images/main_screenshot.png differ diff --git a/report_pdf_options/models/__init__.py b/report_pdf_options/models/__init__.py new file mode 100644 index 000000000..bdf49f605 --- /dev/null +++ b/report_pdf_options/models/__init__.py @@ -0,0 +1 @@ +from . import ir_actions \ No newline at end of file diff --git a/report_pdf_options/models/ir_actions.py b/report_pdf_options/models/ir_actions.py new file mode 100644 index 000000000..ec4ee83ec --- /dev/null +++ b/report_pdf_options/models/ir_actions.py @@ -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 diff --git a/report_pdf_options/static/description/defaultoption.gif b/report_pdf_options/static/description/defaultoption.gif new file mode 100644 index 000000000..5a8124827 Binary files /dev/null and b/report_pdf_options/static/description/defaultoption.gif differ diff --git a/report_pdf_options/static/description/index.html b/report_pdf_options/static/description/index.html new file mode 100644 index 000000000..8d2bfe557 --- /dev/null +++ b/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/report_pdf_options/static/description/printoptions.gif b/report_pdf_options/static/description/printoptions.gif new file mode 100644 index 000000000..bb1ed38e0 Binary files /dev/null and b/report_pdf_options/static/description/printoptions.gif differ diff --git a/report_pdf_options/static/description/printoptions2.gif b/report_pdf_options/static/description/printoptions2.gif new file mode 100644 index 000000000..5267dd4d3 Binary files /dev/null and b/report_pdf_options/static/description/printoptions2.gif differ diff --git a/report_pdf_options/static/description/setupoptions.gif b/report_pdf_options/static/description/setupoptions.gif new file mode 100644 index 000000000..a6a616ba3 Binary files /dev/null and b/report_pdf_options/static/description/setupoptions.gif differ diff --git a/report_pdf_options/static/src/js/PdfOptionsModal.js b/report_pdf_options/static/src/js/PdfOptionsModal.js new file mode 100644 index 000000000..5e127f650 --- /dev/null +++ b/report_pdf_options/static/src/js/PdfOptionsModal.js @@ -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("你想要做什么?"); + } + executePdfAction(option) { + this.props.onSelectOption(option); + } +} + +PdfOptionsModal.template = "report_pdf_options.ButtonOptions"; +PdfOptionsModal.components = { Dialog }; \ No newline at end of file diff --git a/report_pdf_options/static/src/js/qwebactionmanager.js b/report_pdf_options/static/src/js/qwebactionmanager.js new file mode 100644 index 000000000..dd6b4bede --- /dev/null +++ b/report_pdf_options/static/src/js/qwebactionmanager.js @@ -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 = '

wkhtmltopdf.org'; // 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); + } + }) diff --git a/report_pdf_options/static/src/xml/report_pdf_options.xml b/report_pdf_options/static/src/xml/report_pdf_options.xml new file mode 100644 index 000000000..aeeab5728 --- /dev/null +++ b/report_pdf_options/static/src/xml/report_pdf_options.xml @@ -0,0 +1,23 @@ + + + + +
+
+ + + +
+
+
+
+
diff --git a/report_pdf_options/views/ir_actions_report.xml b/report_pdf_options/views/ir_actions_report.xml new file mode 100644 index 000000000..d803c2ca1 --- /dev/null +++ b/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 diff --git a/soong_workflow/models/soong_workflow_mixin.py b/soong_workflow/models/soong_workflow_mixin.py index 5c9be6a0c..368efbc68 100644 --- a/soong_workflow/models/soong_workflow_mixin.py +++ b/soong_workflow/models/soong_workflow_mixin.py @@ -158,7 +158,8 @@ class SoongWorkflowMixin(models.AbstractModel): res = self._load_state_view(view_type, res) res = self._load_one2many_views(view_type, res) res = self._update_fields_view(view_type, res) - res = self._add_state_tree_view(view_type, res) + # 列表视图增加状态字段 + # res = self._add_state_tree_view(view_type, res) return res def _remove_default_header(self, view_type, res): diff --git a/yuthon_notice/__manifest__.py b/yuthon_notice/__manifest__.py index d37ce6dc8..25cd1a91c 100644 --- a/yuthon_notice/__manifest__.py +++ b/yuthon_notice/__manifest__.py @@ -17,6 +17,7 @@ 'views/yuthon_ntice_views.xml', 'views/yuthon_ntice_type_views.xml', 'views/yuthon_confirm_users_views.xml', + 'report/notice_report.xml', ], 'installable': True, 'application': True, diff --git a/yuthon_notice/models/yuthon_notice.py b/yuthon_notice/models/yuthon_notice.py index 3dbfee897..ca327e2c6 100644 --- a/yuthon_notice/models/yuthon_notice.py +++ b/yuthon_notice/models/yuthon_notice.py @@ -8,6 +8,7 @@ class YuthonNotice(models.Model): _description = '通知公告' _inherit = ['mail.thread.main.attachment', 'mail.activity.mixin', 'soong.workflow.mixin'] _rec_name = 'name' + _order = "sequence desc" name = fields.Char(string='通知公告标题') code = fields.Char(string="编号", default=lambda self: self.env['ir.sequence'].next_by_code('notice_code')) @@ -19,13 +20,13 @@ class YuthonNotice(models.Model): create_date = fields.Date(string="发布日期") start_date = fields.Date(string="生效日期") end_date = fields.Date(string="终止日期") + sequence = fields.Integer(string="顺序", default=1) statu = fields.Selection([('new', '草稿'), ('approval', '审批中'), ('no', '未发布'), ('done', '已发布')], default='new', string="公告状态") # pub_range = fields.Char(string="发布范围") - notice_data = fields.Html(string="内容") notice_documents_ids = fields.Many2many('documents.document', string="通知公告文件") # is_confirm = fields.Boolean(string="是否需要人员确认") is_notice_roger = fields.Boolean(string="已读") - notice_text = fields.Text(string="正文") + notice_text = fields.Html(string="正文") @api.onchange('is_notice_roger') def onchange_is_notice_roger(self): @@ -33,6 +34,12 @@ class YuthonNotice(models.Model): if not roger_id: self.is_notice_roger = False + def on_sequence(self): + self.sequence = 1 + + def no_sequence(self): + self.sequence = 0 + # @api.onchange('department_ids', 'employee_ids') # def onchange_pub_range(self): # for pub in self: diff --git a/yuthon_notice/report/notice_report.xml b/yuthon_notice/report/notice_report.xml new file mode 100644 index 000000000..670c7811c --- /dev/null +++ b/yuthon_notice/report/notice_report.xml @@ -0,0 +1,26 @@ + + + + 通知公告打印 + yuthon.notice + qweb-pdf + yuthon_notice.yuthon_notice_report_template + yuthon_notice.yuthon_notice_report_template + '%s' % (object.name).replace('/', '') + + + report + + + + diff --git a/yuthon_notice/views/yuthon_ntice_views.xml b/yuthon_notice/views/yuthon_ntice_views.xml index 27098b9a7..ef40fda03 100644 --- a/yuthon_notice/views/yuthon_ntice_views.xml +++ b/yuthon_notice/views/yuthon_ntice_views.xml @@ -7,12 +7,18 @@ - + + + + +