From 3d08f7d4c87fe83d1aae8cf3d9107bbfadf850bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir?= Date: Fri, 17 Jul 2020 10:25:39 +0000 Subject: [PATCH] [FIX] sale_timesheet: correctly trigger compute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revision fad3ed7ce4828275e92e8f748dbb7cdc4156fb57 introduced a forced recompute of `billable_type` which unfortunately has repercutions (compute triggers) upon every single task of a project, meaning that it will not scale properly as the number of tasks grows and it is now called everytime we want to access a project view form whch is a terrible performance drop. The underlying issue that it tried to address was that the field billable_type was not correctly computed when deleting the linked sale_order_id from the project. This happens because when deleting a record, it is PSQL that sets relational m2o value (in this cas sale_order_id to NULL and the ORM has no way to catch that information. A proper fix consists to change the dependency of the computed field from the m2o to one of its fields. This will properly mark 'billable_type' to be recomputed when unlinking the sale order. Note that to avoid useless recomputation which would lead to the sale result, we rely on a filed that should not change once the sale order is created. closes odoo/odoo#54817 X-original-commit: 4f2b532c3ef4ebd9beb2a448f59c4e645ba1e8a1 Signed-off-by: Rémi Rahir (rar) --- addons/sale_timesheet/models/project.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 77af2fcb7be..0e4f2a69cd0 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -61,13 +61,12 @@ class Project(models.Model): @api.depends('billable_type', 'allow_billable', 'sale_order_id', 'partner_id') def _compute_display_create_order(self): for project in self: - project._compute_billable_type() show = True if not project.partner_id or project.billable_type != 'no' or project.allow_billable or project.sale_order_id: show = False project.display_create_order = show - @api.depends('sale_order_id', 'sale_line_id', 'sale_line_employee_ids') + @api.depends('sale_order_id.create_date', 'sale_line_id', 'sale_line_employee_ids') def _compute_billable_type(self): for project in self: billable_type = 'no'