[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>
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user