From 88d69f4ac53eb67c18d75840af865d7a73def048 Mon Sep 17 00:00:00 2001 From: Moises Lopez Date: Sun, 23 Aug 2026 23:25:04 -0600 Subject: [PATCH] [FIX] report_qweb_encrypt: accept single res_id Odoo's PDF report API accepts res_ids either as a list or as a single integer. This mirrors how Odoo normalizes res_ids internally before continuing the rendering flow: - https://github.com/odoo/odoo/blob/80e1a4464f75df5beeae0d8205a282da755c1a7d/odoo/addons/base/models/ir_actions_report.py#L659 There are real callers that use the single-id form. For example, stock.picking renders the delivery report with self.id: - https://github.com/odoo/odoo/blob/ba4315ec85341431dd9bcd4f4d64217c37a4865f/addons/stock/models/stock_picking.py#L2014 report_qweb_encrypt kept using the original res_ids value after calling super() and sliced it to evaluate the encryption password. When a caller passed a single id, slicing the integer raised TypeError before the password could be read. Normalize the local value before calling _get_pdf_password, and change the existing test to pass a single res_id, which is the form that used to fail. --- report_qweb_encrypt/models/ir_actions_report.py | 2 ++ report_qweb_encrypt/tests/test_report_qweb_encrypt.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/report_qweb_encrypt/models/ir_actions_report.py b/report_qweb_encrypt/models/ir_actions_report.py index 8114c7f0b8..1313688136 100644 --- a/report_qweb_encrypt/models/ir_actions_report.py +++ b/report_qweb_encrypt/models/ir_actions_report.py @@ -33,6 +33,8 @@ def _render_qweb_pdf(self, report_ref, res_ids=None, data=None): ) report_sudo = self._get_report(report_ref) if res_ids: + if isinstance(res_ids, int): + res_ids = [res_ids] encrypt_password = self.env.context.get("encrypt_password") report = self._get_report_from_name(report_sudo.report_name).with_context( encrypt_password=encrypt_password diff --git a/report_qweb_encrypt/tests/test_report_qweb_encrypt.py b/report_qweb_encrypt/tests/test_report_qweb_encrypt.py index 2095531c1d..d99a53c118 100644 --- a/report_qweb_encrypt/tests/test_report_qweb_encrypt.py +++ b/report_qweb_encrypt/tests/test_report_qweb_encrypt.py @@ -40,12 +40,12 @@ def test_report_qweb_manual_encrypt(self): report.encrypt = "manual" # If no encrypt_password, still not encrypted - pdf, _ = report.with_context(**ctx)._render_qweb_pdf(report.report_name, [1]) + pdf, _ = report.with_context(**ctx)._render_qweb_pdf(report.report_name, 1) self.assertFalse(pdf.count(b"/Encrypt")) # Valid python string for password ctx.update({"encrypt_password": "secretcode"}) - pdf, _ = report.with_context(**ctx)._render_qweb_pdf(report.report_name, [1]) + pdf, _ = report.with_context(**ctx)._render_qweb_pdf(report.report_name, 1) self.assertTrue(pdf.count(b"/Encrypt")) # TODO: test_report_qweb_manual_encrypt, require JS test?