[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) <sgv@odoo.com>
This commit is contained in:
Victor Piryns (pivi)
2024-02-12 20:24:10 +00:00
parent 96703da336
commit ba83922654
+3 -5
View File
@@ -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)