From 294cdf1672fccb8e145f33d97098315f9b408483 Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Fri, 2 Aug 2024 10:20:59 +0200 Subject: [PATCH] [IMP] base_report_to_printer: Allow to set a paperformat and fit-to-page for a printer --- base_report_to_printer/models/printing_printer.py | 9 +++++++++ base_report_to_printer/views/printing_printer.xml | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/base_report_to_printer/models/printing_printer.py b/base_report_to_printer/models/printing_printer.py index f6af23031df..25c60e39c50 100644 --- a/base_report_to_printer/models/printing_printer.py +++ b/base_report_to_printer/models/printing_printer.py @@ -63,6 +63,8 @@ class PrintingPrinter(models.Model): model = fields.Char(readonly=True) location = fields.Char(readonly=True) uri = fields.Char(string="URI", readonly=True) + paperformat_id = fields.Many2one("report.paperformat") + fit_to_page = fields.Boolean() tray_ids = fields.One2many( comodel_name="printing.tray", inverse_name="printer_id", string="Paper Sources" ) @@ -170,6 +172,13 @@ def print_options(self, report=None, **print_opts): options.update(getattr(self, "_set_option_%s" % option)(report, value)) except AttributeError: options[option] = str(value) + + if self.paperformat_id: + width = int(self.paperformat_id.print_page_width) + height = int(self.paperformat_id.print_page_height) + options["media"] = f"Custom.{width}x{height}mm" + if self.fit_to_page: + options["fit-to-page"] = "" return options def print_file(self, file_name, report=None, **print_opts): diff --git a/base_report_to_printer/views/printing_printer.xml b/base_report_to_printer/views/printing_printer.xml index 5c7657c0688..de07de714ee 100644 --- a/base_report_to_printer/views/printing_printer.xml +++ b/base_report_to_printer/views/printing_printer.xml @@ -77,6 +77,10 @@ + + + +