diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-07-23 08:13:39 +0000 |
|---|---|---|
| committer | Julien Mougenot <jum@odoo.com> | 2020-07-31 08:04:57 +0000 |
| commit | dc8973fd6e44975fc79af184282434b0aa1c11aa (patch) | |
| tree | c37c5928735dc0542ba39dfd2f732c3ded89d022 /addons/web/static/tests/control_panel | |
| parent | 9dd2c7fdc8b593c0cfaa733351b0096cfc5e2f27 (diff) | |
[FIX] web: default operators for search fields
During the refactoring of the control panel (https://github.com/odoo/odoo/pull/41268)
a regression concerning the operator used for the fields set as
search_default was introduced: the default operator was fixed to '='
while it would have been necessary to take into consideration the
optional 'operator' attribute or the field types. Moreover, the default
operator associated to many2one fields when using autocompletion was
also mistakenly set to 'ilike' instead of '='. The present commit
restores the previous behavior.
closes odoo/odoo#55099
X-original-commit: 1f8e93fc590a6c7ef6b93953058f2dcd643ac620
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Co-authored-by: Julien Mougenot <jum@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/tests/control_panel')
| -rw-r--r-- | addons/web/static/tests/control_panel/control_panel_tests.js | 87 | ||||
| -rw-r--r-- | addons/web/static/tests/control_panel/favorite_menu_tests.js | 4 |
2 files changed, 74 insertions, 17 deletions
diff --git a/addons/web/static/tests/control_panel/control_panel_tests.js b/addons/web/static/tests/control_panel/control_panel_tests.js index 24744291cc9..c9e89387505 100644 --- a/addons/web/static/tests/control_panel/control_panel_tests.js +++ b/addons/web/static/tests/control_panel/control_panel_tests.js @@ -18,6 +18,75 @@ odoo.define('web.control_panel_tests', function (require) { } }, function () { + QUnit.test('default field operator', async function (assert) { + assert.expect(2); + + const fields = { + foo_op: { string: "Foo Op", type: "char", store: true, sortable: true, searchable: true }, + foo: { string: "Foo", type: "char", store: true, sortable: true, searchable: true }, + bar_op: { string: "Bar Op", type: "many2one", relation: 'partner', searchable: true }, + bar: { string: "Bar", type: "many2one", relation: 'partner', searchable: true }, + selec: { string: "Selec", type: "selection", selection: [['red', "Red"], ['black', "Black"]] }, + }; + const arch = ` + <search> + <field name="bar"/> + <field name="bar_op" operator="child_of"/> + <field name="foo"/> + <field name="foo_op" operator="="/> + <field name="selec"/> + </search>`; + const searchMenuTypes = []; + const params = { + cpModelConfig: { + arch, + fields, + context: { + show_filterC: true, + search_default_bar: 10, + search_default_bar_op: 10, + search_default_foo: "foo", + search_default_foo_op: "foo_op", + search_default_selec: 'red', + }, + searchMenuTypes, + }, + cpProps: { fields, searchMenuTypes }, + env: { + session: { + async rpc() { + return [[10, "Deco Addict"]]; + }, + }, + }, + }; + const controlPanel = await createControlPanel(params); + + assert.deepEqual( + cpHelpers.getFacetTexts(controlPanel).map(t => t.replace(/\s/g, "")), + [ + "BarDecoAddict", + "BarOpDecoAddict", + "Foofoo", + "FooOpfoo_op", + "SelecRed" + ] + ); + assert.deepEqual( + controlPanel.getQuery().domain, + [ + "&", "&", "&", "&", + ["bar", "=", 10], + ["bar_op", "child_of", 10], + ["foo", "ilike", "foo"], + ["foo_op", "=", "foo_op"], + ["selec", "=", "red"], + ] + ); + + controlPanel.destroy(); + }); + QUnit.module('Keyboard navigation'); QUnit.test('remove a facet with backspace', async function (assert) { @@ -146,21 +215,11 @@ odoo.define('web.control_panel_tests', function (require) { // view to emulate the behavior of fields_view_get() // [see ir.ui.view `_apply_group()`] - delete this.fields['bar']; - delete this.fields['date_field']; + delete this.fields.bar; + delete this.fields.date_field; - const arch = ` - <search> - <field name="foo"/> - <filter name="filterDate" string="Date" date="date_field" default_period="last_365_days" invisible="1" groups="base.group_system"/> - <filter name="groupByBar" string="Bar" context="{'group_by': 'bar'}" invisible="1" groups="base.group_system"/> - </search>`; const searchMenuTypes = []; const params = { - cpStoreConfig: { - viewInfo: { arch, fields: this.fields }, - searchMenuTypes - }, cpProps: { fields: this.fields, searchMenuTypes }, }; const controlPanel = await createControlPanel(params); @@ -176,7 +235,7 @@ odoo.define('web.control_panel_tests', function (require) { QUnit.test('groupby menu is not rendered if searchMenuTypes does not have groupBy', async function (assert) { assert.expect(2); - const arch = `<search/>`; + const arch = `<search/>`; const searchMenuTypes = ['filter']; const params = { cpModelConfig: { @@ -193,7 +252,5 @@ odoo.define('web.control_panel_tests', function (require) { controlPanel.destroy(); }); - - }); }); diff --git a/addons/web/static/tests/control_panel/favorite_menu_tests.js b/addons/web/static/tests/control_panel/favorite_menu_tests.js index d01afdfb063..bf2ec76d564 100644 --- a/addons/web/static/tests/control_panel/favorite_menu_tests.js +++ b/addons/web/static/tests/control_panel/favorite_menu_tests.js @@ -371,7 +371,7 @@ odoo.define('web.favorite_menu_tests', function (require) { search: function (searchQuery) { const { domain, groupBy, timeRanges } = searchQuery; if (firstSearch) { - assert.deepEqual(domain, [['foo', '=', 'a']]); + assert.deepEqual(domain, [['foo', 'ilike', 'a']]); assert.deepEqual(groupBy, ['date_field:month']); assert.deepEqual(timeRanges, { comparisonId: "previous_period", @@ -399,7 +399,7 @@ odoo.define('web.favorite_menu_tests', function (require) { const { domain, groupBy, timeRanges } = controlPanel.getQuery(); assert.deepEqual(domain, [ "&", - ["foo", "=", "a"], + ["foo", "ilike", "a"], "&", ["date_field", ">=", "2019-01-01"], ["date_field", "<=", "2019-12-31"] |
