Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] [16.0] hr_contract_update_overtime: Reorganize Leaves across Contracts + Message #172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hr_contract_update_overtime/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ You can Update Overtime in different ways:
- Header button on Contract History form view
- Header button on Contract form view

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Header button on Contract form view is visible if the user is responsible HR for the employee


If you Update Overtime from Contract History, leaves will also be
reorganized across their contract calendars.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
Expand Down
22 changes: 20 additions & 2 deletions hr_contract_update_overtime/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-11 08:46+0000\n"
"PO-Revision-Date: 2024-07-11 10:47+0200\n"
"POT-Creation-Date: 2024-07-17 09:15+0000\n"
"PO-Revision-Date: 2024-07-17 11:16+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
Expand All @@ -27,6 +27,24 @@ msgstr "Contrato"
msgid "Contract history"
msgstr "Histórico de contratación"

#. module: hr_contract_update_overtime
#. odoo-python
#: code:addons/hr_contract_update_overtime/models/hr_contract.py:0
#, python-format
msgid "Overtime updated"
msgstr "Horas Extra actualizadas"

#. module: hr_contract_update_overtime
#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form
msgid ""
"This action will also reorganize all the Employee's leaves by distributing "
"them across their contract calendars. If you do not want this to happen, "
"you can Update Overtime from a specific contract."
msgstr ""
"Esta acción también reorganizará todas las ausencias del Empleado "
"distribuyéndolas en los calendarios de sus contratos. Si no quieres que "
"esto pase, puedes actualizar las Horas Extra desde un contrato específico."

#. module: hr_contract_update_overtime
#: model:ir.actions.server,name:hr_contract_update_overtime.hr_contract_history_update_overtime_all_action
#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form
Expand Down
17 changes: 17 additions & 0 deletions hr_contract_update_overtime/i18n/hr_contract_update_overtime.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-17 09:15+0000\n"
"PO-Revision-Date: 2024-07-17 09:15+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -23,6 +25,21 @@ msgstr ""
msgid "Contract history"
msgstr ""

#. module: hr_contract_update_overtime
#. odoo-python
#: code:addons/hr_contract_update_overtime/models/hr_contract.py:0
#, python-format
msgid "Overtime updated"
msgstr ""

#. module: hr_contract_update_overtime
#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form
msgid ""
"This action will also reorganize all the Employee's leaves by distributing "
"them across their contract calendars. If you do not want this to happen, you"
" can Update Overtime from a specific contract."
msgstr ""

#. module: hr_contract_update_overtime
#: model:ir.actions.server,name:hr_contract_update_overtime.hr_contract_history_update_overtime_all_action
#: model_terms:ir.ui.view,arch_db:hr_contract_update_overtime.hr_contract_history_view_form
Expand Down
8 changes: 7 additions & 1 deletion hr_contract_update_overtime/models/hr_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
from datetime import datetime, timedelta

from odoo import fields, models
from odoo import _, fields, models


class HrContract(models.Model):
Expand All @@ -25,3 +25,9 @@ def action_update_overtime(self):
continue
attendances = record._get_attendances()
attendances._update_overtime()
record.message_post(
body=_("Overtime updated"),
subtype_xmlid="mail.mt_note",
message_type="comment",
author_id=self.env.user.partner_id.id,
)
16 changes: 15 additions & 1 deletion hr_contract_update_overtime/models/hr_contract_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ class HrContractHistory(models.Model):
_inherit = "hr.contract.history"

def action_update_overtime(self):
return self.mapped("contract_ids").action_update_overtime()
for record in self:
all_contracts = record.contract_ids.sorted("date_start", reverse=False)
valid_contracts = all_contracts.filtered(
lambda c: c.state in {"open", "close"}
)
for contract in valid_contracts:
other_contracts = all_contracts - contract
# Reorganize Leaves
other_contracts.resource_calendar_id.transfer_leaves_to(
contract.resource_calendar_id,
resources=contract.employee_id.resource_id,
from_date=contract.date_start,
)
# Update Overtime
self.contract_ids.action_update_overtime()
3 changes: 3 additions & 0 deletions hr_contract_update_overtime/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ You can Update Overtime in different ways:
- An action on the Contract History tree view
- Header button on Contract History form view
- Header button on Contract form view

If you Update Overtime from Contract History, leaves will also be reorganized
across their contract calendars.
2 changes: 2 additions & 0 deletions hr_contract_update_overtime/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ <h1 class="title">Update Overtime from HR Contract</h1>
<li>Header button on Contract History form view</li>
<li>Header button on Contract form view</li>
</ul>
<p>If you Update Overtime from Contract History, leaves will also be
reorganized across their contract calendars.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,59 @@ def make_dtt(days_before, h=0, m=0, to_date=False):
("employee_id", "=", cls.employee.id),
]
)
cls.overtime_model = cls.env["hr.attendance.overtime"]
# Create all leaves on last contract
leaves = cls.env["resource.calendar.leaves"].create(
[
{
"name": "Test Leave 2h",
"date_from": make_dtt(4, h=8, m=0),
"date_to": make_dtt(4, h=8, m=30),
"resource_id": cls.employee.resource_id.id,
"calendar_id": rc_8h_day.id,
"company_id": company.id,
},
{
"name": "Test Leave 4h",
"date_from": make_dtt(3, h=8, m=0),
"date_to": make_dtt(3, h=8, m=30),
"resource_id": cls.employee.resource_id.id,
"calendar_id": rc_8h_day.id,
"company_id": company.id,
},
{
"name": "Test Leave 8h",
"date_from": make_dtt(2, h=8, m=0),
"date_to": make_dtt(2, h=8, m=30),
"resource_id": cls.employee.resource_id.id,
"calendar_id": rc_8h_day.id,
"company_id": company.id,
},
]
)
# `hr_holidays_attendance` adds extra constrains when considering one
# leave valid for an employee. It wouldn't be a problem, but it's
# auto-installable. Thus, if you run this test at install time where
# that module is included for installation, it will be on scope for the
# test and break it. Therefore, we need to create the holiday request
# if it's installed, even when we don't need that dependency normally.
if "holiday_id" in leaves._fields:
leave_type = cls.env["hr.leave.type"].create(
{"name": "Beach 🏖️", "time_type": "leave"}
)
for res_leave in leaves:
res_leave.holiday_id = (
cls.env["hr.leave"]
.with_context(leave_skip_state_check=True)
.create(
{
"state": "validate",
"date_from": res_leave.date_from,
"date_to": res_leave.date_to,
"employee_id": cls.employee.id,
"holiday_status_id": leave_type.id,
}
)
)

def test_overtime(self):
self.assertEqual(self.contract_history.contract_count, 3)
Expand All @@ -210,4 +262,8 @@ def test_overtime(self):
)
.mapped("duration")
)
self.assertEqual(sum(total_overtime), -3.0)
# Check Overtime
self.assertEqual(sum(total_overtime), -1.5)
# Check Leaves has been moved correctly
for contract in self.contract_history.contract_ids:
self.assertEqual(len(contract.resource_calendar_id.leave_ids), 1)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
type="object"
groups="hr_attendance.group_hr_attendance_user"
help="Update Overtime on Running and Expired contracts"
confirm="This action will also reorganize all the Employee's leaves by distributing them across their contract calendars. If you do not want this to happen, you can Update Overtime from a specific contract."
/>
</xpath>
</field>
Expand Down
Loading