hr_timesheet_sheet* fixes: back to list after remove a timesheet. bulk unfreeze confirmed and pending sheets

This commit is contained in:
Luis 2026-10-01 09:38:17 +02:00
parent 8b0d0bb6cc
commit 0323b6672e
11 changed files with 354 additions and 34 deletions

View file

@ -107,7 +107,46 @@ class HrTimesheetSheetDeleteWizard(models.TransientModel):
)
return Markup("").join(parts)
def _delete_cascade_list_action_xml_id(self):
"""Hook for extensions
The list the user plausibly comes from. Deleting the sheet of another
employee requires *Timesheets / Administrator*, and that sheet is only
listed by *All Timesheet Sheets*; every other case is a user looking at
his own sheets, and *My Timesheet Sheets* is the only list of sheets an
employee outside that group has a menu for.
"""
self.ensure_one()
own_sheets = self.sheet_ids.user_id == self.env.user
is_manager = self.env.user.has_group("hr_timesheet.group_timesheet_manager")
if own_sheets or not is_manager:
return "hr_timesheet_sheet.act_hr_timesheet_sheet_my_timesheets"
return "hr_timesheet_sheet.act_hr_timesheet_sheet_all_timesheets"
def _delete_cascade_next_action(self):
"""Hook for extensions
Called before the deletion, while the sheets can still be read.
Opened from a list, the caller is left on that list: closing the dialog
reloads it and keeps its filters, its grouping and its selection, and
there is no dead record on screen. Opened from the form of a sheet that
no longer exists, closing the dialog would leave that form on screen
with the values of a deleted record: return the list of sheets instead,
with ``target="main"`` so the deleted form is dropped from the
breadcrumb rather than kept one step behind.
"""
self.ensure_one()
if not self.env.context.get("sheet_delete_cascade_from_form"):
return {"type": "ir.actions.act_window_close"}
action = self.env["ir.actions.act_window"]._for_xml_id(
self._delete_cascade_list_action_xml_id()
)
action["target"] = "main"
return action
def action_confirm_delete(self):
self.ensure_one()
next_action = self._delete_cascade_next_action()
self.sheet_ids._with_delete_cascade().unlink()
return {"type": "ir.actions.act_window_close"}
return next_action

View file

@ -55,6 +55,11 @@
name="binding_model_id"
ref="hr_timesheet_sheet.model_hr_timesheet_sheet"
/>
<field name="binding_view_types">list,kanban,form</field>
<!--
Not bound to the form view: there the Delete Sheet button of the
header is the only entry point, and it is the one that tells the
wizard the sheet form has to be left behind once the sheet is gone.
-->
<field name="binding_view_types">list,kanban</field>
</record>
</odoo>