From 1647026446625431f7ea6749ff49b70739e2a0b8 Mon Sep 17 00:00:00 2001 From: loris-fab Date: Mon, 3 Aug 2026 15:08:21 +0200 Subject: [PATCH] [T3351] FIX: Restore childpack printing - Register report.child_compassion.childpack_full/small rendering models so the report falls back on data['doc_ids']. The web client builds the report URL from the wizard options and drops the record ids, so the report was rendered on an empty recordset and produced a blank PDF whenever "Print background" was left unchecked. - Call get_base_url() per record in _compute_qr_code, as it requires a singleton and raised "Expected singleton" when printing the QR code for several children at once. --- child_compassion/models/__init__.py | 1 + child_compassion/models/child_compassion.py | 2 +- child_compassion/models/report_childpack.py | 48 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 child_compassion/models/report_childpack.py diff --git a/child_compassion/models/__init__.py b/child_compassion/models/__init__.py index 383179c25..f79e9bb15 100644 --- a/child_compassion/models/__init__.py +++ b/child_compassion/models/__init__.py @@ -20,5 +20,6 @@ major_revision, project_compassion, project_lifecycle_event, + report_childpack, weekly_demand, ) diff --git a/child_compassion/models/child_compassion.py b/child_compassion/models/child_compassion.py index 49f46b914..b5699cb76 100644 --- a/child_compassion/models/child_compassion.py +++ b/child_compassion/models/child_compassion.py @@ -297,7 +297,6 @@ def _compute_qr_code(self): UTMs can be overridden through the context keys ``qr_utm_medium``, ``qr_utm_source`` and ``qr_utm_campaign``. """ - base_url = self.get_base_url().rstrip("/") utm_params = { "utm_medium": self.env.context.get("qr_utm_medium") or "childpack_qr", "utm_source": self.env.context.get("qr_utm_source") or "hold_campaign", @@ -307,6 +306,7 @@ def _compute_qr_code(self): utm_params["utm_campaign"] = utm_campaign query = urlencode(utm_params) for child in self: + base_url = child.get_base_url().rstrip("/") url = f"{base_url}/my2/new-sponsorship/{child.id}?{query}" qr = pyqrcode.create(url) child.qr_code_data = qr.png_as_base64_str(15, (0, 84, 166)) diff --git a/child_compassion/models/report_childpack.py b/child_compassion/models/report_childpack.py new file mode 100644 index 000000000..ed618f586 --- /dev/null +++ b/child_compassion/models/report_childpack.py @@ -0,0 +1,48 @@ +############################################################################## +# +# Copyright (C) 2016-2026 Compassion CH (http://www.compassion.ch) +# Releasing children from poverty in Jesus' name +# +# The licence is in the file __manifest__.py +# +############################################################################## +from odoo import api, models + + +class ReportChildpackFull(models.AbstractModel): + """ + Rendering context of the childpack reports. + + The print wizard passes its options (lang, type, print_qr, ...) through the + ``data`` dictionary. When that dictionary is set, the web client builds the + report URL without the record ids (see ``getReportUrl`` in web), so the + report is rendered with no ``docids`` at all and would print a blank page. + We therefore fall back on the ids the wizard stored in ``data['doc_ids']``. + """ + + _name = "report.child_compassion.childpack_full" + _description = "Childpack report rendering context" + + @api.model + def _get_report_values(self, docids, data=None): + data = dict(data or {}) + docids = docids or data.get("doc_ids") or self.env.context.get("active_ids", []) + lang = data.get("lang") + docs = self.env["compassion.child"].browse(docids) + if lang: + docs = docs.with_context(lang=lang) + data.update( + { + "doc_ids": docs.ids, + "doc_model": "compassion.child", + "docs": docs, + } + ) + return data + + +# pylint: disable=R7980 +class ReportChildpackSmall(models.AbstractModel): + _inherit = "report.child_compassion.childpack_full" + _name = "report.child_compassion.childpack_small" + _description = "Small childpack report rendering context"