-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] hr_attendance_overtime_hours: pre-commit auto fixes
- Loading branch information
1 parent
d4b2254
commit 1939f82
Showing
5 changed files
with
40 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import hr_attendance_overtime | ||
from . import hr_attendance_overtime |
47 changes: 29 additions & 18 deletions
47
hr_attendance_overtime_hours/models/hr_attendance_overtime.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
from odoo import models, fields, api | ||
from datetime import datetime, time | ||
import logging | ||
from datetime import datetime, time | ||
|
||
from odoo import api, fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class HrAttendanceOvertime(models.Model): | ||
_inherit = 'hr.attendance.overtime' | ||
|
||
planned_hours = fields.Float(compute='_compute_planned_hours', store=True, readonly=True) | ||
worked_hours = fields.Float(compute='_compute_worked_hours', store=True, readonly=True) | ||
_inherit = "hr.attendance.overtime" | ||
|
||
planned_hours = fields.Float( | ||
compute="_compute_planned_hours", store=True, readonly=True | ||
) | ||
worked_hours = fields.Float( | ||
compute="_compute_worked_hours", store=True, readonly=True | ||
) | ||
|
||
@api.depends('date') | ||
@api.depends("date") | ||
def _compute_planned_hours(self): | ||
for overtime in self: | ||
# Get work hours from calendar | ||
planned_hours = overtime.employee_id.resource_calendar_id.get_work_hours_count( | ||
datetime.combine(overtime.date, time.min), | ||
datetime.combine(overtime.date, time.max), | ||
True) | ||
planned_hours = ( | ||
overtime.employee_id.resource_calendar_id.get_work_hours_count( | ||
datetime.combine(overtime.date, time.min), | ||
datetime.combine(overtime.date, time.max), | ||
True, | ||
) | ||
) | ||
overtime.planned_hours = planned_hours | ||
|
||
@api.depends('duration') | ||
@api.depends("duration") | ||
def _compute_worked_hours(self): | ||
for overtime in self: | ||
# Get sum of attendance entries | ||
attendance_ids = self.env['hr.attendance'].search([ | ||
('employee_id', '=', overtime.employee_id.id), | ||
('check_in', '>=', datetime.combine(overtime.date, time.min)), | ||
('check_out', '<=', datetime.combine(overtime.date, time.max)), | ||
]) | ||
overtime.worked_hours = sum(attendance_ids.mapped('worked_hours')) | ||
attendance_ids = self.env["hr.attendance"].search( | ||
[ | ||
("employee_id", "=", overtime.employee_id.id), | ||
("check_in", ">=", datetime.combine(overtime.date, time.min)), | ||
("check_out", "<=", datetime.combine(overtime.date, time.max)), | ||
] | ||
) | ||
overtime.worked_hours = sum(attendance_ids.mapped("worked_hours")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
10 changes: 6 additions & 4 deletions
10
hr_attendance_overtime_hours/views/hr_attendance_overtime.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters