diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-05-03 09:34:57 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-05-05 12:04:19 +0000 |
| commit | 9c2a0f1db7654b2822b0c6c2703be3583fd92428 (patch) | |
| tree | ae515533a60e7a30e3a0b3a4383dfdb0079cedc6 | |
| parent | a8c54b40cd7db9b417764a17624bd1362ae38d63 (diff) | |
[FIX] web: no confusion betweed false and 'false'
In the search panel, if a select multi was grouped by a field that can
take the value 'false' (like a char field), that value would be confused
with the value false and the group 'false' would never be
displayed (its values would be put in the group false).
This commit avoids that situation by using JSON.stringify instead of
the implicit stringification done when using a value as an object key.
closes odoo/odoo#50647
X-original-commit: 5b19e6c13b636d108e8aa1a09f01124fdb38a577
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
| -rw-r--r-- | addons/web/static/src/js/views/search_panel.js | 4 | ||||
| -rw-r--r-- | addons/web/static/tests/views/search_panel_tests.js | 50 |
2 files changed, 52 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/search_panel.js b/addons/web/static/src/js/views/search_panel.js index 6a1d8381fb7..b15411da2a7 100644 --- a/addons/web/static/src/js/views/search_panel.js +++ b/addons/web/static/src/js/views/search_panel.js @@ -349,9 +349,9 @@ var SearchPanel = Widget.extend({ if (filter.groupBy) { var groups = {}; values.forEach(function (value) { - var groupId = value.group_id; + var groupId = JSON.stringify(value.group_id); if (!groups[groupId]) { - if (groupId) { + if (groupId !== 'false') { groupIds.push(groupId); } groups[groupId] = { diff --git a/addons/web/static/tests/views/search_panel_tests.js b/addons/web/static/tests/views/search_panel_tests.js index 11cf8b03513..3c58a5a3923 100644 --- a/addons/web/static/tests/views/search_panel_tests.js +++ b/addons/web/static/tests/views/search_panel_tests.js @@ -1890,6 +1890,56 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('Does not confuse false and "false" groupby values', async function (assert) { + assert.expect(6); + + this.data.company.fields.char_field = {string: "Char Field", type: 'char'}; + + this.data.company.records = [ + {id: 3, name: 'A', char_field: false, }, + {id: 5, name: 'B', char_field: 'false', } + ]; + + var kanban = await createView({ + View: KanbanView, + model: 'partner', + data: this.data, + services: this.services, + arch: `<kanban> + <templates><t t-name="kanban-box"> + <div> + <field name="foo"/> + </div> + </t></templates> + </kanban>`, + archs: { + 'partner,false,search': ` + <search> + <searchpanel> + <field name="company_id" select="multi" groupby="char_field"/> + </searchpanel> + </search>`, + }, + }); + + assert.containsOnce(kanban, '.o_search_panel_section'); + var $firstSection = kanban.$('.o_search_panel_section'); + + // There should be a group 'false' displayed with only value B inside it. + assert.containsOnce($firstSection, '.o_search_panel_filter_group'); + assert.strictEqual($firstSection.find('.o_search_panel_filter_group').text().replace(/\s/g, ''), + 'falseB2'); + assert.containsOnce($firstSection.find('.o_search_panel_filter_group'), '.o_search_panel_filter_value'); + + // Globally, there should be two values, one displayed in the group 'false', and one at the end of the section + // (the group false is not displayed and its values are displayed at the first level) + assert.containsN($firstSection, '.o_search_panel_filter_value', 2); + assert.strictEqual($firstSection.find('.o_search_panel_filter_value').text().replace(/\s/g, ''), + 'B2A2'); + + kanban.destroy(); + }); + QUnit.test('tests conservation of category record order', async function (assert) { assert.expect(1); |
