Skip to content

Commit

Permalink
[FIX] web: onchange in non inline one2many list
Browse files Browse the repository at this point in the history
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. 13c8851 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 13c8851.

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.
  • Loading branch information
aab-odoo committed Jun 21, 2018
1 parent b188d1f commit 8ace39f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion addons/web/static/src/js/views/basic/basic_model.js
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions addons/web/static/src/js/views/form/form_view.js
Expand Up @@ -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);
}));
Expand Down
49 changes: 48 additions & 1 deletion addons/web/static/tests/fields/relational_fields_tests.js
Expand Up @@ -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'};
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 8ace39f

Please sign in to comment.