Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] #10 allow resetting future leaves for employees, #38

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading