Skip to content

Commit

Permalink
Merge pull request #71 from kmee/feat/l10n_br_hr_overtime_custom_mult…
Browse files Browse the repository at this point in the history
…iplier

[ADD]: l10n_br_hr_overtime_custom_multiplier
  • Loading branch information
mileo authored Nov 27, 2024
2 parents b37adb8 + 89b0495 commit ff91196
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_br_hr_overtime_custom_multiplier/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions l10n_br_hr_overtime_custom_multiplier/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'L10n Br Hr Overtime Custom Multiplier',
'summary': """
Module allows companies to apply a custom multiplier to overtime calculations in the Brazilian localization, providing flexible and configurable overtime management.""",
'version': '16.0.1.0.0',
'license': 'AGPL-3',
'author': 'KMEE,Odoo Community Association (OCA)',
'website': 'https://kmee.com.br/',
'depends': [
'hr_attendance',
'l10n_br_resource',
],
'data': [
'views/hr_attendance_overtime.xml',
'views/res_config_settings.xml',
],
'demo': [
],
}
3 changes: 3 additions & 0 deletions l10n_br_hr_overtime_custom_multiplier/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import hr_attendance
from . import res_config_settings
from . import hr_attendance_overtime
71 changes: 71 additions & 0 deletions l10n_br_hr_overtime_custom_multiplier/models/hr_attendance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models


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
})

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

from odoo import _, api, fields, models


class HrAttendanceOvertime(models.Model):

_inherit = "hr.attendance.overtime"

extra_hours_withou_multiplier = fields.Float(string='Extra Hours without Multiplier')

applied_multiplier = fields.Float(string='Applied Multiplier', default=1.0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

saturday_overtime_multiplier = fields.Char(string='Saturday Overtime Multiplier', config_parameter='saturday_overtime_multiplier')
sunday_holidays_overtime_multiplier = fields.Char(string='Sunday and Holidays Overtime Multiplier', config_parameter='sunday_holidays_overtime_multiplier')
business_days_over_2_hours_overtime_multiplier = fields.Char(string='Business Days Over 2 Hours Overtime Multiplier', config_parameter='business_days_over_2_hours_overtime_multiplier')
business_days_under_2_hours_overtime_multiplier = fields.Char(string='Business Days Under 2 Hours Overtime Multiplier', config_parameter='business_days_under_2_hours_overtime_multiplier')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="hr_attendance_overtime_tree_view">
<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="extra_hours_withou_multiplier"/>
<field name="applied_multiplier"/>
</field>
</field>
</record>

<record id="action_hr_overtime_list" model="ir.actions.act_window">
<field name="name">Extra hours</field>
<field name="res_model">hr.attendance.overtime</field>
<field name="view_mode">tree</field>
<field name="help">View and manage overtime records for employees</field>
</record>


<menuitem id="hr_overtime_menu"
name="Extra hours"
parent="hr_attendance.menu_hr_attendance_root"
action="action_hr_overtime_list"/>

</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="res_config_settings_form_view">
<field name="name">res.config.settings.form (in l10n_br_hr_overtime_custom_multiplier)</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="hr_attendance.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='overtime_settings']" position="inside">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<label for="saturday_overtime_multiplier"/>
<div class="text-muted">
<field name="saturday_overtime_multiplier"/>
</div>

<label for="sunday_holidays_overtime_multiplier"/>
<div class="text-muted">
<field name="sunday_holidays_overtime_multiplier"/>
</div>

<label for="business_days_over_2_hours_overtime_multiplier"/>
<div class="text-muted">
<field name="business_days_over_2_hours_overtime_multiplier"/>
</div>

<label for="business_days_under_2_hours_overtime_multiplier"/>
<div class="text-muted">
<field name="business_days_under_2_hours_overtime_multiplier"/>
</div>
</div>
</div>

</xpath>
</field>
</record>



</odoo>

0 comments on commit ff91196

Please sign in to comment.