Fix duplicate translation for issue1717
Don't create translation for en_US Set en_US language when loading modules Add constraint to prevent duplicate model translation
This commit is contained in:
1 parent
7f98467acf
commit
d5eae53bcb
2 files changed
+25
-1
No files matched your search
@@ -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':
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
Reference in new issue
Block a user