Skip to content

Commit

Permalink
Merge pull request #73 from kmee/16.0-overtime
Browse files Browse the repository at this point in the history
16.0 overtime
  • Loading branch information
mileo authored Nov 29, 2024
2 parents 119da71 + d781c22 commit 45be6a4
Show file tree
Hide file tree
Showing 15 changed files with 637 additions and 200 deletions.
34 changes: 9 additions & 25 deletions l10n_br_hr_overtime_custom_multiplier/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ L10n Br Hr Overtime Custom Multiplier
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fkmee--odoo--addons-lightgray.png?logo=github
:target: https://github.com/OCA/kmee-odoo-addons/tree/16.0/l10n_br_hr_overtime_custom_multiplier
:alt: OCA/kmee-odoo-addons
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/kmee-odoo-addons-16-0/kmee-odoo-addons-16-0-l10n_br_hr_overtime_custom_multiplier
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/kmee-odoo-addons&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
.. |badge3| image:: https://img.shields.io/badge/github-KMEE%2Fkmee--odoo--addons-lightgray.png?logo=github
:target: https://github.com/KMEE/kmee-odoo-addons/tree/16.0/l10n_br_hr_overtime_custom_multiplier
:alt: KMEE/kmee-odoo-addons

|badge1| |badge2| |badge3|

