[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 <IT-Ideas@users.noreply.github.com>
This commit is contained in:
Cedric Prieels (cpr)
2021-10-04 17:26:44 +00:00
parent 2cf2b8cb6f
commit 5aaed9ec92
+9 -9
View File
@@ -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()