Template bug
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user