diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index 5698f59..0395d69 100644 --- a/base_report_to_printer/README.rst +++ b/base_report_to_printer/README.rst @@ -82,7 +82,8 @@ The jobs will be sent to the printer with a name matching the print_report_name of the report (truncated at 80 characters). By default this will not be displayed by CUPS web interface or in Odoo. To see this information, you need to change the configuration of your CUPS server and set the JobPrivateValue -directive to "job-name", and reload the server. See `cupsd.conf(5) +directive to "none" (or some other list of values which does not include +"job-name") , and reload the server. See `cupsd.conf(5) ` for details. Usage @@ -156,6 +157,7 @@ Contributors * Alexandre Fayolle * Matias Peralta * Hughes Damry +* Akim Juillerat Maintainers ~~~~~~~~~~~ diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index 3162307..ec2ce52 100644 --- a/base_report_to_printer/__manifest__.py +++ b/base_report_to_printer/__manifest__.py @@ -24,6 +24,7 @@ "views/printing_report.xml", "views/res_users.xml", "views/ir_actions_report.xml", + "wizards/print_attachment_report.xml", "wizards/printing_printer_update_wizard_view.xml", ], "assets": { diff --git a/base_report_to_printer/models/ir_actions_report.py b/base_report_to_printer/models/ir_actions_report.py index 1f1d63f..652d6f2 100644 --- a/base_report_to_printer/models/ir_actions_report.py +++ b/base_report_to_printer/models/ir_actions_report.py @@ -8,6 +8,8 @@ from odoo import _, api, exceptions, fields, models from odoo.tools.safe_eval import safe_eval, time +REPORT_TYPES = {"qweb-pdf": "pdf", "qweb-text": "text"} + class IrActionsReport(models.Model): _inherit = "ir.actions.report" @@ -99,9 +101,16 @@ class IrActionsReport(models.Model): def print_document(self, record_ids, data=None): """Print a document, do not return the document file""" - document, doc_format = self.with_context( - must_skip_send_to_printer=True - )._render_qweb_pdf(self.report_name, record_ids, data=data) + report_type = REPORT_TYPES.get(self.report_type) + if not report_type: + raise exceptions.UserError( + _("This report type (%s) is not supported by direct printing!") + % str(self.report_type) + ) + method_name = "_render_qweb_%s" % (report_type) + document, doc_format = getattr( + self.with_context(must_skip_send_to_printer=True), method_name + )(self.report_name, record_ids, data=data) behaviour = self.behaviour() printer = behaviour.pop("printer", None) @@ -161,3 +170,24 @@ class IrActionsReport(models.Model): ) return document, doc_format + + def _render_qweb_text(self, report_ref, docids, data=None): + """Generate a TEXT file and returns it. + + If the action configured on the report is server, it prints the + generated document as well. + """ + document, doc_format = super()._render_qweb_text( + report_ref, docids=docids, data=data + ) + + behaviour = self.behaviour() + printer = behaviour.pop("printer", None) + can_print_report = self._can_print_report(behaviour, printer, document) + + if can_print_report: + printer.print_document( + self, document, doc_format=self.report_type, **behaviour + ) + + return document, doc_format diff --git a/base_report_to_printer/readme/CONFIGURE.rst b/base_report_to_printer/readme/CONFIGURE.rst index 0b12368..3463730 100644 --- a/base_report_to_printer/readme/CONFIGURE.rst +++ b/base_report_to_printer/readme/CONFIGURE.rst @@ -8,5 +8,6 @@ The jobs will be sent to the printer with a name matching the print_report_name of the report (truncated at 80 characters). By default this will not be displayed by CUPS web interface or in Odoo. To see this information, you need to change the configuration of your CUPS server and set the JobPrivateValue -directive to "job-name", and reload the server. See `cupsd.conf(5) +directive to "none" (or some other list of values which does not include +"job-name") , and reload the server. See `cupsd.conf(5) ` for details. diff --git a/base_report_to_printer/readme/CONTRIBUTORS.rst b/base_report_to_printer/readme/CONTRIBUTORS.rst index 9fffa8e..db926ad 100644 --- a/base_report_to_printer/readme/CONTRIBUTORS.rst +++ b/base_report_to_printer/readme/CONTRIBUTORS.rst @@ -13,3 +13,4 @@ * Alexandre Fayolle * Matias Peralta * Hughes Damry +* Akim Juillerat diff --git a/base_report_to_printer/security/security.xml b/base_report_to_printer/security/security.xml index ebda2e8..8f68e12 100644 --- a/base_report_to_printer/security/security.xml +++ b/base_report_to_printer/security/security.xml @@ -125,6 +125,23 @@ Update printer wizard + + + + + + Print Attachment User + + + + + + + + + Print Attachment Line User + + diff --git a/base_report_to_printer/static/description/index.html b/base_report_to_printer/static/description/index.html index 1934af2..b46ef5f 100644 --- a/base_report_to_printer/static/description/index.html +++ b/base_report_to_printer/static/description/index.html @@ -3,7 +3,7 @@ - + Report to printer