From c1feb0deafd68d744d05bd0b9603fd6ceb94f59c Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Tue, 10 May 2022 10:39:45 +0200 Subject: [PATCH] [IMP] sale_project: get the SOL from the milestone to task if no SOL found Before this commit, the compute of `sale_line_id` field searches a SOL to set to each task containing in `self` as default value for `sale_line_id`. If no SOL is found in the parent task or the project set into the task then no SOL will set. Since a milestone can be set to a task and a milestone can have a SOL set in its model, the task could have the one of the milestone if no SOL is found. This commit sets the SOL from the milestone to the task if no SOL is found in the project or the parent task related to that task. task-2829542 --- addons/sale_project/models/project.py | 4 ++-- .../tests/test_so_line_milestones.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/sale_project/models/project.py b/addons/sale_project/models/project.py index 9b7113a381d..3b12797eb9e 100644 --- a/addons/sale_project/models/project.py +++ b/addons/sale_project/models/project.py @@ -496,12 +496,12 @@ class ProjectTask(models.Model): task.partner_id = sale_order_id.partner_id task.sale_order_id = sale_order_id - @api.depends('commercial_partner_id', 'sale_line_id.order_partner_id', 'parent_id.sale_line_id', 'project_id.sale_line_id') + @api.depends('commercial_partner_id', 'sale_line_id.order_partner_id', 'parent_id.sale_line_id', 'project_id.sale_line_id', 'milestone_id.sale_line_id') def _compute_sale_line(self): for task in self: if not task.sale_line_id: # if the display_project_id is set then it means the task is classic task or a subtask with another project than its parent. - task.sale_line_id = task.display_project_id.sale_line_id or task.parent_id.sale_line_id or task.project_id.sale_line_id + task.sale_line_id = task.display_project_id.sale_line_id or task.parent_id.sale_line_id or task.project_id.sale_line_id or task.milestone_id.sale_line_id # check sale_line_id and customer are coherent if task.sale_line_id.order_partner_id.commercial_partner_id != task.partner_id.commercial_partner_id: task.sale_line_id = False diff --git a/addons/sale_project/tests/test_so_line_milestones.py b/addons/sale_project/tests/test_so_line_milestones.py index 8b33b666592..c804e0215e5 100644 --- a/addons/sale_project/tests/test_so_line_milestones.py +++ b/addons/sale_project/tests/test_so_line_milestones.py @@ -9,8 +9,8 @@ from odoo.tests.common import tagged class TestSoLineMilestones(TestSaleCommon): @classmethod - def setUpClass(cls): - super().setUpClass() + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) uom_hour = cls.env.ref('uom.product_uom_hour') @@ -107,3 +107,17 @@ class TestSoLineMilestones(TestSaleCommon): self.milestone1.unlink() self.assertEqual(self.sol1.qty_delivered, 0.0, "Delivered quantity should update when a milestone is removed") + + def test_compute_sale_line_in_task(self): + task = self.env['project.task'].create({ + 'name': 'Test Task', + 'project_id': self.project.id, + }) + self.assertEqual(task.sale_line_id, self.sol1, 'The task should have the one of the project linked') + self.project.sale_line_id = False + task.sale_line_id = False + self.assertFalse(task.sale_line_id) + task.write({'milestone_id': self.milestone1.id}) + self.assertEqual(task.sale_line_id, self.milestone1.sale_line_id, 'The task should have the SOL from the milestone.') + self.project.sale_line_id = self.sol2 + self.assertEqual(task.sale_line_id, self.sol1, 'The task should keep the SOL linked to the milestone.')