[FIX] sale_timesheet: multiple lines create new project

- Create 2 products A & B set as:
Service Invoicing Policy: Milestones (manually set quantities on order)
Service Tracking: Create a new project but no task
- Create a SO with A & B, validate
- Set a delivered quantity for both products
- Go to the project overview

Only the delivered quantity of a single SO line is retrieved in the 'To
invoice'.

It occurs because only a single SO line is linked to the project, while
both are expected to be linked to it.

opw-2003097

closes odoo/odoo#33815

Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2019-06-04 06:02:24 +00:00
parent 0e403f8d8a
commit fea84b5757
2 changed files with 8 additions and 2 deletions
@@ -327,6 +327,12 @@ class SaleOrderLine(models.Model):
map_so_project_templates[(so_line.order_id.id, so_line.product_id.project_template_id.id)] = project
else:
map_so_project[so_line.order_id.id] = project
elif not project:
# Attach subsequent SO lines to the created project
so_line.project_id = (
map_so_project_templates.get((so_line.order_id.id, so_line.product_id.project_template_id.id))
or map_so_project.get(so_line.order_id.id)
)
if so_line.product_id.service_tracking == 'task_new_project':
if not project:
if so_line.product_id.project_template_id:
@@ -363,8 +363,8 @@ class TestSaleService(TestCommonSaleTimesheetNoChart):
# check each line has or no generate something
self.assertTrue(so_line1.project_id, "Line1 should have create a project based on template A")
self.assertTrue(so_line2.project_id, "Line2 should have create an empty project")
self.assertFalse(so_line3.project_id, "Line3 should not have create a project, since line1 already create a project based on template A")
self.assertFalse(so_line4.project_id, "Line4 should not have create a project, since line1 already create an empty project")
self.assertEqual(so_line3.project_id, so_line1.project_id, "Line3 should reuse project of line1")
self.assertEqual(so_line4.project_id, so_line2.project_id, "Line4 should reuse project of line2")
self.assertTrue(so_line4.task_id, "Line4 should have create a new task, even if no project created.")
self.assertTrue(so_line5.project_id, "Line5 should have create a project based on template B")