Skip to content
Closed
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 hr_holidays_ux/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizard
3 changes: 2 additions & 1 deletion hr_holidays_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
"name": "Holidays UX",
"version": "19.0.1.0.0",
"version": "19.0.1.1.0",
"category": "Human Resources",
"sequence": 14,
"summary": "Split time off records by month",
Expand All @@ -31,6 +31,7 @@
"hr_holidays",
],
"data": [
"data/ir_actions_server.xml",
"views/hr_leave_type_views.xml",
"views/hr_leave_views.xml",
],
Expand Down
11 changes: 11 additions & 0 deletions hr_holidays_ux/data/ir_actions_server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="action_reset_allocation_to_confirm" model="ir.actions.server">
<field name="name">Reset to "To Approve"</field>
<field name="model_id" ref="hr_holidays.model_hr_leave_allocation"/>
<field name="binding_model_id" ref="hr_holidays.model_hr_leave_allocation"/>
<field name="binding_view_types">list</field>
<field name="state">code</field>
<field name="code">records.action_reset_to_confirm()</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions hr_holidays_ux/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import hr_leave
from . import hr_leave_allocation
from . import hr_leave_type
22 changes: 22 additions & 0 deletions hr_holidays_ux/models/hr_leave_allocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import _, models
from odoo.exceptions import UserError


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

def action_reset_to_confirm(self):
"""Revert validated allocations back to 'To Approve' (confirm) state.

Blocked when any selected allocation has leaves already taken, since
reverting the approval would make those days go into deficit.
Permission checks (officer/manager role) are enforced by
_check_approval_update inside write().
"""
blocked = self.filtered(lambda a: a.leaves_taken > 0)
if blocked:
raise UserError(
_("The following allocations already have leaves taken and cannot be reset:\n%s")
% "\n".join(blocked.mapped("display_name"))
)
self.filtered(lambda a: a.state in ("validate", "validate1")).write({"state": "confirm"})
1 change: 1 addition & 0 deletions hr_holidays_ux/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_leave_allocation_generate_multi_wizard
46 changes: 46 additions & 0 deletions hr_holidays_ux/wizard/hr_leave_allocation_generate_multi_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from datetime import date

from odoo import models


class HrLeaveAllocationGenerateMultiWizard(models.TransientModel):
_inherit = "hr.leave.allocation.generate.multi.wizard"

def action_generate_allocations(self):
"""Override to prevent auto-approval after batch creation.

Upstream calls action_approve() right after create(), bypassing the
validation flow configured on the leave type. We reproduce the method
without those calls so allocations land in 'confirm' (To Approve).
no_validation types still auto-approve via the create() hook in
hr.leave.allocation.
"""
self.ensure_one()
employees = self._get_employees_from_allocation_mode()
vals_list = self._prepare_allocation_values(employees)
if not vals_list:
return None
allocations = (
self.env["hr.leave.allocation"]
.with_context(
mail_notify_force_send=False,
mail_activity_automation_skip=True,
)
.create(vals_list)
)
accrual_allocations = allocations.filtered(lambda a: a.allocation_type == "accrual")
for date_to, allocation in accrual_allocations.grouped("date_to").items():
date_to = min(date_to, date.today()) if date_to else False
allocation._process_accrual_plans(date_to)
return {
"type": "ir.actions.act_window",
"name": self.env._("Generated Allocations"),
"views": [
[self.env.ref("hr_holidays.hr_leave_allocation_view_tree").id, "list"],
[self.env.ref("hr_holidays.hr_leave_allocation_view_form_manager").id, "form"],
],
"view_mode": "list",
"res_model": "hr.leave.allocation",
"domain": [("id", "in", allocations.ids)],
"context": {"active_id": False},
}
Loading