[IMP] base: add translations when creating a record with lang != 'en_US'

This commit is contained in:
Raphael Collet
2015-10-26 17:34:34 +01:00
parent e039dc6a0b
commit 528a3204f1
+16 -8
View File
@@ -4208,13 +4208,13 @@ class BaseModel(object):
if not edit:
vals.pop(field)
for field in vals:
current_field = self._columns[field]
if current_field._classic_write:
updates.append((field, '%s', current_field._symbol_set[1](vals[field])))
column = self._columns[field]
if column._classic_write:
updates.append((field, '%s', column._symbol_set[1](vals[field])))
#for the function fields that receive a value, we set them directly in the database
#(they may be required), but we also need to trigger the _fct_inv()
if (hasattr(current_field, '_fnct_inv')) and not isinstance(current_field, fields.related):
if (hasattr(column, '_fnct_inv')) and not isinstance(column, fields.related):
#TODO: this way to special case the related fields is really creepy but it shouldn't be changed at
#one week of the release candidate. It seems the only good way to handle correctly this is to add an
#attribute to make a field `really readonly´ and thus totally ignored by the create()... otherwise
@@ -4226,11 +4226,9 @@ class BaseModel(object):
else:
#TODO: this `if´ statement should be removed because there is no good reason to special case the fields
#related. See the above TODO comment for further explanations.
if not isinstance(current_field, fields.related):
if not isinstance(column, fields.related):
upd_todo.append(field)
if field in self._columns \
and hasattr(current_field, 'selection') \
and vals[field]:
if hasattr(column, 'selection') and vals[field]:
self._check_selection_field_value(cr, user, field, vals[field], context=context)
if self._log_access:
updates.append(('create_uid', '%s', user))
@@ -4255,6 +4253,16 @@ class BaseModel(object):
id_new, = cr.fetchone()
recs = self.browse(cr, user, id_new, context)
if context.get('lang') and context['lang'] != 'en_US':
# add translations for context['lang']
for field in vals:
column = self._columns[field]
if column._classic_write and column.translate and not callable(column.translate):
self.pool['ir.translation']._set_ids(
cr, user, self._name+','+field, 'model',
context['lang'], recs.ids, vals[field], vals[field],
)
if self._parent_store and not context.get('defer_parent_store_computation'):
if self.pool._init:
self.pool._init_parent[self._name] = True