Module allows companies to apply a custom multiplier to overtime
calculations in the Brazilian localization, providing flexible and
Expand All @@ -40,10 +34,10 @@ configurable overtime management.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/kmee-odoo-addons/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/KMEE/kmee-odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/kmee-odoo-addons/issues/new?body=module:%20l10n_br_hr_overtime_custom_multiplier%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/KMEE/kmee-odoo-addons/issues/new?body=module:%20l10n_br_hr_overtime_custom_multiplier%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -65,16 +59,6 @@ Contributors
Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/kmee-odoo-addons <https://github.com/OCA/kmee-odoo-addons/tree/16.0/l10n_br_hr_overtime_custom_multiplier>`_ project on GitHub.
This module is part of the `KMEE/kmee-odoo-addons <https://github.com/KMEE/kmee-odoo-addons/tree/16.0/l10n_br_hr_overtime_custom_multiplier>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
You are welcome to contribute.
7 changes: 5 additions & 2 deletions l10n_br_hr_overtime_custom_multiplier/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
"l10n_br_resource",
],
"data": [
"security/hr_attendance_exception.xml",
"security/hr_overtime_multiplier_range.xml",
#
"views/hr_attendance_overtime.xml",
"views/res_config_settings.xml",
"views/hr_overtime_multiplier_range.xml",
"views/hr_attendance_exception.xml",
],
"demo": [],
}
3 changes: 2 additions & 1 deletion l10n_br_hr_overtime_custom_multiplier/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import hr_attendance
from . import res_config_settings
from . import hr_attendance_overtime
from . import hr_overtime_multiplier_range
from . import hr_attendance_exception
165 changes: 89 additions & 76 deletions l10n_br_hr_overtime_custom_multiplier/models/hr_attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,98 @@


class HrAttendance(models.Model):

_inherit = "hr.attendance"

@api.model
def _update_overtime(self, employee_attendance_dates=None):
res = super(HrAttendance, self)._update_overtime(employee_attendance_dates)

def get_overtime_multiplier_and_bank_time(
date_time, original_overtime, is_holiday=False
):

config_params = self.env["ir.config_parameter"].sudo()

# Get the day of the week (0=Monday, 6=Sunday)
day_of_week = date_time.weekday()

# Check if it is a holiday
if is_holiday:
return float(
config_params.get_param("sunday_holidays_overtime_multiplier", 1)
)

# Saturdays (day 5)
if day_of_week == 5:
return float(config_params.get_param("saturday_overtime_multiplier", 1))

# Sundays (day 6)
if day_of_week == 6:
return float(
config_params.get_param("sunday_holidays_overtime_multiplier", 1)
)

# For weekdays (Monday to Friday)
if original_overtime < 2: # Less than 2 hours of overtime
return float(
config_params.get_param(
"business_days_under_2_hours_overtime_multiplier", 1
)
)
else: # More than 2 hours of overtime
return float(
config_params.get_param(
"business_days_over_2_hours_overtime_multiplier", 1
)
)

if employee_attendance_dates is None:
employee_attendance_dates = self._get_attendances_dates()

self.env["hr.attendance.overtime"].flush_model(["duration", "duration_real"])

for emp, attendance_dates in employee_attendance_dates.items():
for day_data in attendance_dates:
attendance_date = day_data[1]
overtime = self.env["hr.attendance.overtime"].search(
[
("employee_id", "=", emp.id),
("date", "=", attendance_date),
("adjustment", "=", False),
]
)

is_holiday = emp.resource_calendar_id.data_eh_feriado(attendance_date)

if overtime:
for overtime_record in overtime:
overtime_multiplier = get_overtime_multiplier_and_bank_time(
attendance_date, overtime_record.duration, is_holiday
)

overtime_record.write(
{
"duration": overtime_record.duration
* overtime_multiplier,
"duration_real": overtime_record.duration_real
* overtime_multiplier,
"extra_hours_withou_multiplier": overtime_record.duration,
"applied_multiplier": overtime_multiplier,
}
)
self.env["hr.attendance.overtime"].search(
[("attendance_id", "in", self.ids)]
).unlink()
res = super(
HrAttendance, self.with_context(attendance_ids=self.ids)
)._update_overtime(employee_attendance_dates)

return res


# def get_overtime_multiplier(date_time,
# original_overtime, is_holiday=False, employee_id=None):
# # Check if there is an exception
# for this employee on this date
# exception = self.env['hr.attendance.exception'].search([
# ('employee_id', '=', employee_id),
# ('date', '=', date_time.date())
# ], limit=1)

# if exception:
# day_of_week = exception.day_of_week_override
# else:
# day_of_week = 'holiday' if is_holiday else (
# 'monday' if date_time.weekday() == 0 else
# 'tuesday' if date_time.weekday() == 1 else
# 'wednesday' if date_time.weekday() == 2 else
# 'thursday' if date_time.weekday() == 3 else
# 'friday' if date_time.weekday() == 4 else
# 'saturday' if date_time.weekday() == 5 else
# 'sunday' if date_time.weekday() == 6 else 'weekday')

# # Search for applicable multiplier range
# applicable_range = self.env['hr.overtime.multiplier.range'].search([
# ('overtime_from', '<=', original_overtime),
# ('overtime_to', '>', original_overtime),
# # "|",

# # ('monday', '=', day_of_week == 'monday'),
# # ('tuesday', '=', day_of_week == 'tuesday'),
# # ('wednesday', '=', day_of_week == 'wednesday'),
# # ('thursday', '=', day_of_week == 'thursday'),
# # ('friday', '=', day_of_week == 'friday'),
# # ('saturday', '=', day_of_week == 'saturday'),
# # ('sunday', '=', day_of_week == 'sunday'),
# # ('holiday', '=', day_of_week == 'holiday'),
# ], limit=1)

# return applicable_range.multiplier if applicable_range else 1.0

# if employee_attendance_dates is None:
# employee_attendance_dates = self._get_attendances_dates()

# self.env["hr.attendance.overtime"].flush_model(["duration", "duration_real"])

# for emp, attendance_dates in employee_attendance_dates.items():
# for day_data in attendance_dates:
# attendance_date = day_data[1]
# overtime = self.env["hr.attendance.overtime"].search(
# [
# ("employee_id", "=", emp.id),
# ("date", "=", attendance_date),
# ("adjustment", "=", False),
# ]
# )

# # Convert attendance_date to a datetime object if it is a date object
# if isinstance(attendance_date, date)
# and not isinstance(attendance_date, datetime):
# attendance_date = datetime.combine(attendance_date, datetime.min.time())

# is_holiday = emp.resource_calendar_id.data_eh_feriado(attendance_date)

# if overtime:
# for overtime_record in overtime:
# overtime_multiplier = get_overtime_multiplier(
# attendance_date, overtime_record.duration, is_holiday, emp.id
# )

# overtime_record.write(
# {
# "duration":
# overtime_record.duration * overtime_multiplier,
# "duration_real":
# overtime_record.duration_real * overtime_multiplier,
# "extra_hours_withou_multiplier":
# overtime_record.duration,
# "applied_multiplier": overtime_multiplier,
# }
# )

# return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class HrAttendanceException(models.Model):
_name = "hr.attendance.exception"
_description = "Attendance Exception"

employee_id = fields.Many2one("hr.employee", string="Employee", required=True)
date = fields.Date(required=True)
day_of_week_override = fields.Selection(
[
("monday", "Monday"),
("tuesday", "Tuesday"),
("wednesday", "Wednesday"),
("thursday", "Thursday"),
("friday", "Friday"),
("saturday", "Saturday"),
("sunday", "Sunday"),
("holiday", "Holiday"),
],
string="Override Day of the Week",
required=True,
)

@api.constrains("employee_id", "date")
def _check_duplicate_exception(self):
for record in self:
duplicate_exception = self.search(
[
("employee_id", "=", record.employee_id.id),
("date", "=", record.date),
("id", "!=", record.id),
]
)
if duplicate_exception:
raise ValidationError(
_("An exception already exists for this employee on this date.")
)
Loading

0 comments on commit 45be6a4

Please sign in to comment.