Explorar el Código

fix: Filter planned hours to only count working days like Odoo Planning

- Added working days filter to planned hours calculation
- Now only counts hours that fall on working days according to employee's calendar
- Uses same logic as Odoo Planning native application
- Calculates working ratio for slots that span multiple days
- This should match the 99h33 shown in Odoo Planning vs 181.25 in our module
root hace 5 meses
padre
commit
70ee1f218e
Se han modificado 1 ficheros con 22 adiciones y 0 borrados
  1. 22 0
      hr_efficiency/models/hr_efficiency.py

+ 22 - 0
hr_efficiency/models/hr_efficiency.py

@@ -415,6 +415,28 @@ class HrEfficiency(models.Model):
         for slot in planning_slots:
             hours = slot.allocated_hours or 0.0
             
+            # Only count hours for working days according to employee's calendar
+            if employee.resource_calendar_id:
+                # Get working hours for the slot's date range
+                slot_start = slot.start_datetime.date()
+                slot_end = slot.end_datetime.date()
+                
+                # Calculate working hours for this slot period
+                slot_start_dt = datetime.combine(slot_start, datetime.min.time())
+                slot_end_dt = datetime.combine(slot_end, datetime.max.time())
+                work_hours_data = employee._list_work_time_per_day(slot_start_dt, slot_end_dt)
+                
+                # Sum working hours for the slot period
+                slot_working_hours = sum(hours for _, hours in work_hours_data[employee.id])
+                
+                # Only count the portion that falls on working days
+                if slot_working_hours > 0:
+                    # Calculate the ratio of working hours to total slot hours
+                    slot_duration = (slot.end_datetime - slot.start_datetime).total_seconds() / 3600
+                    if slot_duration > 0:
+                        working_ratio = min(1.0, slot_working_hours / slot_duration)
+                        hours = hours * working_ratio
+            
             # Check if the slot is linked to a billable project
             if slot.project_id and slot.project_id.allow_billable:
                 total_billable += hours