Skip to content

Commit

Permalink
[ADD] verdigado#57 allow higher value overtime for holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Dec 11, 2023
1 parent 9b9ab76 commit 451223e
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 2 deletions.
4 changes: 4 additions & 0 deletions verdigado_attendance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
"views/base_ical.xml",
"views/hr_attendance_view.xml",
"views/hr_attendance_report.xml",
"views/hr_employee.xml",
"views/hr_leave_type.xml",
"views/hr_leave.xml",
"views/hr_menu_human_resources_configuration.xml",
"views/menu.xml",
"views/res_config_settings.xml",
],
"demo": [
"demo/res_users.xml",
Expand All @@ -52,10 +54,12 @@
],
"web.assets_backend": [
"verdigado_attendance/static/src/scss/backend.scss",
"verdigado_attendance/static/src/js/hr_attendance.js",
"verdigado_attendance/static/src/js/systray.esm.js",
"verdigado_attendance/static/src/js/time_off_calendar.js",
],
"web.assets_qweb": [
"verdigado_attendance/static/src/xml/hr_attendance.xml",
"verdigado_attendance/static/src/xml/hr_holidays.xml",
"verdigado_attendance/static/src/xml/systray.xml",
"verdigado_attendance/static/src/xml/time_off_calendar.xml",
Expand Down
3 changes: 3 additions & 0 deletions verdigado_attendance/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from . import hr_attendance_break
from . import hr_attendance_overtime
from . import hr_attendance_report
from . import hr_employee
from . import hr_leave
from . import hr_leave_type
from . import res_config_settings
from . import res_company
from . import res_users
21 changes: 20 additions & 1 deletion verdigado_attendance/models/hr_attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ class HrAttendance(models.Model):
check_out = DatetimeWithoutSeconds()

def _update_overtime(self, employee_attendance_dates=None):
"""Recreate missing overtime records"""
"""
Recreate missing overtime records to generate correct expected hours
Create adjustments for extra overtime by holiday factor
"""
result = super()._update_overtime(
employee_attendance_dates=employee_attendance_dates
)
if employee_attendance_dates is None:
employee_attendance_dates = self._get_attendances_dates()

missing_vals = []
for employee, attendance_dates in employee_attendance_dates.items():
dates = [attendance_date for _dummy, attendance_date in attendance_dates]
Expand All @@ -26,12 +30,27 @@ def _update_overtime(self, employee_attendance_dates=None):
("employee_id", "=", employee.id),
("company_id", "=", self.env.company.id),
("date", "in", dates),
("adjustment", "=", False),
]
)
missing_vals += [
{"employee_id": employee.id, "date": attendance_date}
for attendance_date in set(dates)
- set(existing_overtime.mapped("date"))
]

overtime_factor = employee._get_effective_holiday_overtime_factor()
if overtime_factor != 1:
missing_vals += [
{
"employee_id": employee.id,
"date": overtime.date,
"adjustment": True,
"duration": overtime.duration * overtime_factor
- overtime.duration,
"holiday_overtime_for_overtime_id": overtime.id,
}
for overtime in existing_overtime
]
self.env["hr.attendance.overtime"].sudo().create(missing_vals)
return result
3 changes: 3 additions & 0 deletions verdigado_attendance/models/hr_attendance_overtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class HrAttendanceOvertime(models.Model):
_inherit = "hr.attendance.overtime"

expected_hours = fields.Float(compute="_compute_expected_hours", store=True)
holiday_overtime_for_overtime_id = fields.Many2one(
"hr.attendance.overtime", ondelete="cascade"
)

@api.depends("date", "employee_id", "duration")
def _compute_expected_hours(self):
Expand Down
31 changes: 31 additions & 0 deletions verdigado_attendance/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models


class HrEmployee(models.Model):
_inherit = "hr.employee"

holiday_overtime_factor = fields.Float(
default=0,
help="When activated on holidays/weekends, overtime is multiplied with this factor",
)

