Skip to content

Commit

Permalink
[ADD] #34 expected hours to attendance report
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Oct 2, 2023
1 parent 4324e4b commit 4e61db1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions verdigado_attendance/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

from . import hr_attendance
from . import hr_attendance_break
from . import hr_attendance_overtime
from . import hr_attendance_report
from . import hr_leave_type
30 changes: 30 additions & 0 deletions verdigado_attendance/models/hr_attendance_overtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from datetime import datetime, time

import pytz

from odoo import fields, models


class HrAttendanceOvertime(models.Model):
_inherit = "hr.attendance.overtime"

expected_hours = fields.Float(compute="_compute_expected_hours", store=True)

def _compute_expected_hours(self):
for this in self:
employee = this.employee_id
tz = pytz.timezone(employee.tz)
this.expected_hours = (
this.adjustment
and False
or employee._get_work_days_data_batch(
tz.localize(datetime.combine(this.date, time.min)).astimezone(
pytz.utc
),
tz.localize(datetime.combine(this.date, time.max)).astimezone(
pytz.utc
),
)[employee.id]["hours"]
)
11 changes: 9 additions & 2 deletions verdigado_attendance/models/hr_attendance_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)


from odoo import models
from odoo import fields, models


class HrAttendanceReport(models.Model):
_inherit = "hr.attendance.report"

expected_hours = fields.Float()

def _select(self):
"""Add expected hours"""
return super()._select() + ", coalesce(ot.expected_hours, 0) expected_hours"

def _join(self):
"""Add overtime adjustments"""
return super()._join() + " UNION %s %s %s" % (
self._select()
.replace("hra.worked_hours", "0")
.replace("break_hours", "0")
.replace("ot.duration", "0"),
.replace("ot.duration", "0")
.replace("coalesce(ot.expected_hours, 0)", "0"),
self._from(),
super()._join().replace("ot.adjustment = FALSE", "ot.adjustment = TRUE"),
)
9 changes: 9 additions & 0 deletions verdigado_attendance/views/hr_attendance_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
<!-- Copyright 2023 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<data>
<record id="hr_attendance_report_view_pivot" model="ir.ui.view">
<field name="model">hr.attendance.report</field>
<field name="inherit_id" ref="hr_attendance.hr_attendance_report_view_pivot" />
<field name="arch" type="xml">
<field name="worked_hours" position="before">
<field name="expected_hours" type="measure" widget="float_time" />
</field>
</field>
</record>
<record
id="hr_attendance.hr_attendance_report_action"
model="ir.actions.act_window"
Expand Down

0 comments on commit 4e61db1

Please sign in to comment.