diff options
| author | Xavier ALT <xal@odoo.com> | 2020-06-10 23:57:42 +0000 |
|---|---|---|
| committer | Xavier ALT <xal@odoo.com> | 2020-06-25 15:01:29 +0000 |
| commit | 19033e804ec243c593c9549a3f0024fbf2230ab1 (patch) | |
| tree | 778c915c3604d3923a0681502f0d14de1b01d2ff /addons/web/static | |
| parent | 6162a0fee38b6776567a0a324783cbdce38f0f43 (diff) | |
[FIX] web: in search view, use modifiers to determine if filter is invisible
In search view, the "invisible" attribute can use complex expression,
and so we must rely on the "modifiers" attribute set by the ir.ui.view
post-processing to determine if a filter should be invisible or not.
For example, considering the context {'hide_myfilter': False}, the
following view:
```xml
<search>
...
<filter name="myfilter" string="My Filter" invisible="context.get('hide_myfilter')"/>
...
</search>
```
Will be returned as such by the server:
```xml
<search>
...
<filter name="myfilter" string="My Filter" invisible="context.get('hide_myfilter')"
modifiers="{"invisible": false}"/>
...
</search>
```
After this commit, the filter "myfilter" will correctly be shown.
OPW-2243639
closes odoo/odoo#53690
X-original-commit: 00969326e24dadd9b3f6e026789a1e575dd1c8dc
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
Signed-off-by: Xavier ALT <xavieralt@users.noreply.github.com>
Diffstat (limited to 'addons/web/static')
3 files changed, 25 insertions, 2 deletions
diff --git a/addons/web/static/src/js/control_panel/control_panel_model.js b/addons/web/static/src/js/control_panel/control_panel_model.js index e1eb9c8da1a..67b9c999f74 100644 --- a/addons/web/static/src/js/control_panel/control_panel_model.js +++ b/addons/web/static/src/js/control_panel/control_panel_model.js @@ -915,7 +915,7 @@ odoo.define('web.ControlPanelModel', function (require) { filter.isDefault = attrs.isDefault; } filter.description = attrs.string || attrs.help || attrs.name || attrs.domain || 'Ω'; - if (attrs.invisible) { + if (JSON.parse(attrs.modifiers || '{}').invisible) { filter.invisible = true; } switch (filter.type) { 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 af6704da7af..84000e7c616 100644 --- a/addons/web/static/tests/control_panel/control_panel_tests.js +++ b/addons/web/static/tests/control_panel/control_panel_tests.js @@ -53,7 +53,7 @@ odoo.define('web.control_panel_tests', function (require) { QUnit.test('fields and filters with groups/invisible attribute', async function (assert) { // navigation and automatic menu closure don't work here (i don't know why yet) --> // should be tested separatly - assert.expect(14); + assert.expect(16); const arch = ` <search> @@ -61,6 +61,7 @@ odoo.define('web.control_panel_tests', function (require) { <field name="foo" string="Foo A"/> <filter name="filterA" string="FA" domain="[]"/> <filter name="filterB" string="FB" invisible="1" domain="[]"/> + <filter name="filterC" string="FC" invisible="not context.get('show_filterC')" domain="[]"/> <filter name="groupByA" string="GA" context="{ 'group_by': 'date_field:day' }"/> <filter name="groupByB" string="GB" context="{ 'group_by': 'date_field:day' }" invisible="1"/> </search>`; @@ -69,6 +70,7 @@ odoo.define('web.control_panel_tests', function (require) { cpStoreConfig: { viewInfo: { arch, fields: this.fields }, actionContext: { + show_filterC: true, search_default_display_name: 'value', search_default_filterB: true, search_default_groupByB: true @@ -98,6 +100,7 @@ odoo.define('web.control_panel_tests', function (require) { selectorContainsValue('.o_menu_item a', "FA", true); selectorContainsValue('.o_menu_item a', "FB", false); + selectorContainsValue('.o_menu_item a', "FC", true); await cpHelpers.toggleGroupByMenu(controlPanel); @@ -117,6 +120,7 @@ odoo.define('web.control_panel_tests', function (require) { selectorContainsValue('.o_menu_item a', "FA", true); selectorContainsValue('.o_menu_item a', "FB", false); + selectorContainsValue('.o_menu_item a', "FC", true); await cpHelpers.toggleGroupByMenu(controlPanel); diff --git a/addons/web/static/tests/helpers/test_utils_create.js b/addons/web/static/tests/helpers/test_utils_create.js index 341ace4fba8..17debd413d0 100644 --- a/addons/web/static/tests/helpers/test_utils_create.js +++ b/addons/web/static/tests/helpers/test_utils_create.js @@ -191,6 +191,25 @@ odoo.define('web.test_utils_create', function (require) { fields: {}, }, params.cpProps); + if (config.viewInfo && config.viewInfo.arch && config.viewInfo.fields) { + const { arch, fields } = config.viewInfo; + const model = "__mockmodel__"; + const serverParams = { + model, + data: { [model]: { fields, records: [] } }, + }; + const mockServer = await testUtilsMock.addMockEnvironment( + new Widget(), + serverParams, + ); + Object.assign(config.viewInfo, testUtilsMock.fieldsViewGet(mockServer, { + arch, + fields, + model, + viewOptions: { context: config.actionContext }, + })); + } + class Parent extends Component { constructor() { super(); |
