Skip to content

Commit

Permalink
Merge pull request #75 from kmee/fix-overtime
Browse files Browse the repository at this point in the history
Fix overtime
  • Loading branch information
mileo authored Dec 3, 2024
2 parents beab389 + a6098d2 commit 1baaba3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
20 changes: 19 additions & 1 deletion hr_holidays_allocation_plan/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _get_running_contracts(self, employee):
.search(
[
("employee_id", "=", employee.id),
("state", "=", "open"),
("state", "in", ("open", "close")),
],
)
.mapped("date_start")
Expand All @@ -298,8 +298,14 @@ def _create_recurrent(self, employee, running_contracts):
current_date = (
oldest_running_contract # Start allocation from contract start date
)
jump = False

while current_date < fields.Date.today():

if self.immediate_allocation and not jump:
current_date += relativedelta(years=self.recurring_renewal_frequency)
jump = True

date_from = current_date
date_to = date_from + relativedelta(years=self.validity_period)

Expand Down Expand Up @@ -406,6 +412,14 @@ def action_cancel(self):
for record in self:
record.state = "cancel"

def action_back2draft(self):
for record in self:
if record.state == "cancel":
record.state = "draft"
record.action_allocation_refuse()
record.action_allocation_draft()
record.action_allocation_unlink()

def action_allocation_refuse(self):
for record in self:
record.allocation_ids.action_refuse()
Expand All @@ -414,6 +428,10 @@ def action_allocation_draft(self):
for record in self:
record.allocation_ids.action_draft()

def action_allocation_unlink(self):
for record in self:
record.allocation_ids.unlink()

def action_allocation_confirm(self):
for record in self:
record.allocation_ids.action_confirm()
10 changes: 10 additions & 0 deletions hr_holidays_allocation_plan/views/hr_leave_allocation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
type="object"
/>
<button string="Cancel" name="action_cancel" type="object" />
<button
string="Back to Draft"
name="action_back2draft"
type="object"
/>
<field
name="state"
widget="statusbar"
Expand Down Expand Up @@ -144,6 +149,11 @@
name="action_allocation_draft"
type="object"
/>
<button
string="Allocation Delete"
name="action_allocation_unlink"
type="object"
/>
<field name="allocation_ids" nolabel="1">
<tree>
<field name="create_date" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from datetime import date, datetime

from odoo import api, fields, models


Expand Down Expand Up @@ -32,18 +34,19 @@ def _compute_total_hours(self):
total_hours = fields.Float(compute="_compute_total_hours", store=True)

@api.model
def _search_overtime_range(self, date, employee_id=None):
if not date:
def _search_overtime_range(self, attendance_date, employee_id=None):
if not attendance_date:
return self

exception_id = self.env["hr.attendance.exception"]

day_name = fields.Date.from_string(date).strftime("%A").lower()
day_name = fields.Date.from_string(attendance_date).strftime("%A").lower()
domain = []

if employee_id:
exception_id = exception_id.search(
[("employee_id", "=", employee_id.id), ("date", "=", date)], limit=1
[("employee_id", "=", employee_id.id), ("date", "=", attendance_date)],
limit=1,
)

if exception_id:
Expand All @@ -66,7 +69,15 @@ def _search_overtime_range(self, date, employee_id=None):
elif day_name == "sunday":
domain.append(("sunday", "=", True))

if employee_id and employee_id.resource_calendar_id.data_eh_feriado(date):
# 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())

if employee_id and employee_id.resource_calendar_id.data_eh_feriado(
attendance_date
):
domain.append(("holiday", "=", True))

overtime_ranges = self.search(domain)
Expand Down

0 comments on commit 1baaba3

Please sign in to comment.