summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobot Odoo <xmo+roboto@odoo.com>2018-11-28 14:49:44 +0100
committerGitHub <noreply@github.com>2018-11-28 14:49:44 +0100
commit34b26bc7d6ea5b1bca9cab0f0bb41d993984f2af (patch)
tree2fa60f4dced9fdde6bb3ddace473cdbc92b1daab
parentd1490e27774193487df81733fdabf5f3d1f97f55 (diff)
parent1d2a4d8459cf07703f22b207b38c483b684a472a (diff)
[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
-rw-r--r--addons/hr_attendance/models/hr_employee.py4
-rw-r--r--doc/cla/corporate/camptocamp.md1
2 files changed, 4 insertions, 1 deletions
diff --git a/addons/hr_attendance/models/hr_employee.py b/addons/hr_attendance/models/hr_employee.py
index 3521acb64de..8ff4baf4ebc 100644
--- a/addons/hr_attendance/models/hr_employee.py
+++ b/addons/hr_attendance/models/hr_employee.py
@@ -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):
diff --git a/doc/cla/corporate/camptocamp.md b/doc/cla/corporate/camptocamp.md
index 206fad26646..e4206b66474 100644
--- a/doc/cla/corporate/camptocamp.md
+++ b/doc/cla/corporate/camptocamp.md
@@ -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