diff --git a/CHANGELOG b/CHANGELOG index f3dca45eb8..99696e3025 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* 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 * Validate wizard definition on module tests diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index fc1bf17c46..583dc9f5b7 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -10,7 +10,7 @@ from lxml import etree from itertools import izip from io import BytesIO -from sql import Column, Null +from sql import Column, Null, Literal from sql.functions import Substring, Position from sql.conditionals import Case from sql.operators import Or, And @@ -1060,11 +1060,14 @@ class TranslationSet(Wizard): pool = Pool() Report = pool.get('ir.action.report') Translation = pool.get('ir.translation') + context = Transaction().context - with Transaction().set_context(active_test=False): - reports = Report.search([]) - - if not reports: + if context.get('active_model') == Report.__name__: + reports = Report.browse(context.get('active_ids', [])) + elif context.get('active_model', 'ir.ui.menu') == 'ir.ui.menu': + with Transaction().set_context(active_test=False): + reports = Report.search([]) + else: return cursor = Transaction().connection.cursor() @@ -1148,12 +1151,16 @@ class TranslationSet(Wizard): pool = Pool() View = pool.get('ir.ui.view') Translation = pool.get('ir.translation') + context = Transaction().context - with Transaction().set_context(active_test=False): - views = View.search([]) - - if not views: + if context.get('active_model') == View.__name__: + views = View.browse(context.get('active_ids', [])) + elif context.get('active_model', 'ir.ui.menu') == 'ir.ui.menu': + with Transaction().set_context(active_test=False): + views = View.search([]) + else: return + cursor = Transaction().connection.cursor() translation = Translation.__table__() for view in views: @@ -1498,20 +1505,36 @@ class TranslationUpdate(Wizard): def do_update(self, action): pool = Pool() Translation = pool.get('ir.translation') + Report = pool.get('ir.action.report') + View = pool.get('ir.ui.view') + context = Transaction().context cursor = Transaction().connection.cursor() cursor_update = Transaction().connection.cursor() translation = Translation.__table__() lang = self.start.language.code parent_lang = get_parent(lang) + if context.get('active_model') == Report.__name__: + reports = Report.browse(context.get('active_ids', [])) + source_clause = ((translation.type == 'report') + & translation.name.in_([r.report_name for r in reports])) + elif context.get('active_model') == View.__name__: + views = View.browse(context.get('active_ids', [])) + source_clause = ((translation.type == 'view') + & translation.name.in_([v.model for v in views])) + else: + source_clause = Literal(True) + columns = [translation.name.as_('name'), translation.res_id.as_('res_id'), translation.type.as_('type'), translation.src.as_('src'), translation.module.as_('module')] cursor.execute(*(translation.select(*columns, where=(translation.lang == 'en') + & source_clause & translation.type.in_(self._source_types)) - translation.select(*columns, where=(translation.lang == lang) + & source_clause & translation.type.in_(self._source_types)))) to_create = [] for row in cursor_dict(cursor): @@ -1530,9 +1553,11 @@ class TranslationUpdate(Wizard): columns.append(translation.value) cursor.execute(*(translation.select(*columns, where=(translation.lang == parent_lang) + & source_clause & translation.type.in_(self._source_types)) & translation.select(*columns, where=(translation.lang == lang) + & source_clause & translation.type.in_(self._source_types)))) for row in cursor_dict(cursor): cursor_update.execute(*translation.update( @@ -1545,6 +1570,9 @@ class TranslationUpdate(Wizard): & (translation.module == row['module']) & (translation.lang == lang))) + if context.get('active_model') in {Report.__name__, View.__name__}: + return + columns = [translation.name.as_('name'), translation.res_id.as_('res_id'), translation.type.as_('type'), translation.module.as_('module')] diff --git a/trytond/ir/translation.xml b/trytond/ir/translation.xml index 10bb5d0baa..47be6616c3 100644 --- a/trytond/ir/translation.xml +++ b/trytond/ir/translation.xml @@ -271,6 +271,18 @@ this repository contains the full copyright notices and license terms. --> Set Translations ir.translation.set + + form_action + ir.action.report,-1 + + + + form_action + ir.ui.view,-1 + + Synchronize Translations ir.translation.update + + form_action + ir.action.report,-1 + + + + form_action + ir.ui.view,-1 + +