Skip to content
Snippets Groups Projects
Commit 3b1316e7 authored by Hamza (hisl)'s avatar Hamza (hisl)
Browse files

[FIX] hr_timesheet : update effective_hours for progress_hours computation


Steps to reproduce the issue:

Add a project and create a task with a timesheet in it
set the allocated hours to 00:03
add a line in the timesheet with hours spent 00:03
Current Behaviour:
The percentage calculated would be 96%, even though the time allocated and time spent are equal.

Desired Behaviour:
The percentage should be 100 as both values i.e. time spent and time allocated are equal.

This is happening because effective_hours value is being rounded off to 2 decimal places, and is not accurate enough to compute the progress_hours.

Here, I have used the same line, that is used to compute effective_hours, to compute the task_total_hours but without rounding off. This will make the calculate more precise and accurate.

OPW-3270858

closes odoo/odoo#121168

Signed-off-by: default avatarXavier Bol (xbo) <xbo@odoo.com>
parent 39f23ac5
Branches
Tags
No related merge requests found
......@@ -130,12 +130,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)], ['unit_amount', 'task_id'], ['task_id'])
timesheets_per_task = {res['task_id'][0]: res['unit_amount'] for res 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):
......
......@@ -499,3 +499,31 @@ class TestTimesheet(TestCommonTimesheet):
self.assertEqual(timesheet.product_uom_id, self.project_customer.company_id.project_time_mode_id,
"The product_uom_id of the timesheet should be equal to the project's company uom "
"if the project's analytic account has no company_id")
def test_percentage_of_planned_hours(self):
""" Test the percentage of planned hours on a task. """
self.task1.planned_hours = round(11/60, 2)
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%.')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment