diff --git a/addons/hr_timesheet/models/project_task.py b/addons/hr_timesheet/models/project_task.py index 3ee502ad559..8dea201957d 100644 --- a/addons/hr_timesheet/models/project_task.py +++ b/addons/hr_timesheet/models/project_task.py @@ -65,12 +65,12 @@ class Task(models.Model): def _compute_effective_hours(self): if not any(self._ids): for task in self: - task.effective_hours = round(sum(task.timesheet_ids.mapped('unit_amount')), 2) + task.effective_hours = sum(task.timesheet_ids.mapped('unit_amount')) return timesheet_read_group = self.env['account.analytic.line']._read_group([('task_id', 'in', self.ids)], ['task_id'], ['unit_amount:sum']) timesheets_per_task = {task.id: amount for task, amount in timesheet_read_group} for task in self: - task.effective_hours = round(timesheets_per_task.get(task.id, 0.0), 2) + task.effective_hours = timesheets_per_task.get(task.id, 0.0) @api.depends('effective_hours', 'subtask_effective_hours', 'planned_hours') def _compute_progress_hours(self): diff --git a/addons/hr_timesheet/tests/test_timesheet.py b/addons/hr_timesheet/tests/test_timesheet.py index 197086c5348..eb414391ba7 100644 --- a/addons/hr_timesheet/tests/test_timesheet.py +++ b/addons/hr_timesheet/tests/test_timesheet.py @@ -665,3 +665,31 @@ class TestTimesheet(TestCommonTimesheet): with self.assertRaises(UserError): self.task1.write({'project_id': False, 'parent_id': False}) + + def test_percentage_of_planned_hours(self): + """ Test the percentage of planned hours on a task. """ + self.task1.planned_hours = 11/60 + self.assertEqual(self.task1.effective_hours, 0, 'No timesheet should be created yet.') + self.assertEqual(self.task1.progress, 0, 'No timesheet should be created yet.') + self.env['account.analytic.line'].create([ + { + 'name': 'Timesheet', + 'project_id': self.project_customer.id, + 'task_id': self.task1.id, + 'unit_amount': 3/60, + 'employee_id': self.empl_employee.id, + }, { + 'name': 'Timesheet', + 'project_id': self.project_customer.id, + 'task_id': self.task1.id, + 'unit_amount': 4/60, + 'employee_id': self.empl_employee.id, + }, { + 'name': 'Timesheet', + 'project_id': self.project_customer.id, + 'task_id': self.task1.id, + 'unit_amount': 4/60, + 'employee_id': self.empl_employee.id, + }, + ]) + self.assertEqual(self.task1.progress, 100, 'The percentage of planned hours should be 100%.')