diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 7f0a0f43ab..64c11a7036 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -65,6 +65,12 @@ class Translation(ModelSQL, ModelView, Cacheable): 'UNIQUE (name, res_id, lang, type, src, module)', 'Translation must be unique'), ] + self._constraints += [ + ('check_unique_model', 'unique_model'), + ] + self._error_messages.update({ + 'unique_model': "Translation of type 'model' must be unique!", + }) self._max_len = 10240 def init(self, module_name): @@ -77,6 +83,20 @@ class Translation(ModelSQL, ModelView, Cacheable): def default_fuzzy(self): return False + def check_unique_model(self, ids): + "Check unique model" + cursor = Transaction().cursor + query = ('SELECT count(1) FROM "%s" ' + 'WHERE type = %%s ' + 'AND res_id != 0 ' + 'GROUP BY name, res_id, lang, type, src ' + 'HAVING count(1) > 1' % self._table) + cursor.execute(query, ('model',)) + rowcount = cursor.rowcount + if rowcount == -1 or rowcount is None: + rowcount = len(cursor.fetchall()) + return not bool(rowcount) + def get_model(self, ids, name): res = {} for translation in self.browse(ids): @@ -168,6 +188,9 @@ class Translation(ModelSQL, ModelView, Cacheable): model_fields_obj = self.pool.get('ir.model.field') model_obj = self.pool.get('ir.model') + if lang == 'en_US': + return 0 + model_name, field_name = name.split(',') if model_name in ('ir.model.field', 'ir.model'): if model_name == 'ir.model.field': diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index b9e5a08d18..d2a8e828f5 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -412,7 +412,8 @@ def load_modules(database_name, pool, update=False, lang=None): contextmanager = Transaction().start(database_name, 0) else: contextmanager = contextlib.nested(Transaction().new_cursor(), - Transaction().set_user(0)) + Transaction().set_user(0), + Transaction().set_context(language='en_US')) with contextmanager: cursor = Transaction().cursor force = []