Skip to content

Commit

Permalink
Merge PR #342 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Dec 6, 2023
2 parents af667b9 + 9e71168 commit 6bc2939
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base_report_to_printer/models/printing_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
# Copyright (C) 2013-2014 Camptocamp (<http://www.camptocamp.com>)
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
# Copyright (C) 2023 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import errno
Expand Down Expand Up @@ -137,6 +138,8 @@ def print_document(self, report, content, **print_opts):
"""
self.ensure_one()
fd, file_name = mkstemp()
if isinstance(content, str):
content = content.encode()
try:
os.write(fd, content)
finally:
Expand Down
1 change: 1 addition & 0 deletions base_report_to_printer/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
* Matias Peralta <mnp@adhoc.com.ar>
* Hughes Damry <hughes.damry@acsone.eu>
* Akim Juillerat <akim.juillerat@camptocamp.com>
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
10 changes: 10 additions & 0 deletions base_report_to_printer/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,13 @@ def test_print_document_no_printer(self):
"""It should raise an error"""
with self.assertRaises(exceptions.UserError):
self.report.print_document(self.partners.ids)

def test_print_document_string(self):
"""Test string encoding"""
with mock.patch(
"odoo.addons.base_report_to_printer.models."
"printing_printer.PrintingPrinter."
"print_file"
) as print_file:
self.new_printer().print_document("", "test")
print_file.assert_called_once()

0 comments on commit 6bc2939

Please sign in to comment.