[FIX]Docx Report Generation : localesel filter fixed for main record

This commit is contained in:
Fabien BOURGEOIS 2025-02-21 17:44:56 +01:00
parent 8c5e3dbb7d
commit 006d7ef6ec
2 changed files with 7 additions and 4 deletions

View File

@ -14,7 +14,7 @@
"author": "RYDLAB, Yaltik",
"website": "https://rydlab.ru",
"category": "Technical",
"version": "16.0.2.2.6",
"version": "16.0.2.2.7",
"license": "LGPL-3",
"depends": ["base", "web", "custom_report_field", "report_monetary_helpers"],
"external_dependencies": {"python": ["docxcompose", "docxtpl", "beautifulsoup4"]},

View File

@ -530,6 +530,11 @@ class IrActionsReport(models.Model):
jinja_env = jinja2.Environment()
def _localesel(record, field):
if not hasattr(record, '_fields'):
record = values['record']
return record._fields[field].convert_to_export(getattr(record, field), self)
docx_content = BytesIO()
with BytesIO(b64decode(template)) as template_file:
doc = DocxTemplate(template_file)
@ -541,9 +546,7 @@ class IrActionsReport(models.Model):
format_datetime(self.env, dt, dt_format=df)
)
jinja_env.filters['duration'] = lambda du: format_duration(du)
jinja_env.filters['localesel'] = lambda record, field: (
record._fields[field].convert_to_export(getattr(record, field), self)
)
jinja_env.filters['localesel'] = _localesel
doc.render(values, jinja_env)
doc.save(docx_content)
docx_content.seek(0)