diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-05-29 11:22:35 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-05-29 20:53:40 +0200 |
| commit | 45bce324f34eeb8ee69e028e0d20b08d998c0eef (patch) | |
| tree | 221eea130b9bb7d2987f2b2c93526ef3ab675f18 /addons/web/static/tests/fields | |
| parent | 5788ee8a1cc903431b100a3861686cfa606aa620 (diff) | |
[FIX] web: BasicModel: correctly apply x2many changes
Suppose that we have a form view with a one2many list (non
editable) containing a record. In edit mode, the user clicks on
that record to edit it in a form view (in a dialog). In this form
view, there is an x2many field that isn't in the list. Before this
rev., it crashed when the user clicked on 'Save' in the dialog
after editing the value of the x2many.
This was because the basic model didn't use the correct fieldsInfo
in that case (it use the fieldsInfo of the list view instead of the
one of the form view, and the x2many field isn't in the list).
Also ensures that the record is correctly saved even if editing the
x2many is the only change done, as this wasn't the case before.
Diffstat (limited to 'addons/web/static/tests/fields')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 57 |
1 files changed, 57 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 66c825cb3c7..6003cef3d0c 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -3103,6 +3103,63 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('one2many with x2many in form view (but not in list view)', function (assert) { + assert.expect(1); + + // avoid error when saving the edited related record (because the + // related x2m field is unknown in the inline list view) + // also ensure that the changes are correctly saved + + this.data.turtle.fields.o2m = {string: "o2m", type: "one2many", relation: 'user'}; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<group>' + + '<field name="turtles">' + + '<tree>' + + '<field name="turtle_foo"/>' + + '</tree>' + + '</field>' + + '</group>' + + '</form>', + res_id: 1, + archs: { + "turtle,false,form": '<form string="Turtles">' + + '<field name="partner_ids" widget="many2many_tags"/>' + + '</form>', + }, + viewOptions: { + mode: 'edit', + }, + mockRPC: function (route, args) { + if (args.method === 'write') { + assert.deepEqual(args.args[1].turtles, [[1, 2, { + partner_ids: [[6, false, [2, 4, 1]]], + }]]); + } + return this._super.apply(this, arguments); + }, + }); + + form.$('.o_data_row:first').click(); // edit first record + + var $input = $('.modal .o_field_many2manytags input'); + $input.click(); // opens the dropdown + $input.autocomplete('widget').find('li').click(); // add 'first record' + + // add a many2many tag and save + $('.modal .o_field_x2many_list_row_add a').click(); + $('.modal .o_field_widget[name=name]').val('test').trigger('input'); + $('.modal .modal-footer .btn-primary').click(); // save + + form.$buttons.find('.o_form_button_save').click(); + + form.destroy(); + }); + QUnit.test('one2many (who contains display_name) with tree view and without form view', function (assert) { assert.expect(1); |
