[FIX] web: BasicModel: default_get: false m2o inside o2m

Sometimes, a default_get returns a create command for a one2many,
with a dict of values containing value 'false' for a many2one. This
is strictly equivalent to the case where the many2one field isn't
in the dict of values, but we have to handle both cases, and before
this rev., we only handled the latter one.

This happens for example in Sales > Leads (must be activated in the
Settings) > in the list view, check several leads > in 'Action',
click on 'Forward to Partner' > crash.
This commit is contained in:
Aaron Bohy
2017-08-11 10:29:56 +02:00
parent 870aa81ad9
commit 5fce37486a
2 changed files with 40 additions and 1 deletions
@@ -2922,7 +2922,7 @@ var BasicModel = AbstractModel.extend({
r._changes = _.defaults(value[2], r.data);
for (var name in r._changes) {
if (r._changes[name] === null) {
if (!r._changes[name]) {
continue;
}
var isFieldInView = name in r.fields;
@@ -958,6 +958,45 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('list in form: create with one2many with many2one (version 2)', function (assert) {
// This test simulates the exact same scenario as the previous one,
// except that the value for the many2one is explicitely set to false,
// which is stupid, but this happens, so we have to handle it
assert.expect(1);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'default_get') {
return $.when({p: [[0, 0, {display_name: 'new record', trululu: false}]]});
} else if (args.method === 'name_get') {
// This should not be called at all and thus is not accounted for
// in the assert.expect. If this is called, you broke this test.
assert.notOk(_.str.startsWith(args.args[0][0], 'virtual_'),
"should not call name_get for the m2o inside o2m which has no value");
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual($('td.o_data_cell:first').text(), 'new record',
"should have created the new record in the o2m with the correct name");
form.destroy();
});
QUnit.test('list in form: default_get with x2many create', function (assert) {
assert.expect(3);