[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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.')
|
||||
|
||||
Reference in New Issue
Block a user