changeset 7c28ddc99210 in trytond:6.0 details: https://hg.tryton.org/trytond?cmd=changeset&node=7c28ddc99210 description: Include action report name on report name max length
issue10946 review374151002 (grafted from 90517aa1addf77b9a1d8ac5cb65506f7828d6b11) diffstat: trytond/report/report.py | 20 ++++++++++++++------ 1 files changed, 14 insertions(+), 6 deletions(-) diffs (55 lines): diff -r 812c69084e51 -r 7c28ddc99210 trytond/report/report.py --- a/trytond/report/report.py Fri Nov 05 00:01:42 2021 +0100 +++ b/trytond/report/report.py Sat Nov 13 01:38:59 2021 +0100 @@ -154,11 +154,13 @@ else: action_report = ActionReport(action_id) - def report_name(records): + def report_name(records, reserved_length=0): names = [] name_length = 0 record_count = len(records) - max_length = REPORT_NAME_MAX_LENGTH - len(str(record_count)) - 2 + max_length = (REPORT_NAME_MAX_LENGTH + - reserved_length + - len(str(record_count)) - 2) for record in records[:5]: record_name = record.rec_name name_length += len(record_name) + 1 @@ -190,6 +192,7 @@ headers.append(dict(key)) n = len(groups) + join_string = '-' if n > 1: padding = math.ceil(math.log10(n)) content = BytesIO() @@ -198,9 +201,10 @@ zip(headers, groups), 1): oext, rcontent = cls._execute( group_records, header, data, action_report) - filename = report_name(group_records) number = str(i).zfill(padding) - filename = slugify('%s-%s' % (number, filename)) + filename = report_name( + group_records, len(number) + len(join_string)) + filename = slugify(join_string.join([number, filename])) rfilename = '%s.%s' % (filename, oext) content_zip.writestr(rfilename, rcontent) content = content.getvalue() @@ -210,8 +214,12 @@ groups[0], headers[0], data, action_report) if not isinstance(content, str): content = bytearray(content) if bytes == str else bytes(content) - filename = '-'.join( - filter(None, [action_report.name, report_name(records)])) + action_report_name = action_report.name[:REPORT_NAME_MAX_LENGTH] + filename = join_string.join( + filter(None, [ + action_report_name, + report_name( + records, len(action_report_name) + len(join_string))])) return (oext, content, action_report.direct_print, filename) @classmethod