[IMP] hr_attendance: faster loading of employees kanban view
**Description of the issue/feature this PR addresses:** Addon hr_attendance adds a check_in/check_out status icon in every card of the employee kanban view. The status is figured out using computed field ``attendance_state``, itself relying on a computed Many2one field, ``last_attendance_id``. The current way to compute the latter field seems to fetch all attendances before getting the most recent one. For each employee. Which causes the employee kanban view to load very slowly (~30 sec in 90-employee Camptocamp's instance). This PR suggests to load only the last attendance entry. Co-authored with @guewen **Current behavior before PR:** Employee kanban view loads very slowly. **Desired behavior after PR is merged:** Employee kanban view loads reasonably fast. -- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr closes odoo/odoo#28953
This commit is contained in:
@@ -49,7 +49,9 @@ class HrEmployee(models.Model):
|
||||
@api.depends('attendance_ids')
|
||||
def _compute_last_attendance_id(self):
|
||||
for employee in self:
|
||||
employee.last_attendance_id = employee.attendance_ids and employee.attendance_ids[0] or False
|
||||
employee.last_attendance_id = self.env['hr.attendance'].search([
|
||||
('employee_id', '=', employee.id),
|
||||
], limit=1)
|
||||
|
||||
@api.depends('last_attendance_id.check_in', 'last_attendance_id.check_out', 'last_attendance_id')
|
||||
def _compute_attendance_state(self):
|
||||
|
||||
@@ -34,3 +34,4 @@ Damien Crier damien.crier@camptocamp.com https://github.com/damdam-s
|
||||
Simone Orsi simahawk@gmail.com https://github.com/simahawk
|
||||
Patrick Tombez patrick.tombez@camptocamp.com https://github.com/p-tombez
|
||||
Julien Coux julien.coux@camptocamp.com https://github.com/jcoux
|
||||
Alexandre Saunier alexandre.saunier@camptocamp.com https://github.com/asaunier
|
||||
|
||||
Reference in New Issue
Block a user