Instead of using sort + groupby of itertools (which group only consecutive), use only the groupby of odoo.tools which decrease the complexity of the code and avoid unmatched keys between sort keys and groupby keys task-2648449 Part-of: odoo/odoo#76761