From aac7bad852c778e26551b400e52bcf645fc66afb Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sat, 13 Jun 2026 12:25:49 +0200 Subject: [PATCH] Template bug --- modules/purchase_trade/invoice.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/purchase_trade/invoice.py b/modules/purchase_trade/invoice.py index df0ab99..c25b5c2 100644 --- a/modules/purchase_trade/invoice.py +++ b/modules/purchase_trade/invoice.py @@ -1,5 +1,7 @@ from decimal import Decimal, ROUND_HALF_UP from datetime import date as dt_date +import os +from pathlib import Path from sql import Literal from sql.conditionals import Case @@ -10,6 +12,7 @@ from trytond.pool import Pool, PoolMeta from trytond.modules.purchase_trade.numbers_to_words import amount_to_currency_words from trytond.exceptions import UserError from trytond.transaction import Transaction +from trytond.tools import file_open from trytond.modules.account_invoice.invoice import ( InvoiceReport as BaseInvoiceReport) from trytond.modules.sale.sale import SaleReport as BaseSaleReport @@ -1849,14 +1852,32 @@ class ReportTemplateMixin: return f'{default_prefix}/{template}' return template + @classmethod + def _load_report_content(cls, report_path): + file_name = report_path.replace('/', os.sep) + try: + with file_open(file_name, mode='rb') as fp: + return fp.read() + except FileNotFoundError: + modules_dir = Path(__file__).resolve().parent.parent + path = modules_dir.joinpath(*report_path.split('/')) + try: + return path.read_bytes() + except FileNotFoundError: + raise UserError('No template found') + @classmethod def _get_resolved_action(cls, action): report_path = cls._resolve_configured_report_path(action) + report_content = cls._load_report_content(report_path) if isinstance(action, dict): resolved = dict(action) resolved['report'] = report_path + resolved['report_content'] = report_content return resolved setattr(action, 'report', report_path) + setattr(action, 'report_content', report_content) + action._template_cache.clear() return action @classmethod