diff --git a/CHANGELOG b/CHANGELOG index 99696e3025..a711135aa0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Store custom report translation in separate module * Add form action keyword for set/synchronize translation on report and view * Add negative value for col attribute * Allow to use domain_ method with Function fields diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 583dc9f5b7..dad82d5099 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -1073,68 +1073,72 @@ class TranslationSet(Wizard): cursor = Transaction().connection.cursor() translation = Translation.__table__() for report in reports: - cursor.execute(*translation.select( - translation.id, translation.name, translation.src, - where=(translation.lang == 'en') - & (translation.type == 'report') - & (translation.name == report.report_name) - & (translation.module == report.module or ''))) - trans_reports = {t['src']: t for t in cursor_dict(cursor)} - content = None if report.report: with file_open(report.report.replace('/', os.sep), mode='rb') as fp: content = fp.read() - strings = [] - for content in [report.report_content_custom, content]: + for content, module in [ + (report.report_content_custom, None), + (content, report.module)]: if not content: continue - func_name = 'extract_report_%s' % report.template_extension - strings.extend(getattr(self, func_name)(content)) - for string in {}.fromkeys(strings).keys(): - src_md5 = Translation.get_src_md5(string) - done = False - if string in trans_reports: - del trans_reports[string] - continue - for string_trans in trans_reports: - if string_trans in strings: - continue - seqmatch = SequenceMatcher(lambda x: x == ' ', - string, string_trans) - if seqmatch.ratio() == 1.0: - del trans_reports[report.report_name][string_trans] - done = True - break - if seqmatch.ratio() > 0.6: - cursor.execute(*translation.update( - [translation.src, translation.fuzzy, - translation.src_md5], - [string, True, src_md5], - where=(translation.name == report.report_name) - & (translation.type == 'report') - & (translation.src == string_trans) - & (translation.module == report.module))) - del trans_reports[string_trans] - done = True - break - if not done: - cursor.execute(*translation.insert( - [translation.name, translation.lang, - translation.type, translation.src, - translation.value, translation.module, - translation.fuzzy, translation.src_md5, - translation.res_id], - [[report.report_name, 'en', 'report', string, - '', report.module, False, src_md5, -1]])) - if strings: - cursor.execute(*translation.delete( - where=(translation.name == report.report_name) + cursor.execute(*translation.select( + translation.id, translation.name, translation.src, + where=(translation.lang == 'en') & (translation.type == 'report') - & (translation.module == report.module) - & ~translation.src.in_(strings))) + & (translation.name == report.report_name) + & (translation.module == module))) + trans_reports = {t['src']: t for t in cursor_dict(cursor)} + + strings = set() + func_name = 'extract_report_%s' % report.template_extension + strings.update(getattr(self, func_name)(content)) + + for string in strings: + src_md5 = Translation.get_src_md5(string) + done = False + if string in trans_reports: + del trans_reports[string] + continue + for string_trans in trans_reports: + if string_trans in strings: + continue + seqmatch = SequenceMatcher(lambda x: x == ' ', + string, string_trans) + if seqmatch.ratio() == 1.0: + del trans_reports[report.report_name][string_trans] + done = True + break + if seqmatch.ratio() > 0.6: + cursor.execute(*translation.update( + [translation.src, translation.fuzzy, + translation.src_md5], + [string, True, src_md5], + where=( + translation.name == report.report_name) + & (translation.type == 'report') + & (translation.src == string_trans) + & (translation.module == module))) + del trans_reports[string_trans] + done = True + break + if not done: + cursor.execute(*translation.insert( + [translation.name, translation.lang, + translation.type, translation.src, + translation.value, translation.module, + translation.fuzzy, translation.src_md5, + translation.res_id], + [[report.report_name, 'en', 'report', string, + '', module, False, src_md5, -1]])) + if strings: + cursor.execute(*translation.delete( + where=(translation.name == report.report_name) + & (translation.type == 'report') + & (translation.module == module) + & ~translation.src.in_(list(strings)))) def _translate_view(self, element): strings = [] diff --git a/trytond/ir/translation.xml b/trytond/ir/translation.xml index 47be6616c3..72f08a06fd 100644 --- a/trytond/ir/translation.xml +++ b/trytond/ir/translation.xml @@ -16,7 +16,21 @@ this repository contains the full copyright notices and license terms. --> Translations ir.translation + + + + Modules + + + + + Local + + + diff --git a/trytond/report/report.py b/trytond/report/report.py index 8ce19bcf1f..5ed1f747a0 100644 --- a/trytond/report/report.py +++ b/trytond/report/report.py @@ -76,6 +76,7 @@ class TranslateFactory: cache = self.cache[self.language] = {} code = self.language while code: + # Order to get empty module/custom report first translations = self.translation.search([ ('lang', '=', code), ('type', '=', 'report'), @@ -84,7 +85,7 @@ class TranslateFactory: ('value', '!=', None), ('fuzzy', '=', False), ('res_id', '=', -1), - ]) + ], order=[('module', 'DESC')]) for translation in translations: cache.setdefault(translation.src, translation.value) code = get_parent_language(code)