[FIX] hr_timesheet: fix timesheet computation between hours and days
Steps to reproduce: - Install Project, Timesheets. - Create a new porject with allocated hours set to 40 hours (5 days). - Taking into account that our company have a 8-hour/day work schedule (40 hours/week). - We go then to the timesheet app and we add a line for the project created with 8 hours as hours spent. - Now we got to the timesheet configuration and we change the uom to days. - We go back to the timesheet app and we see the result, we can also try to add just 1 day. Issue: The days are not properly computed, only when we are in hours are being computed properly. But when we change the uom to days, the computation that we see in the list will still be wrong. Solution: We really take into account which uom are we working with so we compute the time properly depending on the uom. opw-3138053 closes odoo/odoo#115049 X-original-commit: a31a1b6aff4db0415dc9c44bae33901f4833aba1 Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
@@ -154,10 +154,10 @@ class Project(models.Model):
|
||||
# Timesheets may be stored in a different unit of measure, so first
|
||||
# we convert all of them to the reference unit
|
||||
# if the timesheet has no product_uom_id then we take the one of the project
|
||||
total_time = sum([
|
||||
unit_amount * uoms_dict.get(product_uom_id, project.timesheet_encode_uom_id).factor_inv
|
||||
for product_uom_id, unit_amount in timesheet_time_dict[project.id]
|
||||
], 0.0)
|
||||
total_time = 0.0
|
||||
for product_uom_id, unit_amount in timesheet_time_dict[project.id]:
|
||||
factor = uoms_dict.get(product_uom_id, project.timesheet_encode_uom_id).factor_inv
|
||||
total_time += unit_amount * (1.0 if project.encode_uom_in_days else factor)
|
||||
# Now convert to the proper unit of measure set in the settings
|
||||
total_time *= project.timesheet_encode_uom_id.factor
|
||||
project.total_timesheet_time = int(round(total_time))
|
||||
|
||||
@@ -564,3 +564,27 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
'unit_amount': 3,
|
||||
})
|
||||
self.assertEqual(timesheet.employee_id, self.empl_employee)
|
||||
|
||||
def test_uom_change_timesheet(self):
|
||||
"""
|
||||
We check that we don't over transform the timesheet unit amount when changing
|
||||
the company encoding timesheet uom, we keep it in the project as hours.
|
||||
So it will be transformed only once when encoding the timesheet.
|
||||
"""
|
||||
Timesheet = self.env['account.analytic.line']
|
||||
project = self.env['project.project'].create({
|
||||
'name': 'Project',
|
||||
'allow_timesheets': True,
|
||||
'partner_id': self.partner.id,
|
||||
})
|
||||
project.allocated_hours = 40.0
|
||||
|
||||
Timesheet.create({
|
||||
'name': 'FirstTimeSheet',
|
||||
'project_id': project.id,
|
||||
'unit_amount': 8,
|
||||
'employee_id': self.empl_employee2.id
|
||||
})
|
||||
self.env.company.timesheet_encode_uom_id = self.env.ref('uom.product_uom_day')
|
||||
self.assertEqual(project.total_timesheet_time, 8, "Total timesheet time should be 8 hours")
|
||||
self.assertEqual(project.timesheet_encode_uom_id.name, 'Days', "Timesheet encode uom should be 'Days'")
|
||||
|
||||
Reference in New Issue
Block a user