Add report data to header_key

Closes #13627
This commit is contained in:
Cédric Krier
2024-10-24 18:11:42 +02:00
parent 5966a42979
commit 16da4be04f
4 changed files with 12 additions and 6 deletions
+4 -2
View File
@@ -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):
+1
View File
@@ -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
+2 -1
View File
@@ -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)
+5 -3
View File
@@ -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))