def _get_effective_holiday_overtime_factor(self, date=None):
"""Return an employee's effective overtime factor for some date"""
self.ensure_one()
date = (
date
or self.env["hr.attendance"]._get_day_start_and_day(
self,
fields.Datetime.now(),
)[1]
)
return (
(self.holiday_overtime_factor or self.company_id.holiday_overtime_factor)
if (
date.isoweekday() >= 6
or self.env["hr.holidays.public"].is_public_holiday(date, self.id)
)
else 1
)
7 changes: 6 additions & 1 deletion verdigado_attendance/models/res_company.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import models
from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

holiday_overtime_factor = fields.Float(
default=1,
help="When activated on holidays/weekends, overtime is multiplied with this factor",
)

def write(self, vals):
"""Don't delete overtime records that are adjustments when changing overtime settings"""
if "hr_attendance_overtime" in vals or "overtime_start_date" in vals:
Expand Down
13 changes: 13 additions & 0 deletions verdigado_attendance/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)


from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

holiday_overtime_factor = fields.Float(
related="company_id.holiday_overtime_factor", readonly=False
)
11 changes: 11 additions & 0 deletions verdigado_attendance/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, models


class ResUsers(models.Model):
_inherit = "res.users"

@api.model
def get_effective_holiday_overtime_factor(self):
return self.env.user.employee_id._get_effective_holiday_overtime_factor()
31 changes: 31 additions & 0 deletions verdigado_attendance/static/src/js/hr_attendance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright 2023 Hunki Enterprises BV
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */

odoo.define("verdigado_attendance.hr_attendance", function (require) {
"use strict";

var myAttendances = require("hr_attendance.my_attendances");

myAttendances.include({
events: _.extend({}, myAttendances.prototype.events, {
"click .o_hr_attendance_break_icon": _.debounce(
function () {
this._hr_attendance_break();
},
200,
true
),
}),

willStart: function () {
var self = this;
var promise = this._rpc({
model: "res.users",
method: "get_effective_holiday_overtime_factor",
}).then(function (data) {
self.effective_holiday_overtime_factor = data;
});
return Promise.all([this._super.apply(this, arguments), promise]);
},
});
});
15 changes: 15 additions & 0 deletions verdigado_attendance/static/src/xml/hr_attendance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf8" ?>
<templates>
<t t-inherit="hr_attendance.HrAttendanceMyMainMenu">
<xpath expr="//h4[@t-if='checked_in']" position="after">
<div t-if="checked_in and widget.effective_holiday_overtime_factor != 1">
<input type="checkbox" id="apply_holiday_overtime" checked="" />
<label for="apply_holiday_overtime">
Apply holiday overtime factor (
<t t-out="widget.effective_holiday_overtime_factor" />
)
</label>
</div>
</xpath>
</t>
</templates>
12 changes: 12 additions & 0 deletions verdigado_attendance/views/hr_employee.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_employee_form" model="ir.ui.view">
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="model">hr.employee</field>
<field name="arch" type="xml">
<field name="pin" position="after">
<field name="holiday_overtime_factor" />
</field>
</field>
</record>
</odoo>
34 changes: 34 additions & 0 deletions verdigado_attendance/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<data>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="hr_attendance.res_config_settings_view_form" />
<field name="arch" type="xml">
<div name="overtime_settings" position="after">
<h2>Overtime on holidays</h2>
<div class="row mt16 o_settings_container" name="break_settings">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<span
class="fa fa-lg fa-building-o"
title="Values set here are company-specific."
role="img"
aria-label="Values set here are company-specific."
groups="base.group_multi_company"
/>
<label for="holiday_overtime_factor" />
<div class="text-muted">
When recording attendances on a holiday, this factor
will be applied
</div>
<field name="holiday_overtime_factor" />
</div>
</div>
</div>
</div>
</field>
</record>
</data>

0 comments on commit 451223e

Please sign in to comment.