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

@ -44,7 +44,7 @@ class TestHrTimesheetSheetDeleteCascade(TransactionCase):
cls.employee = cls._new_employee("Cascade Employee", cls.user)
cls.employee_other = cls._new_employee("Other Employee", cls.user_other)
cls.employee_span = cls._new_employee("Span Employee", cls.user_span)
cls._new_employee("Cascade Manager", cls.user_manager)
cls.employee_manager = cls._new_employee("Cascade Manager", cls.user_manager)
cls.project = cls.env["project.project"].create(
{
@ -215,6 +215,16 @@ class TestHrTimesheetSheetDeleteCascade(TransactionCase):
.create({})
)
def _wizard_from_form(self, sheets, user=None):
user = user or self.user
action = sheets.with_user(user).action_delete_sheet()
return (
self.env["hr_timesheet.sheet.delete.wizard"]
.with_user(user)
.with_context(**action["context"])
.create({})
)
def _leave_balance(self, employee):
leave_type = self.leave_type.with_context(employee_id=employee.id)
leave_type.invalidate_recordset()
@ -357,6 +367,63 @@ class TestHrTimesheetSheetDeleteCascade(TransactionCase):
self.assertEqual(action["res_model"], "hr_timesheet.sheet.delete.wizard")
self.assertEqual(action["context"]["active_ids"], self.sheet.ids)
# Navigation once the sheet the user was looking at is gone
def test_delete_from_form_returns_to_the_sheet_list(self):
wizard = self._wizard_from_form(self.sheet)
action = wizard.action_confirm_delete()
self.assertEqual(action["type"], "ir.actions.act_window")
self.assertEqual(action["res_model"], "hr_timesheet.sheet")
self.assertEqual(action["target"], "main")
self.assertIn("tree", action["view_mode"])
self.assertFalse(self.sheet.exists())
def test_delete_from_form_returns_own_sheets_to_an_employee(self):
action = self._wizard_from_form(self.sheet).action_confirm_delete()
self.assertEqual(
action["xml_id"],
"hr_timesheet_sheet.act_hr_timesheet_sheet_my_timesheets",
)
def test_delete_from_form_returns_own_sheets_to_a_manager(self):
manager_sheet = self._new_sheet(self.employee_manager)
action = self._wizard_from_form(
manager_sheet, user=self.user_manager
).action_confirm_delete()
self.assertEqual(
action["xml_id"],
"hr_timesheet_sheet.act_hr_timesheet_sheet_my_timesheets",
)
def test_delete_of_another_employee_sheet_returns_all_sheets(self):
action = self._wizard_from_form(
self.sheet_other, user=self.user_manager
).action_confirm_delete()
self.assertEqual(
action["xml_id"],
"hr_timesheet_sheet.act_hr_timesheet_sheet_all_timesheets",
)
self.assertFalse(self.sheet_other.exists())
def test_delete_from_list_stays_on_the_list(self):
action = self._wizard(self.sheet).action_confirm_delete()
self.assertEqual(action, {"type": "ir.actions.act_window_close"})
self.assertFalse(self.sheet.exists())
def test_wizard_is_not_bound_to_the_sheet_form(self):
action = self.env.ref(
"hr_timesheet_sheet_delete_cascade"
".action_hr_timesheet_sheet_delete_wizard"
)
self.assertNotIn("form", action.binding_view_types)
def test_blocked_deletion_navigates_nowhere(self):
self.regular_line.timesheet_invoice_id = self._invoice()
wizard = self._wizard_from_form(self.sheet)
with self.assertRaises(UserError):
wizard.action_confirm_delete()
self.assertTrue(self.sheet.exists())
# RF-02
def test_cascade_deletes_timesheets(self):