From ba839226544adbd013286fe23c500b5bb7796fd9 Mon Sep 17 00:00:00 2001 From: "Victor Piryns (pivi)" Date: Fri, 9 Feb 2024 15:34:41 +0100 Subject: [PATCH] [PERF] hr_homeworking: remove `.id` from left leafs of domains Description: Domains of the form ```python [('stored_Many2X.id', '=/!=/in/not in', list_of_ids)] ``` will force the ORM to generate a sub-`SELECT` (or `LEFT JOIN` in case of `auto_join=True`), which is inefficient, as the `id` can be retrieved directly from the current `model` table, instead of going to fetch it from the `PKey` of the `comodel` table. There is just one *important* detail - in the sub-select, the `ir.rule` of the `comodel` is applied, which is not the case when directly referencing the `field` from the `model`. So in some cases using an explicit `.id` would be a wanted, if the intention was to apply the `ir.rule`. Fix: Remove the `.id` from left leafs of domains that if the field is stored, and the `comodel` doesn't have `ir.rule` associated with it, or the `ir.rule` application is redundant/not needed. `.id` task-3735923 closes odoo/odoo#153475 Signed-off-by: Sofie Gvaladze (sgv) --- addons/hr_homeworking/models/res_partner.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/hr_homeworking/models/res_partner.py b/addons/hr_homeworking/models/res_partner.py index 99ab4c03195..64a8b5de859 100644 --- a/addons/hr_homeworking/models/res_partner.py +++ b/addons/hr_homeworking/models/res_partner.py @@ -7,9 +7,7 @@ class ResPartner(models.Model): def _compute_im_status(self): super()._compute_im_status() - users = self.env["res.users"].search([ - ('partner_id.id', 'in', self.ids)]) - for user in users: + for user in self.user_ids: dayfield = self.env['hr.employee']._get_current_day_location_field() location_type = user[dayfield].location_type if not location_type: @@ -20,6 +18,6 @@ class ResPartner(models.Model): def get_worklocation(self, start_date, end_date): employee_id = self.env['hr.employee'].search([ - ('work_contact_id.id', 'in', self.ids), - ('company_id.id', '=', self.env.company.id)]) + ('work_contact_id', 'in', self.ids), + ('company_id', '=', self.env.company.id)]) return employee_id._get_worklocation(start_date, end_date)