[FIX] web: onchange in non inline one2many list

Let's assume a one2many list with two fields A and B, and an
onchange on A that sets B. Before this rev., on new records, the
onchange was only triggered if the one2many list was defined
inline.

Rev. 13c885195 was an attempt to fix the onchange issue in x2manys
with non inline views, but it only worked on existing records. This
rev. fixes the problem for both cases (existing and new records),
and thus reverts the fix of 13c885195.

The idea of this fix is to make both cases behave similarly, w.r.t.
fields and viewFields stuff in the fieldsView. In the inline case
(like in the main view case), fields and viewFields are the same.
In the non inline case, viewFields contained more information than
fields. As fields is used everywhere in BasicModel (and viewFields
is basically ignored), the fix is to set fields to viewFields.
This commit is contained in:
Aaron Bohy
2018-06-21 13:58:52 +02:00
parent b188d1fc1f
commit 8ace39f8bc
3 changed files with 50 additions and 2 deletions
@@ -2567,7 +2567,7 @@ var BasicModel = AbstractModel.extend({
count: ids.length,
context: record.context,
fieldsInfo: fieldsInfo,
fields: view ? view.viewFields : fieldInfo.relatedFields,
fields: view ? view.fields : fieldInfo.relatedFields,
limit: fieldInfo.limit,
modelName: field.relation,
res_ids: ids,
@@ -100,6 +100,7 @@ var FormView = BasicView.extend({
for (var viewName in views) {
// clone to make runbot green?
attrs.views[viewName] = self._processFieldsView(views[viewName], viewName);
attrs.views[viewName].fields = attrs.views[viewName].viewFields;
}
self._setSubViewLimit(attrs);
}));
@@ -9275,7 +9275,7 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('onchange in a one2Many, but not in main record, with non inline view', function (assert) {
QUnit.test('onchange in a one2many with non inline view on an existing record', function (assert) {
assert.expect(6);
this.data.partner.fields.sequence = {string: 'Sequence', type: 'integer'};
@@ -9312,6 +9312,53 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('onchange in a one2many with non inline view on a new record', function (assert) {
assert.expect(8);
this.data.turtle.onchanges = {
display_name: function (obj) {
if (obj.display_name) {
obj.turtle_int = 44;
}
},
};
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="turtles"/></form>',
archs: {
'turtle,false,list': '<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="turtle_int"/>' +
'</tree>',
},
mockRPC: function (route, args) {
assert.step(args.method || route);
return this._super.apply(this, arguments);
},
});
// add a row and trigger the onchange
form.$('.o_field_x2many_list_row_add a').click();
form.$('.o_data_row .o_field_widget[name=display_name]').val('a name').trigger('input');
assert.strictEqual(form.$('.o_data_row .o_field_widget[name=turtle_int]').val(), "44",
"should have triggered the onchange");
assert.verifySteps([
'load_views', // load sub list
'default_get', // main record
'onchange', // main record
'default_get', // sub record
'onchange', // sub record
'onchange', // edition of display_name of sub record
]);
form.destroy();
});
QUnit.test('add a line, edit it and "Save & New"', function (assert) {
assert.expect(5);