diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 4c190a69800..287f2d8eeef 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -96,19 +96,42 @@ class hr_holidays_status(osv.osv): } def name_get(self, cr, uid, ids, context=None): - - if not context.get('employee_id',False): + if context is None: + context = {} + if not context.get('employee_id'): # leave counts is based on employee_id, would be inaccurate if not based on correct employee return super(hr_holidays_status, self).name_get(cr, uid, ids, context=context) - res = [] for record in self.browse(cr, uid, ids, context=context): name = record.name if not record.limit: - name = name + (' (%g/%g)' % (record.leaves_taken or 0.0, record.max_leaves or 0.0)) + name = name + (' (%g/%g)' % (record.virtual_remaining_leaves or 0.0, record.max_leaves or 0.0)) res.append((record.id, name)) return res + def _search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None): + """ Override _search to order the results, according to some employee. + The order is the following + + - limit (limited leaves first, such as Legal Leaves) + - virtual remaining leaves (higher the better, so using reverse on sorted) + + This override is necessary because those fields are not stored and depends + on an employee_id given in context. This sort will be done when there + is an employee_id in context and that no other order has been given + to the method. """ + if context is None: + context = {} + ids = super(hr_holidays_status, self)._search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count, access_rights_uid=access_rights_uid) + if not count and not order and context.get('employee_id'): + leaves = self.browse(cr, uid, ids, context=context) + # perform a 2-steps sort because sorting on reminaing leaves is reversed + # sorted keep the order and is stable so 2-steps + sorted_leaves = leaves.sorted(key=attrgetter('limit')) + sorted_leaves = leaves.sorted(key=attrgetter('virtual_remaining_leaves'), reverse=True) + return [leave.id for leave in sorted_leaves] + return ids + class hr_holidays(osv.osv): _name = "hr.holidays" diff --git a/addons/hr_holidays/hr_holidays_data.xml b/addons/hr_holidays/hr_holidays_data.xml index 1bdcb1310e7..1f4292a9d7c 100644 --- a/addons/hr_holidays/hr_holidays_data.xml +++ b/addons/hr_holidays/hr_holidays_data.xml @@ -22,27 +22,28 @@ + black Sick Leaves - True + red Compensatory Days - True + lavender Unpaid - True + brown diff --git a/addons/hr_holidays/hr_holidays_demo.xml b/addons/hr_holidays/hr_holidays_demo.xml index de2f261dbfa..f70fa072aaa 100644 --- a/addons/hr_holidays/hr_holidays_demo.xml +++ b/addons/hr_holidays/hr_holidays_demo.xml @@ -1,61 +1,61 @@ - + - Casual Leave for Peter Parker + Legal Leaves for Peter Parker add 20 - - Trip with Family - - - - remove - 3 - - - - - Doctor Appointment - - - - remove - draft - 3 - + + International Tour + + + + add + 7 + - Summer Vacation - - - - add - draft - 7 - - - - - International Tour - - - - add - 7 - + Summer Vacation + + + + add + draft + 7 + + + + + Trip with Family + + + + remove + 3 + + + + + Doctor Appointment + + + + remove + draft + 3 + + - - +