diff options
| author | Joseph Caburnay <jcb@odoo.com> | 2020-07-06 14:19:26 +0000 |
|---|---|---|
| committer | Joseph Caburnay <jcb@odoo.com> | 2020-07-09 12:43:36 +0000 |
| commit | 259cf453463448fdd25b5d29f45e0d3e8eb18382 (patch) | |
| tree | 1b3be467819b2ea5452911b02bde629f43352158 /addons/web | |
| parent | 4c4f11580f8d5e551f48337c82bd2376f53042f6 (diff) | |
[FIX] web: trying to create record based on name_create w/o _rec_name
There are orm models that don't have _rec_name defined. The orm doesn't
allow creation of record via name_create if _rec_name is not defined in
the model. This commit considers this fact, such that if name_create
returns false, we don't proceed on displaying the non-existing record.
Note: _rec_name defaults to 'name' if not specified so only few models
don't have _rec_name.
closes odoo/odoo#54270
Task-id: 2285036
X-original-commit: 676c2b8e4fdf7347d44bc5afb7ca51d39338a527
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 6 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields/field_many2one_tests.js | 25 |
2 files changed, 31 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index d8bab11884b..adefa997e99 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1632,6 +1632,12 @@ var BasicModel = AbstractModel.extend({ args: [data.display_name], context: this._getContext(record, {fieldName: fieldName, viewType: options.viewType}), }); + // Check if a record is really created. Models without defined + // _rec_name cannot create record based on name_create. + if (!result) { + record._changes[fieldName] = false; + return Promise.resolve(); + } data = {id: result[0], display_name: result[1]}; } 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 98ff6a47925..eaccd0e8ee5 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 @@ -1184,6 +1184,31 @@ QUnit.module('fields', {}, function () { form.destroy(); }); + QUnit.test('form: quick create for field that returns false after name_create call', async function (assert) { + assert.expect(3); + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form><field name="trululu"/></form>', + mockRPC: function (route, args) { + const result = this._super.apply(this, arguments); + if (args.method === 'name_create') { + assert.step('name_create'); + // Resolve the name_create call to false. This is possible if + // _rec_name for the model of the field is unassigned. + return Promise.resolve(false); + } + return result; + }, + }); + await testUtils.fields.many2one.searchAndClickItem('trululu', { search: 'beam' }); + assert.verifySteps(['name_create'], 'attempt to name_create'); + assert.strictEqual(form.$(".o_input_dropdown input").val(), "", + "the input should contain no text after search and click") + form.destroy(); + }); + QUnit.test('list: quick create then save directly', async function (assert) { assert.expect(8); |
