diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2019-11-26 09:11:34 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-11-26 11:54:15 +0000 |
| commit | 70d856f2c7c0ba8358af86a243ee4b872e057e2b (patch) | |
| tree | 404fd91d9b428b28753d2e46f58faec7283c663d | |
| parent | 4f226e78930b07dff231e72c8c926273c7111337 (diff) | |
[FIX] hr_recruitment: newly hired
The current 'Newly Hired' filter is incorrect in several ways:
- the compute method doesn't assign the value correctly
- the search method mixes `hr.applicant` IDs with `hr.employee` IDs
Moreover, it relies on the fact that the job position is closed. Some
positions might always be opened, so the result is inaccurate.
We make the simpler assumption that the newly hired people are employees
created less than 90 days ago.
opw-2125861
closes odoo/odoo#40899
X-original-commit: ee928babbe433285883f1e878d83392d7199a37d
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
| -rw-r--r-- | addons/hr_recruitment/models/hr_employee.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/addons/hr_recruitment/models/hr_employee.py b/addons/hr_recruitment/models/hr_employee.py index e1b58cf9705..a6f44e22da8 100644 --- a/addons/hr_recruitment/models/hr_employee.py +++ b/addons/hr_recruitment/models/hr_employee.py @@ -1,6 +1,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models +from datetime import timedelta class HrEmployee(models.Model): @@ -10,13 +11,12 @@ class HrEmployee(models.Model): search='_search_newly_hired_employee') def _compute_newly_hired_employee(self): - read_group_result = self.env['hr.applicant'].read_group( - [('emp_id', 'in', self.ids), ('job_id.state', '=', 'recruit')], - ['emp_id'], ['emp_id']) - result = dict((data['emp_id'], data['emp_id_count'] > 0) for data in read_group_result) - for record in self: - record.newly_hired_employee = result.get(record.id, False) + now = fields.Datetime.now() + for employee in self: + employee.newly_hired_employee = bool(employee.create_date > (now - timedelta(days=90))) def _search_newly_hired_employee(self, operator, value): - applicants = self.env['hr.applicant'].search([('job_id.state', '=', 'recruit')]) - return [('id', 'in', applicants.ids)] + employees = self.env['hr.employee'].search([ + ('create_date', '>', fields.Datetime.now() - timedelta(days=90)) + ]) + return [('id', 'in', employees.ids)] |
