Skip to content

Commit 3a7160b

Browse files
HashemKhaledmepe-odoo
authored andcommitted
[FIX] hr: allow version deletion for employees with multiple versions
This makes it possible to delete a version if there are multiple versions for one employee. Task: 5232093
1 parent a165720 commit 3a7160b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

addons/hr/models/hr_employee.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ def _compute_legal_name(self):
495495
@api.depends('current_version_id')
496496
@api.depends_context('version_id')
497497
def _compute_version_id(self):
498-
context_version = self.env['hr.version'].browse(self.env.context.get('version_id', False))
498+
context_version_id = self.env.context.get('version_id', False)
499+
context_version = self.env['hr.version'].browse(context_version_id).exists() if context_version_id else self.env['hr.version']
499500

500501
for employee in self:
501502
if context_version.employee_id == self:

addons/hr/tests/test_hr_version.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,20 @@ def test_hr_version_fields_tracking(self):
676676
fields_without_tracking,
677677
f"The following hr.version fields should have tracking=True: {fields_without_tracking}",
678678
)
679+
680+
def test_delete_hr_version(self):
681+
employee = self.env['hr.employee'].create(
682+
{
683+
'name': 'John Doe',
684+
'date_version': '2024-01-01',
685+
}
686+
)
687+
688+
version1 = employee.version_id
689+
version2 = employee.create_version({
690+
'date_version': '2025-01-01',
691+
})
692+
693+
version1.unlink()
694+
with self.assertRaises(ValidationError):
695+
version2.unlink()

0 commit comments

Comments
 (0)