From 16da4be04f1b06d89df3c4dc40f93c84bfefcd20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Oct 2024 18:11:42 +0200 Subject: [PATCH] Add report data to header_key Closes #13627 --- modules/company/company.py | 6 ++++-- trytond/CHANGELOG | 1 + trytond/doc/ref/report.rst | 3 ++- trytond/trytond/report/report.py | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/company/company.py b/modules/company/company.py index d6e82b5c59..a819411d8d 100644 --- a/modules/company/company.py +++ b/modules/company/company.py @@ -353,8 +353,10 @@ class CompanyConfig(Wizard): class CompanyReport(Report): @classmethod - def header_key(cls, record): - return super().header_key(record) + (('company', record.company),) + def header_key(cls, record, data): + return super().header_key(record, data) + ( + ('company', record.company), + ) @classmethod def get_context(cls, records, header, data): diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 53b82475ab..6c4f9cbe66 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Add report data to header_key * Validate integer digits * Add support for DATE_TRUNC from INTERVAL to SQLite backend * Add support for EXTRACT from INTERVAL to SQLite backend diff --git a/trytond/doc/ref/report.rst b/trytond/doc/ref/report.rst index e0294c3a6d..e3f4b05d3f 100644 --- a/trytond/doc/ref/report.rst +++ b/trytond/doc/ref/report.rst @@ -39,10 +39,11 @@ Class methods are: Verifies if the :attr:`~trytond.transaction.Transaction.user` is allowed to execute the report. -.. classmethod:: Report.header_key(record) +.. classmethod:: Report.header_key(record[, data]) Returns a tuple of keys, composed of couples of name and record value, used to group document with the same header. + ``data`` is the dictionary passed to :meth:~Report.execute`. .. classmethod:: Report.execute(ids, data) diff --git a/trytond/trytond/report/report.py b/trytond/trytond/report/report.py index a14a0b6002..1483af8e74 100644 --- a/trytond/trytond/report/report.py +++ b/trytond/trytond/report/report.py @@ -15,6 +15,7 @@ import unicodedata import warnings import zipfile from email.message import EmailMessage +from functools import partial from io import BytesIO from itertools import groupby @@ -175,7 +176,7 @@ class Report(URLMixin, PoolBase): Model.read(ids, ['id']) @classmethod - def header_key(cls, record): + def header_key(cls, record, data): return () @classmethod @@ -240,16 +241,17 @@ class Report(URLMixin, PoolBase): else: records = [] + header_key = partial(cls.header_key, data=data) if not records: groups = [[]] headers = [{}] elif action_report.single: groups = [[r] for r in records] - headers = [dict(cls.header_key(r)) for r in records] + headers = [dict(header_key(r)) for r in records] else: groups = [] headers = [] - for key, group in groupby(records, key=cls.header_key): + for key, group in groupby(records, key=header_key): groups.append(list(group)) headers.append(dict(key))