[WIP]hr_employee_stats_sheet:add domaine on recovery type

This commit is contained in:
2025-09-16 16:19:22 +02:00
parent 29976fb9a4
commit 80d27f4bbd
4 changed files with 16 additions and 3 deletions

View File

@@ -69,7 +69,7 @@ msgstr "Indiquer le coefficient multiplicateur à appliquer sur les heures suppl
msgid "Choose the recovery type."
msgstr ""
"Sélectionner le type de congé utilisé pour générer des allocations de "
"récupération"
"récupération. Le type de congé doit accepter les allocations négatives et être pris à l'heure."
#. module: hr_employee_stats_sheet
#: model_terms:ir.ui.view,arch_db:hr_employee_stats_sheet.res_config_settings_view_form

View File

@@ -190,7 +190,10 @@ class HrTimesheetSheet(models.Model):
raise UserError(
_("Employe not defined for the timesheet sheet or recovery type not defined in settings")
)
if recovery_type_id.request_unit != 'hour' or not recovery_type_id.allows_negative:
raise UserError(
_("The recovery type must be set to 'Hours' and allow negative leaves in the settings")
)
# check if allocation already exists for this timesheet sheet, if yes, refuse it
allocations = (
self.env["hr.leave.allocation"]
@@ -217,7 +220,6 @@ class HrTimesheetSheet(models.Model):
data_days = recovery_type_id.get_employees_days([employee_id.id])[employee_id.id]
total_recovery_type_leaves = data_days.get(recovery_type_id.id,{})
total_virtual_remaining_recovery_type_leaves = total_recovery_type_leaves.get('virtual_remaining_leaves', 0)
# TODO vérifier si ça marche avec un recovery type dont l'unité de mesure est le jour
# add the recovery hours to the total remaining leaves recovery type, and check if the limit of recovery hours is exceeded
exceeded_hours = total_virtual_remaining_recovery_type_leaves + recovery_hours - max_allowed_recovery_hours
# if limit recovery hours is exceeded, don't create a new allocation

View File

@@ -9,6 +9,7 @@ class ResConfigSettings(models.TransientModel):
related="company_id.recovery_type_id",
string="Leave recovery type",
readonly=False,
domain="[('request_unit', '=', 'hour'), ('allows_negative', '=', True)]",
)
coef = fields.Float(

View File

@@ -14,6 +14,7 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
self.recovery_type = self.env['hr.leave.type'].create({
'name': 'Recovery',
'request_unit': 'hour',
'allows_negative': True,
})
self.employee = self.env['hr.employee'].create({
'name': 'Camille',
@@ -63,6 +64,15 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
stat._compute_hours()
yield stat
def test_invalide_recovery_type(self):
start_date = date.today() - timedelta(days=date.today().weekday() + 7) # lundi de la semaine dernière
self.recovery_type.request_unit = 'day'
self.recovery_type.allows_negative = False
timesheet_sheet = self._create_timesheet_sheet(start_date)
self.env.company.recovery_type_id = self.recovery_type
with self.assertRaises(UserError):
timesheet_sheet.action_generate_recovery_allocation()
def test_no_recovery_hours(self):
start_date = date.today() - timedelta(days=date.today().weekday() + 7) # lundi de la semaine dernière
timesheet_sheet = self._create_timesheet_sheet(start_date)