From 67bc68dfd387c81ab7ce6296e4d236fcd5365f8b Mon Sep 17 00:00:00 2001 From: jvm-odoo Date: Thu, 24 Oct 2019 07:54:28 +0000 Subject: [PATCH] [FIX] hr_holidays: fix leaves types order In the leaves app, you can create an allocation request where you can select a leave type. Before this commit: - The leaves type order is not correct when you have a lot of them. You should have your remaining leaves on the top of the list. When you click on search more, the order is correct. After this commit: - The leaves type order is correct. Odony's comment: Leave types are reordered after each search(), based on some context-dependent, non-stored conditions. The problem is that the initial search() applies the given *limit*, so the "post-sort" will only sort a limited number of random result from the initial search, rather than all types matching the domain. If you have more than 7 leaves types matching the domain, you have a chance that the m2o auto-completion on the leave request form will not suggest the correct leave types, because the post-sort will not even receive them. So you may not see a leave type for which you have remaining leaves! OPW-2089593 closes odoo/odoo#39372 X-original-commit: 04e85efb82f257c01ea056c759eb1b2cec078188 Signed-off-by: Nicolas Martinelli (nim) Co-authored-by: odony --- addons/hr_holidays/models/hr_leave_type.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 073a4643e3d..3694d194b25 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -324,11 +324,11 @@ class HolidaysType(models.Model): to the method. """ employee_id = self._get_contextual_employee_id() - leave_ids = super(HolidaysType, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid) - if not count and not order and employee_id: - leaves = self.browse(leave_ids) - - return leaves.sorted(key=self._model_sorting_key, reverse=True).ids + post_sort = (not count and not order and employee_id) + leave_ids = super(HolidaysType, self)._search(args, offset=offset, limit=(None if post_sort else limit), order=order, count=count, access_rights_uid=access_rights_uid) + leaves = self.browse(leave_ids) + if post_sort: + return leaves.sorted(key=self._model_sorting_key, reverse=True).ids[:limit] return leave_ids def action_see_days_allocated(self):