[FIX] ir_actions: server action: when creating or writing value on a record

through a server action, try to correctly set the value to write on a given
fields according to its type. For example many2one fields should receive an
int, not a unique containing the id of the new value.
This commit is contained in:
Thibault Delavallée 2014-08-21 10:32:29 +02:00
parent 43fe825870
commit 4c6dcd7fcb
1 changed files with 19 additions and 10 deletions

View File

@ -892,11 +892,7 @@ class ir_actions_server(osv.osv):
"""
res = {}
for exp in action.fields_lines:
if exp.type == 'equation':
expr = eval(exp.value, eval_context)
else:
expr = exp.value
res[exp.col1.name] = expr
res[exp.col1.name] = exp.eval_value(eval_context=eval_context)[exp.id]
if action.use_write == 'current':
model = action.model_id.model
@ -929,11 +925,7 @@ class ir_actions_server(osv.osv):
"""
res = {}
for exp in action.fields_lines:
if exp.type == 'equation':
expr = eval(exp.value, eval_context)
else:
expr = exp.value
res[exp.col1.name] = expr
res[exp.col1.name] = exp.eval_value(eval_context=eval_context)[exp.id]
if action.use_create in ['new', 'copy_current']:
model = action.model_id.model
@ -1036,7 +1028,9 @@ class ir_actions_server(osv.osv):
class ir_server_object_lines(osv.osv):
_name = 'ir.server.object.lines'
_description = 'Server Action value mapping'
_sequence = 'ir_actions_id_seq'
_columns = {
'server_id': fields.many2one('ir.actions.server', 'Related Server Action'),
'col1': fields.many2one('ir.model.fields', 'Field', required=True),
@ -1049,10 +1043,25 @@ class ir_server_object_lines(osv.osv):
('equation', 'Python expression')
], 'Evaluation Type', required=True, change_default=True),
}
_defaults = {
'type': 'value',
}
def eval_value(self, cr, uid, ids, eval_context=None, context=None):
res = dict.fromkeys(ids, False)
for line in self.browse(cr, uid, ids, context=context):
expr = line.value
if line.type == 'equation':
expr = eval(line.value, eval_context)
elif line.col1.ttype in ['many2one', 'integer']:
try:
expr = int(line.value)
except Exception:
pass
res[line.id] = expr
return res
TODO_STATES = [('open', 'To Do'),
('done', 'Done')]