From f07439fbc87cb4cfab568dce24f1e7bdfd31ad64 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Fri, 10 Jun 2022 13:05:26 +0000 Subject: [PATCH] [FIX] mail: display follower subtypes order by sequence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this fix, follower subtypes were displayed by order of id, whereas in DiscussController.read_subscription_data(), it was ordered by : \- parent_mode \- res_mode \- internal \- sequence See : https://github.com/odoo/odoo/blob/fc115ebdf7c3783f9eaabba71eccce23c676d957/addons/mail/controllers/discuss.py#L471-472 In this commit, we just reproduce the same order. Also, for `parentModel` and `resModel`, we want the record with their values unset to come first. We added 'undefined-first', as this sort order might be needed for other models. closes odoo/odoo#93315 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/model/model_field_relation_set.js | 9 +++++++++ addons/mail/static/src/models/follower_subtype.js | 4 +++- addons/mail/static/src/models/follower_subtype_list.js | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/model/model_field_relation_set.js b/addons/mail/static/src/model/model_field_relation_set.js index a69ebd5c828..8f067af3c76 100644 --- a/addons/mail/static/src/model/model_field_relation_set.js +++ b/addons/mail/static/src/model/model_field_relation_set.js @@ -77,6 +77,15 @@ export class RelationSet { } break; } + case 'falsy-first': { + if (!valA) { + return -1; + } + if (!valB) { + return 1; + } + break; + } case 'case-insensitive-asc': { if (typeof valA !== 'string' || typeof valB !== 'string') { break; diff --git a/addons/mail/static/src/models/follower_subtype.js b/addons/mail/static/src/models/follower_subtype.js index 7a240514c09..4484012bfd3 100644 --- a/addons/mail/static/src/models/follower_subtype.js +++ b/addons/mail/static/src/models/follower_subtype.js @@ -57,6 +57,8 @@ registerModel({ parentModel: attr(), // AKU FIXME: use relation instead resModel: attr(), - sequence: attr(), + sequence: attr({ + default: 1, + }), }, }); diff --git a/addons/mail/static/src/models/follower_subtype_list.js b/addons/mail/static/src/models/follower_subtype_list.js index 808f047e0ae..f770e81c0e2 100644 --- a/addons/mail/static/src/models/follower_subtype_list.js +++ b/addons/mail/static/src/models/follower_subtype_list.js @@ -49,6 +49,12 @@ registerModel({ */ _sortFollowerSubtypeViews() { return [ + ['falsy-first', 'subtype.parentModel'], + ['case-insensitive-asc', 'subtype.parentModel'], + ['falsy-first', 'subtype.resModel'], + ['case-insensitive-asc', 'subtype.resModel'], + ['smaller-first', 'subtype.isInternal'], + ['smaller-first', 'subtype.sequence'], ['smaller-first', 'subtype.id'], ]; },