summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-06-20 15:11:33 +0200
committerAaron Bohy <aab@odoo.com>2018-06-21 13:57:58 +0200
commitfdf615a55187ed14d81f99f09fdc790c5241e073 (patch)
tree88012ed70aeab46f9b2dbf0afab38deb62566163 /addons/web/static/tests/fields/relational_fields_tests.js
parent239d460ae5e0f6896f794befa37433211b12944f (diff)
[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.
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 9b42c518891..1147c1398aa 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -9219,7 +9219,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'};
@@ -9256,6 +9256,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);