-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] #75 wizard for allocation vacations
fixes #75
- Loading branch information
Showing
7 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
from . import verdigado_holidays_wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import _, fields, models | ||
|
||
|
||
class VerdigadoHolidaysWizard(models.TransientModel): | ||
_name = "verdigado.holidays.wizard" | ||
_description = "Create holidays allocations" | ||
|
||
full_weekly_hours = fields.Float( | ||
default=38, | ||
string="Weekly hours (100%)", | ||
required=True, | ||
help="Weekly hours of a FTE", | ||
) | ||
full_vacation = fields.Float( | ||
default=30, | ||
string="Vacation days (100%)", | ||
required=True, | ||
help="Vacation of a FTE in days", | ||
) | ||
date_start = fields.Date( | ||
required=True, | ||
default=lambda self: fields.Date.today() | ||
+ relativedelta(month=1, day=1, years=1), | ||
) | ||
date_end = fields.Date( | ||
required=True, | ||
default=lambda self: fields.Date.today() | ||
+ relativedelta(month=12, day=31, years=1), | ||
) | ||
leave_type_id = fields.Many2one( | ||
"hr.leave.type", | ||
required=True, | ||
default=lambda self: self.env.ref("hr_holidays.holiday_status_cl", False), | ||
) | ||
|
||
def button_assign_vacation(self): | ||
days = (self.date_end - self.date_start).days | ||
allocations = self.env["hr.leave.allocation"].browse([]) | ||
for employee in self.env["hr.employee"].browse( | ||
self.env.context.get("active_ids", []) | ||
): | ||
percentage = 0.0 | ||
for calendar in employee.calendar_ids: | ||
if ( | ||
calendar.date_start | ||
and calendar.date_start >= self.date_end | ||
or calendar.date_end | ||
and calendar.date_end <= self.date_start | ||
): | ||
continue | ||
weekly_hours = sum( | ||
calendar.calendar_id.mapped("attendance_ids").mapped( | ||
lambda x: x.hour_to - x.hour_from | ||
) | ||
) | ||
percentage += round( | ||
( | ||
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(weekly_hours / self.full_weekly_hours, 2) | ||
if percentage: | ||
allocations += self.env["hr.leave.allocation"].create( | ||
{ | ||
"name": str(self.date_start.year), | ||
"employee_id": employee.id, | ||
"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_weekly_hours, 2), | ||
} | ||
) | ||
allocations.action_confirm() | ||
allocations.action_validate() | ||
return { | ||
"type": "ir.actions.act_window", | ||
"res_model": "hr.leave.allocation", | ||
"views": [(False, "list"), (False, "form")], | ||
"domain": [("id", "in", allocations.ids)], | ||
"name": _("Created allocations"), | ||
} |
38 changes: 38 additions & 0 deletions
38
verdigado_attendance/wizards/verdigado_holidays_wizard.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="verdigado_holiday_wizard_form" model="ir.ui.view"> | ||
<field name="model">verdigado.holidays.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<div> | ||
This wizard creates allocation proportional to a FTE with following | ||
values | ||
</div> | ||
<group> | ||
<field name="full_weekly_hours" /> | ||
<field name="full_vacation" /> | ||
<field name="date_start" /> | ||
<field name="date_end" /> | ||
<field name="leave_type_id" /> | ||
</group> | ||
<footer> | ||
<button | ||
string="Create allocations" | ||
name="button_assign_vacation" | ||
type="object" | ||
class="btn-primary" | ||
/> | ||
<button string="Discard" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="action_verdigado_holiday_wizard" model="ir.actions.act_window"> | ||
<field name="name">Allocate vacation</field> | ||
<field name="res_model">verdigado.holidays.wizard</field> | ||
<field name="view_mode">form</field> | ||
<field name="target">new</field> | ||
<field name="binding_model_id" ref="hr.model_hr_employee" /> | ||
</record> | ||
</odoo> |