summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-02-20 11:01:22 +0100
committerAaron Bohy <aab@odoo.com>2018-02-23 10:01:39 +0100
commitad1cceb4fbd2f054af647833bd34e4e06012bb6c (patch)
tree2ff88a9dd911149e163d3026f5b36d96e0d11a20 /addons/web/static/tests
parent8a29e37ddaf29d2736394762469b410d84dd583b (diff)
[FIX] web: one2many and onchange corner case issue
Let's assume a one2many list view inside a form view, displaying a single char field A. There is an onchange on the form view returning a command 0 (CREATE) for the one2many. The command 0 only specifies a value for field A. The one2many list isn't editable, so when a sub-record is clicked, it is open in a form view (in a dialog). In this form view, an x2many field B is displayed in a sub list or kanban view. Before this rev., it crashed when the user tried to open the created one2many sub-record (returned by the onchange) in the form view, because of the presence of the x2many field B, which wasn't correctly processed by the BasicModel (its value was undefined, whereas it must be a valid, empty, dataPoint). Moreover, the limit of the x2many field B wasn't set, so a pager was displayed as soon as it contained at least one record. Fixes #22050
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 4f7041ad2d5..89764ce319b 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -3063,6 +3063,108 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('onchange on one2many containing x2many in form view', function (assert) {
+ assert.expect(16);
+
+ this.data.partner.onchanges = {
+ foo: function (obj) {
+ obj.turtles = [[0, false, {turtle_foo: 'new record'}]];
+ },
+ };
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form>' +
+ '<field name="foo"/>' +
+ '<field name="turtles">' +
+ '<tree>' +
+ '<field name="turtle_foo"/>' +
+ '</tree>' +
+ '<form>' +
+ '<field name="partner_ids">' +
+ '<tree editable="top">' +
+ '<field name="foo"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>' +
+ '</field>' +
+ '</form>',
+ archs: {
+ 'partner,false,list': '<tree><field name="foo"/></tree>',
+ 'partner,false,search': '<search></search>',
+ },
+ });
+
+ assert.strictEqual(form.$('.o_data_row').length, 1,
+ "the onchange should have created one record in the relation");
+
+ // open the created o2m record in a form view, and add a m2m subrecord
+ // in its relation
+ form.$('.o_data_row').click();
+
+ assert.strictEqual($('.modal').length, 1, "should have opened a dialog");
+ assert.strictEqual($('.modal .o_data_row').length, 0,
+ "there should be no record in the one2many in the dialog");
+
+ // add a many2many subrecord
+ $('.modal .o_field_x2many_list_row_add a').click();
+
+ assert.strictEqual($('.modal').length, 2,
+ "should have opened a second dialog");
+
+ // select a many2many subrecord
+ $('.modal:nth(1) .o_list_view .o_data_cell:first').click();
+
+ assert.strictEqual($('.modal').length, 1,
+ "second dialog should be closed");
+ assert.strictEqual($('.modal .o_data_row').length, 1,
+ "there should be one record in the one2many in the dialog");
+ assert.notOk($('.modal .o_x2m_control_panel .o_cp_pager div').is(':visible'),
+ 'm2m pager should be hidden');
+
+ // click on 'Save & Close'
+ $('.modal .modal-footer .btn-primary:first').click();
+
+ assert.strictEqual($('.modal').length, 0, "dialog should be closed");
+
+ // reopen o2m record, and another m2m subrecord in its relation, but
+ // discard the changes
+ form.$('.o_data_row').click();
+
+ assert.strictEqual($('.modal').length, 1, "should have opened a dialog");
+ assert.strictEqual($('.modal .o_data_row').length, 1,
+ "there should be one record in the one2many in the dialog");
+
+ // add another m2m subrecord
+ $('.modal .o_field_x2many_list_row_add a').click();
+
+ assert.strictEqual($('.modal').length, 2,
+ "should have opened a second dialog");
+
+ $('.modal:nth(1) .o_list_view .o_data_cell:first').click();
+
+ assert.strictEqual($('.modal').length, 1,
+ "second dialog should be closed");
+ assert.strictEqual($('.modal .o_data_row').length, 2,
+ "there should be two records in the one2many in the dialog");
+
+ // click on 'Discard'
+ $('.modal .modal-footer .btn-default').click();
+
+ assert.strictEqual($('.modal').length, 0, "dialog should be closed");
+
+ // reopen o2m record to check that second changes have properly been discarded
+ form.$('.o_data_row').click();
+
+ assert.strictEqual($('.modal').length, 1, "should have opened a dialog");
+ assert.strictEqual($('.modal .o_data_row').length, 1,
+ "there should be one record in the one2many in the dialog");
+
+ form.destroy();
+ });
+
QUnit.test('embedded one2many with handle widget with minimum setValue calls', function (assert) {
var done = assert.async();
assert.expect(20);