hr_employee.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from odoo import api, fields, models
  3. from odoo.tools.translate import _
  4. from datetime import timedelta
  5. class HrEmployee(models.Model):
  6. _inherit = "hr.employee"
  7. newly_hired_employee = fields.Boolean('Newly hired employee', compute='_compute_newly_hired_employee',
  8. search='_search_newly_hired_employee')
  9. applicant_id = fields.One2many('hr.applicant', 'emp_id', 'Applicant')
  10. def _compute_newly_hired_employee(self):
  11. now = fields.Datetime.now()
  12. for employee in self:
  13. employee.newly_hired_employee = bool(employee.create_date > (now - timedelta(days=90)))
  14. def _search_newly_hired_employee(self, operator, value):
  15. employees = self.env['hr.employee'].search([
  16. ('create_date', '>', fields.Datetime.now() - timedelta(days=90))
  17. ])
  18. return [('id', 'in', employees.ids)]
  19. @api.model_create_multi
  20. def create(self, vals_list):
  21. employees = super().create(vals_list)
  22. for employee in employees:
  23. if employee.applicant_id:
  24. employee.applicant_id.message_post_with_view(
  25. 'hr_recruitment.applicant_hired_template',
  26. values={'applicant': employee.applicant_id},
  27. subtype_id=self.env.ref("hr_recruitment.mt_applicant_hired").id)
  28. return employees