[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) <ltu@odoo.com>
Signed-off-by: Mahendrasinh Barad (mba) <mba@odoo.com>
This commit is contained in:
hiroh-odoo
2022-06-14 14:53:52 +02:00
committed by Barad Mahendra
parent 092074cb1a
commit 9d353ac4f6
+2 -4
View File
@@ -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