Skip to content

Commit

Permalink
fixup! [ADD] #75 wizard for allocation vacations
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Feb 26, 2024
1 parent 2914603 commit 7e8d52b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
20 changes: 18 additions & 2 deletions verdigado_attendance/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from datetime import timedelta

from dateutil.relativedelta import relativedelta

from odoo import fields
from odoo.tests.common import TransactionCase


Expand Down Expand Up @@ -89,9 +92,22 @@ def test_holidays_wizard_25h_week(self):
)
self.env.ref("hr.employee_qdp").write(
{
"calendar_ids": [(6, 0, []), (0, 0, {"calendar_id": calendar_25h.id})],
"calendar_ids": [
(6, 0, []),
(
0,
0,
{
"date_start": fields.Date.today()
+ relativedelta(month=1, day=1, years=1),
"date_end": fields.Date.today()
+ relativedelta(month=6, day=30, years=1),
"calendar_id": calendar_25h.id,
},
),
],
}
)
allocation = self._test_holidays_wizard()
self.assertEqual(allocation.employee_id, self.env.ref("hr.employee_qdp"))
self.assertEqual(allocation.number_of_days, 18)
self.assertEqual(allocation.number_of_days, 9)
45 changes: 37 additions & 8 deletions verdigado_attendance/wizards/verdigado_holidays_wizard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import math

from dateutil.relativedelta import relativedelta

from odoo import _, fields, models
Expand Down Expand Up @@ -50,14 +52,41 @@ def button_assign_vacation(self):
week_days = len(
set(calendar.calendar_id.mapped("attendance_ids.dayofweek"))
)
percentage += round(
(
# use month precision if calendar starts and ends on a month boundary
# use day precision otherwise
if (
max(calendar.date_start or self.date_start, self.date_start).day
== 1
and (
min(calendar.date_end or self.date_end, self.date_end)
- max(calendar.date_start or self.date_start, self.date_start)
).days
/ days,
2,
) * round(float(week_days) / 5, 2)
+ relativedelta(days=1)
).month
!= min(calendar.date_end or self.date_end, self.date_end).month
):
interval_percentage = round(
float(
min(calendar.date_end or self.date_end, self.date_end).month
- max(
calendar.date_start or self.date_start, self.date_start
).month
+ 1
)
/ (self.date_end.month - self.date_start.month + 1),
2,
)
else:
interval_percentage = round(

Check warning on line 78 in verdigado_attendance/wizards/verdigado_holidays_wizard.py

View check run for this annotation

Codecov / codecov/patch

verdigado_attendance/wizards/verdigado_holidays_wizard.py#L78

Added line #L78 was not covered by tests
(
min(calendar.date_end or self.date_end, self.date_end)
- max(
calendar.date_start or self.date_start, self.date_start
)
).days
/ days,
2,
)
percentage += interval_percentage * round(float(week_days) / 5, 2)

if percentage:
allocations += self.env["hr.leave.allocation"].create(
{
Expand All @@ -66,7 +95,7 @@ def button_assign_vacation(self):
"holiday_status_id": self.leave_type_id.id,
"date_from": self.date_start,
"date_to": self.date_end,
"number_of_days": round(percentage * self.full_vacation, 2),
"number_of_days": math.ceil(percentage * self.full_vacation),
}
)
allocations.filtered(lambda x: x.state == "draft").action_confirm()
Expand Down

0 comments on commit 7e8d52b

Please sign in to comment.