[FIX] models: in create, add translations after setting x2many fields. (#19348)

Otherwise if a record rule is defined on a x2many field on the model, the creation will fail because
ir.translation creation check access rules on the model and in this case, the x2many relation are
not set yet.
This commit is contained in:
Cédric Pigeon (ACSONE)
2017-10-10 15:53:09 +02:00
committed by Raphael Collet
parent cae506f0ed
commit 4206d1c2a2
+9 -8
View File
@@ -3924,14 +3924,6 @@ class BaseModel(object):
id_new, = cr.fetchone()
self = self.browse(id_new)
if self.env.lang and self.env.lang != 'en_US':
# add translations for self.env.lang
for name, val in vals.iteritems():
field = self._fields[name]
if field.store and field.column_type and field.translate is True:
tname = "%s,%s" % (self._name, name)
self.env['ir.translation']._set_ids(tname, 'model', self.env.lang, self.ids, val, val)
if self._parent_store and not self._context.get('defer_parent_store_computation'):
if self.pool._init:
self.pool._init_parent[self._name] = True
@@ -3993,6 +3985,15 @@ class BaseModel(object):
self.recompute()
self.check_access_rule('create')
if self.env.lang and self.env.lang != 'en_US':
# add translations for self.env.lang
for name, val in vals.iteritems():
field = self._fields[name]
if field.store and field.column_type and field.translate is True:
tname = "%s,%s" % (self._name, name)
self.env['ir.translation']._set_ids(tname, 'model', self.env.lang, self.ids, val, val)
self.create_workflow()
return id_new