From 1121aa7ab1a6130184a961990850dda4e69329a7 Mon Sep 17 00:00:00 2001 From: "lase@odoo.com" Date: Mon, 18 Mar 2024 10:21:36 +0100 Subject: [PATCH] [FIX] sale_project: omit notes SOL in project status Reported issue: Steps to reproduce: Be sure that 'industry_fsm' is installed. - Go to Project > Projects and swap to the list view - Create and save a new project with a customer - Access the related SO via the smart button - Add a service product, a storable product a section and a note - Go back and access the project status with the smart button > The SOL generated for the section and the note appear as SO items Expected behavior: The purpose of the project status tab is to have an overview at the project to help in the analyse its profitability, the time investment,.. as such, these SOL should not be considered as SO items. In addition, these lines lose their entire purpose in the list view used in this overview (they can not be moved and display irrelevant infos). Cause of the issue: These lines were not filtered out by the current query. opw-3794386 closes odoo/odoo#157984 Signed-off-by: Lancelot Semal (lase) --- addons/sale_project/models/project.py | 6 ++- .../sale_project/tests/test_sale_project.py | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/addons/sale_project/models/project.py b/addons/sale_project/models/project.py index dc4ac212e01..8fd57f10ac1 100755 --- a/addons/sale_project/models/project.py +++ b/addons/sale_project/models/project.py @@ -338,7 +338,11 @@ class Project(models.Model): ) SaleOrderLine = self.env['sale.order.line'] - sale_order_line_domain = [('order_id', 'any', [('analytic_account_id', 'in', self.analytic_account_id.ids)])] + sale_order_line_domain = [ + '&', + ('order_id', 'any', [('analytic_account_id', 'in', self.analytic_account_id.ids)]), + ('display_type', '=', False), + ] sale_order_line_query = SaleOrderLine._where_calc(sale_order_line_domain) sale_order_line_sql = sale_order_line_query.select( f'{SaleOrderLine._table}.project_id AS id', diff --git a/addons/sale_project/tests/test_sale_project.py b/addons/sale_project/tests/test_sale_project.py index 71e82bb9fee..d02ce535b4c 100644 --- a/addons/sale_project/tests/test_sale_project.py +++ b/addons/sale_project/tests/test_sale_project.py @@ -648,3 +648,46 @@ class TestSaleProject(TestSaleProjectCommon): sale_line = self.env['sale.order.line'].browse(sale_line_id) self.assertEqual(sale_line.product_id, product_service, 'The created SOL should use the right product.') self.assertTrue(product_service.name in sale_line_name, 'The created SOL should use the full name of the product and not just what was typed.') + + def test_sale_order_items_of_the_project_status(self): + """ + Checks that the sale order items appearing in the project status display every + sale.order.line referrencing a product ignores the notes and sections + """ + analytic_account = self.env['account.analytic.account'].create({ + 'name': 'Project X', + 'plan_id': self.env.ref('analytic.analytic_plan_projects').id, + }) + project = self.env['project.project'].create({ + 'name': 'Project X', + 'partner_id': self.partner.id, + 'allow_billable': True, + 'analytic_account_id': analytic_account.id, + }) + sale_order = self.env['sale.order'].create({ + 'partner_id': self.partner.id, + 'project_id': project.id, + 'order_line': [ + Command.create({ + 'product_id': self.product_order_service1.id, + 'product_uom_qty': 1, + }), + Command.create({ + 'name': "Section", + 'display_type': "line_section", + }), + Command.create({ + 'name': "notes", + 'display_type': "line_section", + }), + Command.create({ + 'product_id': self.product_a.id, + 'product_uom_qty': 1, + }), + ], + 'analytic_account_id': analytic_account.id, + }) + relevant_sale_order_lines = sale_order.order_line.filtered(lambda sol: sol.product_id) + reported_sale_order_lines = self.env['sale.order.line'].search(project.action_view_sols()['domain']) + self.assertEqual(project.sale_order_line_count, 2) + self.assertEqual(relevant_sale_order_lines, reported_sale_order_lines)