changeset 3925b109f1a4 in trytond:6.2
details: https://hg.tryton.org/trytond?cmd=changeset&node=3925b109f1a4
description:
        Include action report name on report name max length

        issue10946
        review374151002
        (grafted from 90517aa1addf77b9a1d8ac5cb65506f7828d6b11)
diffstat:

 trytond/report/report.py |  22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diffs (59 lines):

diff -r 63897357cc7d -r 3925b109f1a4 trytond/report/report.py
--- a/trytond/report/report.py  Mon Nov 01 16:57:57 2021 +0100
+++ b/trytond/report/report.py  Sat Nov 13 01:38:59 2021 +0100
@@ -157,11 +157,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)
             if action_report.record_name:
                 template = TextTemplate(action_report.record_name)
             else:
@@ -200,6 +202,7 @@
                 headers.append(dict(key))
 
         n = len(groups)
+        join_string = '-'
         if n > 1:
             padding = math.ceil(math.log10(n))
             content = BytesIO()
@@ -208,9 +211,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()
@@ -220,11 +224,15 @@
                 groups[0], headers[0], data, action_report)
         if not isinstance(content, str):
             content = bytearray(content) if bytes == str else bytes(content)
+        action_report_name = action_report.name[:REPORT_NAME_MAX_LENGTH]
         if context.get('with_rec_name', True):
-            filename = '-'.join(
-                filter(None, [action_report.name, report_name(records)]))
+            filename = join_string.join(
+                filter(None, [
+                    action_report_name,
+                    report_name(
+                        records, len(action_report_name) + len(join_string))]))
         else:
-            filename = action_report.name
+            filename = action_report_name
         return (oext, content, action_report.direct_print, filename)
 
     @classmethod

Reply via email to