diff --git a/base_report_to_printer/README.rst b/base_report_to_printer/README.rst index ca78947..1c659b5 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 @@ -155,6 +156,7 @@ Contributors * Rod Schouteden * Alexandre Fayolle * Matias Peralta +* Akim Juillerat Maintainers ~~~~~~~~~~~ diff --git a/base_report_to_printer/__manifest__.py b/base_report_to_printer/__manifest__.py index 61af227..1512214 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 1878344..10d30b1 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(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 + )(record_ids, data=data) behaviour = self.behaviour() printer = behaviour.pop("printer", None) @@ -159,3 +168,22 @@ class IrActionsReport(models.Model): ) return document, doc_format + + def _render_qweb_text(self, 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(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 7085b17..a046d90 100644 --- a/base_report_to_printer/readme/CONTRIBUTORS.rst +++ b/base_report_to_printer/readme/CONTRIBUTORS.rst @@ -12,3 +12,4 @@ * Rod Schouteden * Alexandre Fayolle * Matias Peralta +* 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 fecf525..31051a1 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