From 9d353ac4f6f0db05a882fc07bcf3b4e6370a6959 Mon Sep 17 00:00:00 2001 From: hiroh-odoo Date: Wed, 20 Apr 2022 11:13:40 +0000 Subject: [PATCH] [FIX] sale_timesheet: fix the computation of allocated_hours on project Before this commit: - When project is created from SO, the quantity of SOL is set in allocated hours. Then, when navigating to the 'invoicing' tab and adding an employee mapping, the `allocated hours` is reset to 0. - When manually removing the SOL of a project, the allocated_hours is reset to 0. After this commit, the above issues have been fixed. task-2788878 closes odoo/odoo#93580 X-original-commit: dbcdefc20c676248438643a97fa62ca7fd197671 Signed-off-by: Laurent Stukkens (ltu) Signed-off-by: Mahendrasinh Barad (mba) --- addons/sale_timesheet/models/project.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 09105eee8b4..5035f7019a2 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -200,15 +200,13 @@ class Project(models.Model): uoms_dict = {uom.id: uom for uom in self.env['uom.uom'].browse(uom_ids)} for project in self: - if not project.sale_line_id: - project.allocated_hours = 0 - continue + project_id = project.id or project._origin.id # sale order line may be stored in a different unit of measure, so first # we convert all of them to the reference unit # if the sol has no product_uom_id then we take the one of the project allocated_hours = sum([ product_uom_qty * uoms_dict.get(product_uom, project.timesheet_encode_uom_id.id).factor_inv - for product_uom, product_uom_qty in sol_qty_dict[project.id] + for product_uom, product_uom_qty in sol_qty_dict[project_id] ], 0.0) # Now convert to the unit of measure to hours allocated_hours *= uom_hour.factor