-
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.
Merge pull request #38 from hbrunn/15.0-10-leaves
[ADD] #10 allow resetting future leaves for employees,
- Loading branch information
Showing
4 changed files
with
50 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
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,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() |
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,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> |