Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Time Off

Entity: hr.leave

Compute Method: _compute_dashboard_warning_message

View 20.0
Inputs Method Outputs
  • employee_id
  • employee_id.ids
  • count_as
  • date_to
  • date_from
  • employee_id.name
  • state
  • employee_id.user_id
  • employee_id.user_id.id
+ not_generated = ~self._get_generated_leave_domain()
+ check_warning_leaves = self.filtered_domain(
+             Domain('state', 'not in', ('refuse', 'cancel'))
+             & Domain('work_entry_type_id.allow_request_on_top', '=', False)
+             & not_generated
+         )
+ (self - check_warning_leaves).dashboard_warning_message = False
+ if not check_warning_leaves:
+             return
+ all_leaves = self.search(
+             Domain('date_from', '<', max(check_warning_leaves.mapped('date_to')))
+             & Domain('date_to', '>', min(check_warning_leaves.mapped('date_from')))
+             & Domain('employee_id', 'in', check_warning_leaves.employee_id.ids)
+             & Domain('work_entry_type_id.allow_request_on_top', '=', False)
+             & Domain('state', 'not in', ['cancel', 'refuse'])
+         )
+ for holiday in check_warning_leaves:
+             conflicting_holidays = all_leaves.filtered_domain([
+                 ('employee_id', 'in', holiday.employee_id.ids),
+                 ('count_as', '=', holiday.count_as),
+                 ('date_from', '<', holiday.date_to),
+                 ('date_to', '>', holiday.date_from),
+                 ('id', 'not in', holiday.ids),
+             ])
+             if not conflicting_holidays:
+                 holiday.dashboard_warning_message = False
+                 continue
+ 
+             conflicting_holidays_list = []
+             # Do not display the name of the employee if the conflicting holidays have an employee_id.user_id equivalent to the user id
+             holidays_only_have_uid = bool(holiday.employee_id)
+             holiday_states = dict(conflicting_holidays.fields_get(allfields=['state'])['state']['selection'])
+             for conflicting_holiday in conflicting_holidays:
+                 conflicting_holiday_data = {
+                     'employee_name': conflicting_holiday.employee_id.name,
+                     'date_from': format_date(self.env, min(conflicting_holiday.mapped('date_from'))),
+                     'date_to': format_date(self.env, min(conflicting_holiday.mapped('date_to'))),
+                     'state': holiday_states[conflicting_holiday.state]
+                 }
+                 if conflicting_holiday.employee_id.user_id.id != self.env.uid:
+                     holidays_only_have_uid = False
+                 if conflicting_holiday_data not in conflicting_holidays_list:
+                     conflicting_holidays_list.append(conflicting_holiday_data)
+ 
+             msg = ""
+             if holidays_only_have_uid:
+                 msg = self.env._('You\'ve already booked time off which overlaps with this period:')
+             else:
+                 msg = self.env._('An employee already booked time off which overlaps with this period:')
+ 
+             holiday.dashboard_warning_message = msg + "".join(
+                 ('\n' + (self.env._('%(employee_name)s from %(date_from)s to %(date_to)s - %(state)s') % {
+                     'employee_name': conflicting_holiday_data['employee_name'] if not holidays_only_have_uid else "",
+                     'date_from': conflicting_holiday_data['date_from'],
+                     'date_to': conflicting_holiday_data['date_to'],
+                     'state': conflicting_holiday_data['state']
+                 }).lstrip()) for conflicting_holiday_data in conflicting_holidays_list
+             )
  • dashboard_warning_message

Back to entity