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_allocation_warning

View 20.0
Inputs Method Outputs
  • employee_id
  • work_entry_type_requires_allocation
  • work_entry_type_id
  • work_entry_type_id.time_off_selectable
  • virtual_remaining_leaves
  • work_entry_type_request_unit
  • number_of_hours
  • number_of_days
  • work_entry_type_id.allows_negative
  • work_entry_type_id.max_allowed_negative
+ self.allocation_display_warning = False
+ for leave in self:
+             is_multi_employee = self.env.context.get('default_is_multi_employee', False)
+ 
+             if not leave.employee_id or is_multi_employee or not leave.work_entry_type_requires_allocation or not leave.work_entry_type_id.time_off_selectable:
+                 continue
+ 
+             remaining = leave.virtual_remaining_leaves
+             is_hour = leave.work_entry_type_request_unit == 'hour'
+             request_amount = leave.number_of_hours if is_hour else leave.number_of_days
+             max_excess = leave.work_entry_type_id.max_allowed_negative if leave.work_entry_type_id.allows_negative else 0
+ 
+             if request_amount > (remaining + max_excess):
+                 if is_hour:
+                     leave.allocation_display_warning = self.env._(
+                         "Only %(remaining)s hour(s) available", remaining=float_round(remaining, precision_digits=2))
+                 else:
+                     leave.allocation_display_warning = self.env._(
+                         "Only %(remaining)s day(s) available", remaining=float_round(remaining, precision_digits=2))
  • allocation_display_warning

Back to entity