[IMP] fields, web: change output format of onchange for x2many fields
Those fields are serialized as lists of commands.
This commit is contained in:
@@ -474,19 +474,6 @@ var AbstractManyField = common.AbstractField.extend({
|
||||
throw new Error("set_value of '"+this.name+"' must receive an list of ids without virtual ids.", ids);
|
||||
}
|
||||
if (_.find(ids, function(id) { return typeof(id) !== "number"; } )) {
|
||||
this.dataset.reset_ids([], {keep_read_data: true});
|
||||
ids = _.map(ids, function(command) {
|
||||
if (command instanceof Array) {
|
||||
return command;
|
||||
} else {
|
||||
// command is a dictionary, convert it to a command
|
||||
if (command.id) {
|
||||
return COMMANDS.update(command.id, command);
|
||||
} else {
|
||||
return COMMANDS.create(command);
|
||||
}
|
||||
}
|
||||
});
|
||||
return this.send_commands(ids, {'_inhibit_on_change_flag': this._inhibit_on_change_flag});
|
||||
}
|
||||
this.dataset.reset_ids(ids);
|
||||
@@ -616,7 +603,7 @@ var AbstractManyField = common.AbstractField.extend({
|
||||
}
|
||||
return;
|
||||
case COMMANDS.DELETE_ALL:
|
||||
return dataset.reset_ids([]);
|
||||
return dataset.reset_ids([], {keep_read_data: true});
|
||||
case COMMANDS.REPLACE_WITH:
|
||||
dataset.ids = [];
|
||||
return dataset.alter_ids(command[2], options);
|
||||
|
||||
@@ -107,19 +107,19 @@ class TestOnChange(common.TransactionCase):
|
||||
result = self.Discussion.onchange(values, 'name', field_onchange)
|
||||
self.assertIn('messages', result['value'])
|
||||
self.assertEqual(result['value']['messages'], [
|
||||
{
|
||||
'id': message.id,
|
||||
(5,),
|
||||
(1, message.id, {
|
||||
'name': "[%s] %s" % ("Foo", USER.name),
|
||||
'body': message.body,
|
||||
'author': message.author.name_get()[0],
|
||||
'size': message.size,
|
||||
},
|
||||
{
|
||||
}),
|
||||
(0, 0, {
|
||||
'name': "[%s] %s" % ("Foo", USER.name),
|
||||
'body': BODY,
|
||||
'author': USER.name_get()[0],
|
||||
'size': len(BODY),
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
def test_onchange_specific(self):
|
||||
@@ -149,7 +149,7 @@ class TestOnChange(common.TransactionCase):
|
||||
self.assertIn('participants', result['value'])
|
||||
self.assertEqual(
|
||||
result['value']['participants'],
|
||||
[{'id': usr.id} for usr in discussion.participants + demo],
|
||||
[(5,)] + [(4, usr.id) for usr in discussion.participants + demo],
|
||||
)
|
||||
|
||||
def test_onchange_one2many_value(self):
|
||||
|
||||
+10
-5
@@ -1737,14 +1737,19 @@ class _RelationalMulti(_Relational):
|
||||
return result
|
||||
|
||||
def convert_to_onchange(self, value, fnames=None):
|
||||
# return the recordset value as a list of dicts
|
||||
# return the recordset value as a list of commands; the commands may
|
||||
# give all fields values, the client is responsible for figuring out
|
||||
# which fields are actually dirty
|
||||
fields = [(name, value._fields[name]) for name in (fnames or [])]
|
||||
result = []
|
||||
result = [(5,)]
|
||||
for record in value:
|
||||
vals = {name: field.convert_to_onchange(record[name]) for name, field in fields}
|
||||
if record.id:
|
||||
vals['id'] = record.id
|
||||
result.append(vals)
|
||||
if not record.id:
|
||||
result.append((0, 0, vals))
|
||||
elif vals:
|
||||
result.append((1, record.id, vals))
|
||||
else:
|
||||
result.append((4, record.id))
|
||||
return result
|
||||
|
||||
def convert_to_export(self, value, env):
|
||||
|
||||
Reference in New Issue
Block a user