-
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
205 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,82 @@ | ||
# 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_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), | ||
) | ||
employee_ids = fields.Many2many("hr.employee", string="Employees") | ||
|
||
def button_assign_vacation(self): | ||
days = (self.date_end - self.date_start).days | ||
allocations = self.env["hr.leave.allocation"].browse([]) | ||
for employee in self.employee_ids or 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 | ||
week_days = len( | ||
set(calendar.calendar_id.mapped("attendance_ids.dayofweek")) | ||
) | ||
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(float(week_days) / 5, 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_vacation, 2), | ||
} | ||
) | ||
allocations.filtered(lambda x: x.state == "draft").action_confirm() | ||
allocations.filtered( | ||
lambda x: x.state in ("confirm", "validate1") | ||
).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"), | ||
} |
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
<?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 allocations proportional to a FTE with following | ||
values | ||
</div> | ||
<group> | ||
<field name="full_vacation" /> | ||
<field name="date_start" /> | ||
<field name="date_end" /> | ||
<field name="leave_type_id" /> | ||
<field | ||
name="employee_ids" | ||
widget="many2many_tags" | ||
invisible="context.get('active_model') == 'hr.employee'" | ||
required="context.get('active_model') != 'hr.employee'" | ||
/> | ||
</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> | ||
|
||
<menuitem | ||
id="menu_verdigado_holiday_wizard" | ||
parent="hr_holidays.menu_hr_holidays_approvals" | ||
action="action_verdigado_holiday_wizard" | ||
/> | ||
</odoo> |