From 5aaed9ec92fe7100147f9f7008b7af2838cb2154 Mon Sep 17 00:00:00 2001 From: "Cedric Prieels (cpr)" Date: Fri, 1 Oct 2021 09:30:39 +0000 Subject: [PATCH] [FIX] project: improve performances of has any so to invoice compute Before this commit, the compute _compute_has_any_so_to_invoice was not triggered in case of user change, which means that it could take incorrect values depending on the value of the group as it was missing the proper decorator. Also, performances were not optimal and have been improved. closes odoo/odoo#77748 X-original-commit: 1270bd5dbd51a80b3e60695da4374092c55d6e06 Signed-off-by: LTU-Odoo --- addons/sale_project/models/project.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/sale_project/models/project.py b/addons/sale_project/models/project.py index f6208df28ab..a449ac9c418 100644 --- a/addons/sale_project/models/project.py +++ b/addons/sale_project/models/project.py @@ -33,17 +33,17 @@ class Project(models.Model): ) ).update({'sale_line_id': False}) - @api.depends('sale_order_id') + @api.depends('sale_order_id.invoice_status', 'tasks.sale_order_id.invoice_status') def _compute_has_any_so_to_invoice(self): """Has any Sale Order whose invoice_status is set as To Invoice""" - if not self.user_has_groups('sales_team.group_sale_salesman_all_leads'): - self.has_any_so_to_invoice = False - else: - for project in self: - has_any_so_to_invoice = project.sale_order_id and project.sale_order_id.invoice_status == "to invoice" - for task in project.task_ids: - has_any_so_to_invoice = has_any_so_to_invoice or (task.sale_order_id and task.sale_order_id.invoice_status == "to invoice") - project.has_any_so_to_invoice = has_any_so_to_invoice + project_to_invoice = self.env['project.project'].search([ + '|', + ('sale_order_id.invoice_status', '=', 'to invoice'), + ('tasks.sale_order_id.invoice_status', '=', 'to invoice'), + ('id', 'in', self.ids) + ]) + project_to_invoice.has_any_so_to_invoice = True + (self - project_to_invoice).has_any_so_to_invoice = False def action_view_so(self): self.ensure_one()