Skip to content

Commit

Permalink
[ADD] #10 allow resetting future leaves for employees,
Browse files Browse the repository at this point in the history
all leaves for managers.
Also allow overlapping leaves
  • Loading branch information
hbrunn committed Nov 13, 2023
1 parent b25ba7a commit 04ff3c5
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions verdigado_attendance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"views/hr_attendance_view.xml",
"views/hr_attendance_report.xml",
"views/hr_leave_type.xml",
"views/hr_leave.xml",
"views/hr_menu_human_resources_configuration.xml",
"views/menu.xml",
],
Expand Down
1 change: 1 addition & 0 deletions verdigado_attendance/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from . import hr_attendance_break
from . import hr_attendance_overtime
from . import hr_attendance_report
from . import hr_leave
from . import hr_leave_type
51 changes: 51 additions & 0 deletions verdigado_attendance/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2023 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class HrLeave(models.Model):
_inherit = "hr.leave"

@api.constrains("date_from", "date_to", "employee_id")
def _check_date(self):
for this in self:
if this.holiday_status_id.allow_overlap:
self -= this
elif not self.search_count(
[
("date_from", "<", this.date_to),
("date_to", ">", this.date_from),
("employee_id", "=", this.employee_id.id),
("id", "!=", this.id),
("state", "not in", ["cancel", "refuse"]),
("holiday_status_id.allow_overlap", "=", False),
]
):
self -= this
return super(HrLeave, self)._check_date()

def _check_approval_update(self, state):
"""Always allow to reset to draft for future leaves"""
if state == "draft":
self = self.filtered(
lambda x: not x.date_from
or x.date_from.date() <= fields.Date.today()
and self.env.user.employee_id
not in (x.manager_id | x.employee_id.leave_manager_id.employee_id)
)
return super(HrLeave, self)._check_approval_update(state)

def action_draft(self):
"""Allow setting to draft from any state"""
# manipulate cache to make records look like being in state 'confirm' as
# super only allows it for this and 'refuse'
self.read([])
for this in self:
this._cache["state"] = "confirm"
return super().action_draft()

def unlink(self):
"""Reset to draft before unlink to clean up dependent objects"""
self.action_draft()
return super().unlink()
1 change: 1 addition & 0 deletions verdigado_attendance/models/hr_leave_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class HrLeaveType(models.Model):
_inherit = "hr.leave.type"

dashboard_action_id = fields.Many2one("ir.actions.actions")
allow_overlap = fields.Boolean()

def _get_days_request(self):
"""Add a formatted version for every field used in calendar header"""
Expand Down
15 changes: 15 additions & 0 deletions verdigado_attendance/views/hr_leave.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="hr_leave_view_form" model="ir.ui.view">
<field name="inherit_id" ref="hr_holidays.hr_leave_view_form" />
<field name="model">hr.leave</field>
<field name="arch" type="xml">
<button name="action_draft" position="attributes">
<attribute name="attrs">
{'invisible': ['|', ('can_reset', '=', False), ('state', '=',
'draft')]}
</attribute>
</button>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions verdigado_attendance/views/hr_leave_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<group name="verdigado">
<h2>Verdigado</h2>
<field name="dashboard_action_id" />
<field name="allow_overlap" />
</group>
</group>
</field>
Expand Down
27 changes: 27 additions & 0 deletions verdigado_attendance/views/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,32 @@
model="ir.ui.menu"
>
<field name="groups_id" eval="[(6, 0, [ref('base.group_no_one')])]" />
<record id="action_all_leaves" model="ir.actions.act_window">
<field name="name">All leaves</field>
<field name="res_model">hr.leave</field>
<field name="view_mode">tree,kanban,form,calendar,activity</field>
<field
name="groups_id"
eval="[(6, 0, [ref('hr_holidays.group_hr_holidays_responsible')])]"
/>
</record>
<menuitem
id="menu_all_leaves"
parent="hr_holidays.menu_hr_holidays_root"
action="action_all_leaves"
sequence="2"
groups="hr_holidays.group_hr_holidays_responsible"
/>
<record id="hr_holidays.menu_hr_holidays_dashboard" model="ir.ui.menu">
<field name="sequence">3</field>
</record>
<record id="hr_holidays.menu_hr_holidays_approvals" model="ir.ui.menu">
<field name="sequence">4</field>
</record>
<record id="hr_holidays.menu_hr_holidays_report" model="ir.ui.menu">
<field name="sequence">5</field>
</record>
<record id="hr_holidays.menu_hr_holidays_configuration" model="ir.ui.menu">
<field name="sequence">50</field>
</record>
</odoo>

0 comments on commit 04ff3c5

Please sign in to comment.