diff options
| author | Simon Genin (ges) <ges@odoo.com> | 2020-09-16 13:13:39 +0000 |
|---|---|---|
| committer | Simon Genin (ges) <ges@odoo.com> | 2020-10-02 15:48:42 +0000 |
| commit | 1400b0b9f46a86254c166b422a0b23ed3b3c7a24 (patch) | |
| tree | 6421fdd88202daaaea9bcd7132389f174e94562e | |
| parent | 44c48501a120b3e8e96dcc82bab701b071650494 (diff) | |
[FIX] web: reference field calls name_create
An older commit (50bf8309) had refactor part of the basic field _applyX2ManyOperations.
During this refactor, the reference field was forgotten to be included
in a condition that made the field no longer do the quick create behavior.
The name_create function in the backend was no longer called.
Adds a test for the reference field checking the call to the name_create
function and fixes the problem.
Task id 2322048
closes odoo/odoo#59013
X-original-commit: e7d4baa3d52dc73c9631365801fbe41a4d54e3a1
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 3 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/relational_fields_tests.js | 31 |
2 files changed, 33 insertions, 1 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 bb599b2e859..3b750fc743a 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1583,7 +1583,8 @@ var BasicModel = AbstractModel.extend({ const field = record.fields[fieldName]; const coModel = field.type === 'reference' ? data.model : field.relation; - if (field.type === 'many2one' && !data.id && data.display_name) { + const allowedTypes = ['many2one', 'reference']; + if (allowedTypes.includes(field.type) && !data.id && data.display_name) { // only display_name given -> do a name_create const result = await this._rpc({ model: coModel, diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 487e953003f..6ef0e402562 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -2545,6 +2545,37 @@ QUnit.module('relational_fields', { QUnit.module('FieldReference'); + QUnit.test('Reference field can quick create models', async function (assert) { + assert.expect(8); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: `<form><field name="reference"/></form>`, + mockRPC(route, args) { + assert.step(args.method || route); + return this._super(...arguments); + }, + }); + + await testUtils.fields.editSelect(form.$('select'), 'partner'); + await testUtils.fields.many2one.searchAndClickItem('reference', {search: 'new partner'}); + await testUtils.form.clickSave(form); + + assert.verifySteps([ + 'onchange', + 'name_search', // for the select + 'name_search', // for the spawned many2one + 'name_create', + 'create', + 'read', + 'name_get' + ], "The name_create method should have been called"); + + form.destroy(); + }); + QUnit.test('Reference field in modal readonly mode', async function (assert) { assert.expect(4); |
