Skip to content

Commit

Permalink
[IMP] hr_attendance_overtime_hours: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviedoanhduy committed Aug 7, 2024
1 parent d4b2254 commit 1939f82
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion hr_attendance_overtime_hours/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Show planned and worked hours in overtime view.
""",
"author": "Mint System GmbH, Odoo Community Association (OCA)",
"website": "https://www.mint-system.ch",
"website": "https://github.com/OCA/hr-attendance",
"category": "Human Resources",
"version": "15.0.1.0.0",
"license": "AGPL-3",
Expand Down
2 changes: 1 addition & 1 deletion hr_attendance_overtime_hours/models/__init__.py
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 hr_attendance_overtime_hours/models/hr_attendance_overtime.py
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"))
3 changes: 3 additions & 0 deletions hr_attendance_overtime_hours/pyproject.toml
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 hr_attendance_overtime_hours/views/hr_attendance_overtime.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_attendance_overtime_tree" model="ir.ui.view">
<field name="name">hr_attendance_overtime_hours.view_attendance_overtime_tree</field>
<field
name="name"
>hr_attendance_overtime_hours.view_attendance_overtime_tree</field>
<field name="model">hr.attendance.overtime</field>
<field name="inherit_id" ref="hr_attendance.view_attendance_overtime_tree" />
<field name="arch" type="xml">
<field name="duration" position="before">
<field name="planned_hours" widget="float_time"/>
<field name="worked_hours" widget="float_time"/>
<field name="planned_hours" widget="float_time" />
<field name="worked_hours" widget="float_time" />
</field>
</field>
</record>
Expand Down

0 comments on commit 1939f82

Please sign in to comment.