diff options
| author | Aaron Bohy <aab@odoo.com> | 2020-05-08 12:17:26 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-05-08 15:38:06 +0000 |
| commit | 8000e895cd33cb622919fe6f48934cb692728bc2 (patch) | |
| tree | 5ae23458a5076b49a1060bab0f03d3aa71cdcdc2 /addons/web/static/tests/fields | |
| parent | 23441987651865293d7847be918d2e7bcdcaf521 (diff) | |
[FIX] web: failing quick create in m2o inside x2m
Write something in a many2one field, and click on 'Create "..."'
to quick create a record with the given value (name_create). When
the name_create fails (e.g. because there are mandatory fields in
the model), we open a form view.
Before this commit, when this happened for many2one fields inside
x2many editable lists, it crashed, since [1].
[1] 50bf8309f88fb6c8d8e27b14d40450e92e5a4e4e
closes odoo/odoo#50948
X-original-commit: 43c513306094444ff25ad98584b426ddb8a3b525
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web/static/tests/fields')
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields/field_many2one_tests.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js index b5efdf3af48..fc95fda39d4 100644 --- a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js +++ b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js @@ -2212,6 +2212,80 @@ QUnit.module('fields', {}, function () { form.destroy(); }); + QUnit.test('failing quick create on a many2one', async function (assert) { + assert.expect(4); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form><field name="product_id"/></form>', + archs: { + 'product,false,form': '<form><field name="name"/></form>', + }, + mockRPC(route, args) { + if (args.method === 'name_create') { + return Promise.reject(); + } + if (args.method === 'create') { + assert.deepEqual(args.args[0], { name: 'xyz' }); + } + return this._super(...arguments); + }, + }); + + await testUtils.fields.many2one.searchAndClickItem('product_id', { + search: 'abcd', + item: 'Create "abcd"', + }); + assert.containsOnce(document.body, '.modal .o_form_view'); + assert.strictEqual($('.o_field_widget[name=name]').val(), 'abcd'); + + await testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), 'xyz'); + await testUtils.dom.click($('.modal .modal-footer .btn-primary')); + assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), 'xyz'); + + form.destroy(); + }); + + QUnit.test('failing quick create on a many2one inside a one2many', async function (assert) { + assert.expect(4); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form><field name="p"/></form>', + archs: { + 'partner,false,list': '<tree editable="bottom"><field name="product_id"/></tree>', + 'product,false,form': '<form><field name="name"/></form>', + }, + mockRPC(route, args) { + if (args.method === 'name_create') { + return Promise.reject(); + } + if (args.method === 'create') { + assert.deepEqual(args.args[0], { name: 'xyz' }); + } + return this._super(...arguments); + }, + }); + + await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + await testUtils.fields.many2one.searchAndClickItem('product_id', { + search: 'abcd', + item: 'Create "abcd"', + }); + assert.containsOnce(document.body, '.modal .o_form_view'); + assert.strictEqual($('.o_field_widget[name=name]').val(), 'abcd'); + + await testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), 'xyz'); + await testUtils.dom.click($('.modal .modal-footer .btn-primary')); + assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), 'xyz'); + + form.destroy(); + }); + QUnit.test('slow create on a many2one', async function (assert) { assert.expect(11); |
