summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2019-11-07 07:51:51 +0000
committerAaron Bohy <aab@odoo.com>2020-03-09 14:14:39 +0000
commita9cebd5acbba40ae63aa9f986d9bab39b2112f92 (patch)
tree9e12efe671c7110e6d060919bf024ba3a30ac302 /addons/web/static/tests/fields/relational_fields
parentf129dff5a0094b07bba2f8886513cded0a2d21c6 (diff)
[FIX] web: handle nested one2manys and onchange
Let's assume the following scenario in a form view: - have a one2many field, say fieldA, displayed as a list, containing another one2many, fieldB, (no widget, thus displaying 'n record(s)') - the one2many list is not editable, so there is a sub form view, displaying fieldB as a list, and in this list some random field, say fieldC, is displayed - have a random field on the main form view, with an onchange to populate the one2many - set that random field s.t. the onchange returns something like fieldA: [[5], [0, 0, {fieldB: [[0, 0, {fieldC: 'value'}]]}]] - there is now a record in fieldA's list, displaying '1 record' as value for fieldB - click on that record to open it in a form view (dialog) - in the dialog, in fieldB's list, we expect to have a single row displaying 'value' as value for fieldC Before this rev., it crashed when opening the record in the dialog, whether the form view was inline or not. The crash occured because fieldB was already in the list view, so datapoints already existed for it (a list datapoint, and record datapoints for records in the relation, in our example one record datapoint). However, those datapoints didn't have the fieldsInfo of the form view. When opening the form view, we added the fieldsInfo of the form to the datapoint of the record we opened, but we didn't recursively apply the fieldsInfo to its children. As a consequence, when rendering the list view for fieldB in the dialog, we haven't the information about fieldC, and it crashed. Note that if fieldB wasn't present in fieldA's list view, it worked fine because datapoints didn't exist before we opened the record in the dialog. Task 2120235
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields')
-rw-r--r--addons/web/static/tests/fields/relational_fields/field_one2many_tests.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
index ad68ede00d2..7b470cda22a 100644
--- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
+++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
@@ -5409,6 +5409,108 @@ QUnit.module('fields', {}, function () {
form.destroy();
});
+ QUnit.test('nested x2many (inline form view) and onchanges', async function (assert) {
+ assert.expect(6);
+
+ this.data.partner.onchanges.bar = function (obj) {
+ if (!obj.bar) {
+ obj.p = [[5], [0, 0, {
+ turtles: [[0, 0, {
+ turtle_foo: 'new turtle',
+ }]],
+ }]];
+ }
+ };
+
+ const form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: `<form>
+ <field name="bar"/>
+ <field name="p">
+ <tree>
+ <field name="turtles"/>
+ </tree>
+ <form>
+ <field name="turtles">
+ <tree>
+ <field name="turtle_foo"/>
+ </tree>
+ </field>
+ </form>
+ </field>
+ </form>`,
+ });
+
+ assert.containsNone(form, '.o_data_row');
+
+ await testUtils.dom.click(form.$('.o_field_widget[name=bar] input'));
+ assert.containsOnce(form, '.o_data_row');
+ assert.strictEqual(form.$('.o_data_row').text(), '1 record');
+
+ await testUtils.dom.click(form.$('.o_data_row:first'));
+
+ assert.containsOnce(document.body, '.modal .o_form_view');
+ assert.containsOnce(document.body, '.modal .o_form_view .o_data_row');
+ assert.strictEqual($('.modal .o_form_view .o_data_row').text(), 'new turtle');
+
+ form.destroy();
+ });
+
+ QUnit.test('nested x2many (non inline form view) and onchanges', async function (assert) {
+ assert.expect(6);
+
+ this.data.partner.onchanges.bar = function (obj) {
+ if (!obj.bar) {
+ obj.p = [[5], [0, 0, {
+ turtles: [[0, 0, {
+ turtle_foo: 'new turtle',
+ }]],
+ }]];
+ }
+ };
+
+ const form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: `
+ <form>
+ <field name="bar"/>
+ <field name="p">
+ <tree>
+ <field name="turtles"/>
+ </tree>
+ </field>
+ </form>`,
+ archs: {
+ 'partner,false,form': `
+ <form>
+ <field name="turtles">
+ <tree>
+ <field name="turtle_foo"/>
+ </tree>
+ </field>
+ </form>`,
+ },
+ });
+
+ assert.containsNone(form, '.o_data_row');
+
+ await testUtils.dom.click(form.$('.o_field_widget[name=bar] input'));
+ assert.containsOnce(form, '.o_data_row');
+ assert.strictEqual(form.$('.o_data_row').text(), '1 record');
+
+ await testUtils.dom.click(form.$('.o_data_row:first'));
+
+ assert.containsOnce(document.body, '.modal .o_form_view');
+ assert.containsOnce(document.body, '.modal .o_form_view .o_data_row');
+ assert.strictEqual($('.modal .o_form_view .o_data_row').text(), 'new turtle');
+
+ form.destroy();
+ });
+
QUnit.test('one2many (who contains display_name) with tree view and without form view', async function (assert) {
assert.expect(1);