[FIX] web : error when filter has empty selection
Steps to reproduce: - install approvals - in the approvals app go to filters>add custome filter> approval type Issue: - traceback Cause: - When no other module is installed, there is nothing to display under the approval type filter. Even if the field is not required, the javascript try to access the first element of the selection array to auto-fill the menu. Solution: Add a check, if empty and not required, do not display it and leave the field empty opw-2895516 closes odoo/odoo#96617 X-original-commit: 7fdbb1783ec65919a709e5fcac111994d0eb3cd5 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> Signed-off-by: Vranckx Florian (flvr) <flvr@odoo.com> Co-authored-by: nle-odoo <nle@odoo.com>
This commit is contained in:
co-authored by
nle-odoo
parent
2b29fc2dc8
commit
f294079a89
@@ -125,8 +125,13 @@ odoo.define('web.CustomFilterItem', function (require) {
|
||||
}
|
||||
break;
|
||||
case 'selection':
|
||||
const [firstValue] = this.fields[condition.field].selection[0];
|
||||
condition.value = firstValue;
|
||||
if (this.fields[condition.field].selection.length) {
|
||||
const [firstValue] = this.fields[condition.field].selection[0];
|
||||
condition.value = firstValue;
|
||||
}
|
||||
else {
|
||||
condition.value = "";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
condition.value = "";
|
||||
|
||||
@@ -195,6 +195,36 @@ odoo.define('web.filter_menu_generator_tests', function (require) {
|
||||
await testUtils.fields.editSelect(target.querySelector('.o_generator_menu_value select'), 'white');
|
||||
await cpHelpers.applyFilter(target);
|
||||
});
|
||||
QUnit.test('selection field: no value', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.fields.color.selection = [];
|
||||
let expectedFilters;
|
||||
class MockedSearchModel extends ActionModel {
|
||||
dispatch(method, ...args) {
|
||||
assert.strictEqual(method, 'createNewFilters');
|
||||
const preFilters = args[0];
|
||||
assert.deepEqual(preFilters, expectedFilters);
|
||||
}
|
||||
}
|
||||
const searchModel = new MockedSearchModel();
|
||||
const cfi = await createComponent(CustomFilterItem, {
|
||||
props: {
|
||||
fields: this.fields,
|
||||
},
|
||||
env: { searchModel },
|
||||
});
|
||||
|
||||
// Default value
|
||||
expectedFilters = [{
|
||||
description: 'Color is ""',
|
||||
domain: '[["color","=",""]]',
|
||||
type: 'filter',
|
||||
}];
|
||||
await toggleAddCustomFilterStandalone(cfi);
|
||||
await testUtils.fields.editSelect(cfi.el.querySelector('.o_generator_menu_field'), 'color');
|
||||
await cpHelpers.applyFilter(cfi);
|
||||
})
|
||||
|
||||
QUnit.test('adding a simple filter works', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
Reference in New Issue
Block a user