[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#59044

X-original-commit: 1400b0b9f46a86254c166b422a0b23ed3b3c7a24
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Simon Genin (ges)
2020-10-03 11:08:35 +00:00
parent 71549030c7
commit 2cb2e9c2a2
2 changed files with 33 additions and 1 deletions
@@ -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,
@@ -2568,6 +2568,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);