diff --git a/hr_employee_stats_sheet/i18n/fr.po b/hr_employee_stats_sheet/i18n/fr.po index 9efd36a..609a751 100644 --- a/hr_employee_stats_sheet/i18n/fr.po +++ b/hr_employee_stats_sheet/i18n/fr.po @@ -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 diff --git a/hr_employee_stats_sheet/models/hr_timesheet_sheet.py b/hr_employee_stats_sheet/models/hr_timesheet_sheet.py index ca82407..681862c 100644 --- a/hr_employee_stats_sheet/models/hr_timesheet_sheet.py +++ b/hr_employee_stats_sheet/models/hr_timesheet_sheet.py @@ -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 diff --git a/hr_employee_stats_sheet/models/res_config.py b/hr_employee_stats_sheet/models/res_config.py index c54d034..da3e403 100644 --- a/hr_employee_stats_sheet/models/res_config.py +++ b/hr_employee_stats_sheet/models/res_config.py @@ -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( diff --git a/hr_employee_stats_sheet/tests/test_employee_stats.py b/hr_employee_stats_sheet/tests/test_employee_stats.py index 0aff8fe..2594b3b 100644 --- a/hr_employee_stats_sheet/tests/test_employee_stats.py +++ b/hr_employee_stats_sheet/tests/test_employee_stats.py @@ -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)