changeset 8d73b5f47df2 in trytond:6.0
details: https://hg.tryton.org/trytond?cmd=changeset&node=8d73b5f47df2
description:
        Clean translations after every templates have been parsed

        A report can have many templates, so we must keep the translations for 
all of
        them.

        issue11436
        review388441002
        (grafted from 33c8f05556b355edce4b20b74e408ecd5b7a2bae)
diffstat:

 trytond/ir/translation.py |  17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diffs (41 lines):

diff -r 34a1e50bc2b0 -r 8d73b5f47df2 trytond/ir/translation.py
--- a/trytond/ir/translation.py Fri Aug 05 00:35:20 2022 +0200
+++ b/trytond/ir/translation.py Sat May 07 10:58:45 2022 +0200
@@ -1010,6 +1010,7 @@
 
         cursor = Transaction().connection.cursor()
         translation = Translation.__table__()
+        report_strings = defaultdict(set)
         for report in reports:
             content = None
             if report.report:
@@ -1030,7 +1031,7 @@
                         & (translation.module == module)))
                 trans_reports = {t['src']: t for t in cursor_dict(cursor)}
 
-                strings = set()
+                strings = report_strings[report.report_name, report.module]
                 func_name = 'extract_report_%s' % report.template_extension
                 strings.update(getattr(self, func_name)(content))
 
@@ -1071,12 +1072,14 @@
                                         'report', string,
                                         '', module,
                                         False, -1]]))
-                if strings:
-                    cursor.execute(*translation.delete(
-                            where=(translation.name == report.report_name)
-                            & (translation.type == 'report')
-                            & (translation.module == module)
-                            & ~translation.src.in_(list(strings))))
+        for (report_name, module), strings in report_strings.items():
+            query = translation.delete(
+                where=(translation.name == report_name)
+                & (translation.type == 'report')
+                & (translation.module == module))
+            if strings:
+                query.where &= ~translation.src.in_(list(strings))
+            cursor.execute(*query)
 
     def _translate_view(self, element):
         strings = []

Reply via email to