changeset f5fd5cdc43dc in trytond:6.0
details: https://hg.tryton.org/trytond?cmd=changeset&node=f5fd5cdc43dc
description:
Limit size of report name to 200 chars
issue10330
review332771003
(grafted from 12d2c2e990659c6eb709e937d7382b6ca2912a1d)
diffstat:
trytond/report/report.py | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
diffs (36 lines):
diff -r 975e089d2023 -r f5fd5cdc43dc trytond/report/report.py
--- a/trytond/report/report.py Sun Sep 05 14:40:15 2021 +0200
+++ b/trytond/report/report.py Mon Jul 05 09:52:19 2021 +0200
@@ -88,6 +88,8 @@
TIMEDELTA_DEFAULT_CONVERTER['M'] = TIMEDELTA_DEFAULT_CONVERTER['d'] * 30
TIMEDELTA_DEFAULT_CONVERTER['Y'] = TIMEDELTA_DEFAULT_CONVERTER['d'] * 365
+REPORT_NAME_MAX_LENGTH = 200
+
class TranslateFactory:
@@ -153,9 +155,20 @@
action_report = ActionReport(action_id)
def report_name(records):
- name = '-'.join(r.rec_name for r in records[:5])
- if len(records) > 5:
- name += '__' + str(len(records[5:]))
+ names = []
+ name_length = 0
+ record_count = len(records)
+ max_length = REPORT_NAME_MAX_LENGTH - len(str(record_count)) - 2
+ for record in records[:5]:
+ record_name = record.rec_name
+ name_length += len(record_name) + 1
+ if name_length > max_length:
+ break
+ names.append(record_name)
+
+ name = '-'.join(names)
+ if len(records) > len(names):
+ name += '__' + str(record_count - len(names))
return name
records = []