[FIX] web: edit (list editable) one2manys inside one2manys

Since rev. https://github.com/odoo/odoo/commit/ebd17217c4e7e9ff06d97028de64fb2fc44d6266
the attribute `_editionViewType` has been introduced to use the modifiers from the correct
one2many view type.

This attribute wasn't correctly populated if multiple one2manys were imbricated. The
first view type (form in the test case) was set for the second one2many even though
the view type was list. This was due to the `visitChildren` function use that browses
through all levels (and not only the first one).

To reproduce the bug before this rev. you could try to create a new survey, add a
question (one2many) then select multiple choice and add an answer (one2many editable).
This commit is contained in:
Martin Geubelle
2017-08-16 17:27:48 +02:00
parent ab2e71d9fc
commit 68d0ca03da
2 changed files with 60 additions and 5 deletions
@@ -777,14 +777,15 @@ var BasicModel = AbstractModel.extend({
if (newValue instanceof Array) {
rec._savePoint = newValue.slice(0);
} else {
// save the viewType of edition, so that the correct readonly modifiers
// can be evaluated when the record will be saved
for (var fieldName in (rec._changes || {})) {
rec._editionViewType[fieldName] = options.viewType;
}
rec._savePoint = _.extend({}, newValue);
}
});
// save the viewType of edition, so that the correct readonly modifiers
// can be evaluated when the record will be saved
_.each((record._changes || {}), function (value, fieldName) {
record._editionViewType[fieldName] = options.viewType;
});
}
var shouldReload = 'reload' in options ? options.reload : true;
var method = self.isNew(record_id) ? 'create' : 'write';
@@ -3743,6 +3743,60 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('one2manys (list editable) inside one2manys are saved correctly', function (assert) {
assert.expect(3);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="p">' +
'<tree>' +
'<field name="p"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
archs: {
"partner,false,form": '<form>' +
'<field name="p">' +
'<tree editable="top">' +
'<field name="display_name"/>' +
'</tree>' +
'</field>' +
'</form>'
},
mockRPC: function (route, args) {
if (args.method === 'create') {
assert.deepEqual(args.args[0].p,
[[0, false, {
p: [[0, false, {display_name: "xtv"}]],
}]],
"create should be called with the correct arguments");
}
return this._super.apply(this, arguments);
},
});
// add a o2m subrecord
form.$('.o_field_x2many_list_row_add a').click();
$('.modal-body .o_field_one2many .o_field_x2many_list_row_add a').click();
$('.modal-body input').val('xtv').trigger('input');
$('.modal-footer button:first').click(); // save & close
assert.strictEqual($('.modal').length, 0,
"dialog should be closed");
var row = form.$('.o_field_one2many .o_list_view .o_data_row');
assert.strictEqual(row.children()[0].textContent, '1 record',
"the cell should contains the number of record: 1");
form.$buttons.find('.o_form_button_save').click();
form.destroy();
});
QUnit.test('*_view_ref in context are passed correctly', function (assert) {
var done = assert.async();
assert.expect(4);