[FIX] web: search many2one fields with correct value
Before this commit, searching a many2one field in the search bar would create a domain with a parsed version of the input string. However the parser of m2o fields returns a number (ID) and would consistently return 'NaN'. Now, raw values are taken as is when searching with many2one fields. Task 2239254 closes odoo/odoo#50410 X-original-commit: bac74010daae868da474de9439bc7027d9206e38 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
This commit is contained in:
@@ -239,16 +239,25 @@ odoo.define('web.SearchBar', function (require) {
|
||||
const { type } = this.props.fields[source.fieldName];
|
||||
const parser = field_utils.parse[type];
|
||||
let parsedValue;
|
||||
if (['date', 'datetime'].includes(type)) {
|
||||
const parsedDate = parser(rawValue, { type }, { timezone: true });
|
||||
const dateFormat = type === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
|
||||
const momentValue = moment(parsedDate, dateFormat);
|
||||
if (!momentValue.isValid()) {
|
||||
throw new Error('Invalid date');
|
||||
switch (type) {
|
||||
case 'date':
|
||||
case 'datetime': {
|
||||
const parsedDate = parser(rawValue, { type }, { timezone: true });
|
||||
const dateFormat = type === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
|
||||
const momentValue = moment(parsedDate, dateFormat);
|
||||
if (!momentValue.isValid()) {
|
||||
throw new Error('Invalid date');
|
||||
}
|
||||
parsedValue = parsedDate.toJSON();
|
||||
break;
|
||||
}
|
||||
case 'many2one': {
|
||||
parsedValue = rawValue;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
parsedValue = parser(rawValue);
|
||||
}
|
||||
parsedValue = parsedDate.toJSON();
|
||||
} else {
|
||||
parsedValue = parser(rawValue);
|
||||
}
|
||||
return parsedValue;
|
||||
}
|
||||
|
||||
@@ -484,5 +484,49 @@ odoo.define('web.search_bar_tests', function (require) {
|
||||
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('select autocompleted many2one', async function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
const archs = Object.assign({}, this.archs, {
|
||||
'partner,false,search': `
|
||||
<search>
|
||||
<field name="foo"/>
|
||||
<field name="birthday"/>
|
||||
<field name="birth_datetime"/>
|
||||
<field name="bar" operator="child_of"/>
|
||||
</search>`,
|
||||
});
|
||||
const actionManager = await createActionManager({
|
||||
actions: this.actions,
|
||||
archs,
|
||||
data: this.data,
|
||||
async mockRPC(route, { domain }) {
|
||||
if (route === '/web/dataset/search_read') {
|
||||
assert.step(JSON.stringify(domain));
|
||||
}
|
||||
return this._super(...arguments);
|
||||
},
|
||||
});
|
||||
await actionManager.doAction(1);
|
||||
|
||||
await cpHelpers.editSearch(actionManager, "rec");
|
||||
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li:last-child'));
|
||||
|
||||
await cpHelpers.removeFacet(actionManager, 0);
|
||||
|
||||
await cpHelpers.editSearch(actionManager, "rec");
|
||||
await testUtils.dom.click(actionManager.el.querySelector('.o_expand'));
|
||||
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li.o_menu_item.o_indent'));
|
||||
|
||||
assert.verifySteps([
|
||||
'[]',
|
||||
'[["bar","child_of","rec"]]', // Incomplete string -> Name search
|
||||
'[]',
|
||||
'[["bar","child_of",1]]', // Suggestion select -> Specific ID
|
||||
]);
|
||||
|
||||
actionManager.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user