Skip to content

Commit

Permalink
[ADD] #10 allow resetting future leaves for employees, all leaves for…
Browse files Browse the repository at this point in the history
… managers.
  • Loading branch information
hbrunn committed Nov 22, 2023
1 parent 40c2efc commit 205cbe3
Show file tree
Hide file tree
Showing 4 changed files with 50 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
33 changes: 33 additions & 0 deletions verdigado_attendance/models/hr_leave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


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

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()
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>

0 comments on commit 205cbe3

Please sign in to comment.