[FIX] web: un-stored m2m field is not valid custom groupby

Even if a many2many field is forcely set to be sortable, it should
not be included in the list of custom groupby options if it's
an un-stored field.

closes odoo/odoo#104978

X-original-commit: 9ba52387481bb0720c5d4f5d8a86c3ad6e801137
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
Joseph Caburnay
2022-11-04 11:59:08 +01:00
parent 80318050ef
commit c144ac4cf0
2 changed files with 11 additions and 6 deletions
@@ -43,7 +43,7 @@ odoo.define('web.GroupByMenu', function (require) {
* @returns {boolean}
*/
_validateField(field) {
return (field.sortable || (field.type === "many2many" && field.store)) &&
return (field.type === "many2many" ? field.store : field.sortable) &&
field.name !== "id" &&
GROUPABLE_TYPES.includes(field.type);
}
@@ -19,6 +19,7 @@ odoo.define('web.groupby_menu_tests', function (require) {
float_field: { string: "Float", type: "float", group_operator: 'sum' },
foo: { string: "Foo", type: "char", store: true, sortable: true },
m2m: { string: "Many2Many", type: "many2many", store: true},
m2m_not_stored: { string: "Many2Many not stored", type: "many2many" },
};
patchWithCleanup(browser, {
setTimeout: (fn) => fn(),
@@ -41,7 +42,11 @@ odoo.define('web.groupby_menu_tests', function (require) {
});
QUnit.test('simple rendering with no groupby', async function (assert) {
assert.expect(6);
assert.expect(3);
// Manually make m2m_not_stored to be sortable.
// Even if it's sortable, it should not be included in the add custom groupby options.
this.fields.m2m_not_stored.sortable = true;
const params = {
cpModelConfig: { searchMenuTypes },
@@ -56,10 +61,10 @@ odoo.define('web.groupby_menu_tests', function (require) {
await cpHelpers.toggleAddCustomGroup(controlPanel);
const optionEls = controlPanel.el.querySelectorAll('.o_add_custom_group_menu select option');
assert.strictEqual(optionEls[0].innerText.trim(), 'Birthday');
assert.strictEqual(optionEls[1].innerText.trim(), 'Date');
assert.strictEqual(optionEls[2].innerText.trim(), 'Foo');
assert.strictEqual(optionEls[3].innerText.trim(), 'Many2Many');
assert.deepEqual(
[...optionEls].map((el) => el.innerText.trim()),
['Birthday', 'Date', 'Foo', 'Many2Many']
);
});
QUnit.test('simple rendering with a single groupby', async function (assert) {