File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments