Skip to content

Commit

Permalink
[IMP] base_report_to_printer: Allow to set a paperformat and fit-to-p…
Browse files Browse the repository at this point in the history
…age for a printer
  • Loading branch information
fkantelberg committed Aug 2, 2024
1 parent eebfa45 commit 294cdf1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base_report_to_printer/models/printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"

Check warning on line 179 in base_report_to_printer/models/printing_printer.py

View check run for this annotation

Codecov / codecov/patch

base_report_to_printer/models/printing_printer.py#L177-L179

Added lines #L177 - L179 were not covered by tests
if self.fit_to_page:
options["fit-to-page"] = ""

Check warning on line 181 in base_report_to_printer/models/printing_printer.py

View check run for this annotation

Codecov / codecov/patch

base_report_to_printer/models/printing_printer.py#L181

Added line #L181 was not covered by tests
return options

def print_file(self, file_name, report=None, **print_opts):
Expand Down
4 changes: 4 additions & 0 deletions base_report_to_printer/views/printing_printer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<field name="status" />
<field name="status_message" />
</group>
<group name="options">
<field name="paperformat_id" />
<field name="fit_to_page" />
</group>
<group string="Trays" name="trays">
<field name="tray_ids" nolabel="1">
<form>
Expand Down

0 comments on commit 294cdf1

Please sign in to comment.