From fcba642d6f124d95ad9f32098cb9e2d8ebee6d10 Mon Sep 17 00:00:00 2001 From: lbs-odoo Date: Wed, 16 Jan 2019 08:54:44 +0000 Subject: [PATCH] [IMP] hr_recruitment : add favorite job & new application count, modify views - hr.job receives the favorite functionnality. - Now, a newly created hr.job is favorite by default. - hr.job receives a new field new_application_count that computes the number of applications which are new in the flow for that job (1st step of the recruitment flow). - hr.job kanban boxes now display the field described just above. - hr.job kanban boxes are now clickable and thus open related applications in a kanban view. - Views are modified according to the images given in the related task (see Task ID below). These changes are details such as modifying strings that are displayed or their position in the view, or again icons that are displayed. -> Note : Check related task to see decisions that have been made concerning these images. - Search on Email on hr.applicant has been separated so that it is clearer. - Rename old view crm_case_form_view_job into hr_applicant_view_form Task ID : 1896305 --- addons/hr/views/hr_views.xml | 2 +- addons/hr_recruitment/models/hr_job.py | 45 ++++++++++++++++++- .../hr_recruitment/models/hr_recruitment.py | 6 +-- .../static/src/js/recruitment.js | 18 ++++++++ addons/hr_recruitment/views/hr_job_views.xml | 45 +++++++++---------- .../views/hr_recruitment_templates.xml | 1 + .../views/hr_recruitment_views.xml | 23 +++++----- .../views/hr_applicant_views.xml | 4 +- .../views/hr_job_views.xml | 1 - .../views/hr_job_views.xml | 2 +- 10 files changed, 100 insertions(+), 47 deletions(-) create mode 100644 addons/hr_recruitment/static/src/js/recruitment.js diff --git a/addons/hr/views/hr_views.xml b/addons/hr/views/hr_views.xml index 9f71be2a9c4..8519fdd9020 100644 --- a/addons/hr/views/hr_views.xml +++ b/addons/hr/views/hr_views.xml @@ -506,7 +506,7 @@

- + diff --git a/addons/hr_recruitment/models/hr_job.py b/addons/hr_recruitment/models/hr_job.py index 9510a2f0660..4e710b73706 100644 --- a/addons/hr_recruitment/models/hr_job.py +++ b/addons/hr_recruitment/models/hr_job.py @@ -6,21 +6,29 @@ from odoo import api, fields, models, _ class Job(models.Model): _name = "hr.job" _inherit = ["mail.alias.mixin", "hr.job"] + _order = "state desc, name asc" @api.model def _default_address_id(self): return self.env.user.company_id.partner_id + def _get_default_favorite_user_ids(self): + return [(6, 0, [self.env.uid])] + address_id = fields.Many2one( 'res.partner', "Job Location", default=_default_address_id, help="Address where employees are working") application_ids = fields.One2many('hr.applicant', 'job_id', "Applications") application_count = fields.Integer(compute='_compute_application_count', string="Application Count") + new_application_count = fields.Integer( + compute='_compute_new_application_count', string="New Application", + help="Number of applications that are new in the flow (typically at first step of the flow)") manager_id = fields.Many2one( 'hr.employee', related='department_id.manager_id', string="Department Manager", readonly=True, store=True) - user_id = fields.Many2one('res.users', "Recruitment Responsible", tracking=True) - hr_responsible_id = fields.Many2one('res.users', "HR Responsible", tracking=True, + user_id = fields.Many2one('res.users', "Responsible", tracking=True) + hr_responsible_id = fields.Many2one( + 'res.users', "HR Responsible", tracking=True, help="Person responsible of validating the employee's contracts.") document_ids = fields.One2many('ir.attachment', compute='_compute_document_ids', string="Documents") documents_count = fields.Integer(compute='_compute_document_ids', string="Document Count") @@ -28,6 +36,22 @@ class Job(models.Model): 'mail.alias', "Alias", ondelete="restrict", required=True, help="Email alias for this job position. New emails will automatically create new applicants for this job position.") color = fields.Integer("Color Index") + is_favorite = fields.Boolean(compute='_compute_is_favorite', inverse='_inverse_is_favorite') + favorite_user_ids = fields.Many2many('res.users', 'job_favorite_user_rel', 'job_id', 'user_id', default=_get_default_favorite_user_ids) + + def _compute_is_favorite(self): + for job in self: + job.is_favorite = self.env.user in job.favorite_user_ids + + def _inverse_is_favorite(self): + unfavorited_jobs = favorited_jobs = self.env['hr.job'] + for job in self: + if self.env.user in job.favorite_user_ids: + unfavorited_jobs |= job + else: + favorited_jobs |= job + favorited_jobs.write({'favorite_user_ids': [(4, self.env.uid)]}) + unfavorited_jobs.write({'favorite_user_ids': [(3, self.env.uid)]}) def _compute_document_ids(self): applicants = self.mapped('application_ids').filtered(lambda self: not self.emp_id) @@ -54,6 +78,22 @@ class Job(models.Model): for job in self: job.application_count = result.get(job.id, 0) + def _get_first_stage(self): + self.ensure_one() + return self.env['hr.recruitment.stage'].search([ + '|', + ('job_id', '=', False), + ('job_id', '=', self.id)], order='sequence asc', limit=1) + + def _compute_new_application_count(self): + first_stages = {job.id: job._get_first_stage().id for job in self} + mapped_data = dict.fromkeys(self.ids, 0) + for applicant in self.mapped('application_ids'): + if applicant.stage_id.id == first_stages.get(applicant.job_id.id): + mapped_data[applicant.job_id.id] += 1 + for job in self: + job.new_application_count = mapped_data.get(job.id) + def get_alias_model_name(self, vals): return 'hr.applicant' @@ -68,6 +108,7 @@ class Job(models.Model): @api.model def create(self, vals): + vals['favorite_user_ids'] = vals.get('favorite_user_ids', []) + [(4, self.env.uid)] return super(Job, self.with_context(mail_create_nolog=True)).create(vals) @api.multi diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index 0e4b5fa400c..b1299e50299 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -96,14 +96,12 @@ class Applicant(models.Model): def _default_stage_id(self): if self._context.get('default_job_id'): - ids = self.env['hr.recruitment.stage'].search([ + return self.env['hr.recruitment.stage'].search([ '|', ('job_id', '=', False), ('job_id', '=', self._context['default_job_id']), ('fold', '=', False) - ], order='sequence asc', limit=1).ids - if ids: - return ids[0] + ], order='sequence asc', limit=1).id return False def _default_company_id(self): diff --git a/addons/hr_recruitment/static/src/js/recruitment.js b/addons/hr_recruitment/static/src/js/recruitment.js new file mode 100644 index 00000000000..e9758ddabf8 --- /dev/null +++ b/addons/hr_recruitment/static/src/js/recruitment.js @@ -0,0 +1,18 @@ +odoo.define('job.update_kanban', function (require) { + 'use strict'; + var KanbanRecord = require('web.KanbanRecord'); + + KanbanRecord.include({ + /** + * @override + * @private + */ + _openRecord: function () { + if (this.modelName === 'hr.job' && this.$(".o_hr_job_boxes a").length) { + this.$(".o_hr_job_boxes a").first().click(); + } else { + this._super.apply(this, arguments); + } + } + }); +}); diff --git a/addons/hr_recruitment/views/hr_job_views.xml b/addons/hr_recruitment/views/hr_job_views.xml index 945ea855bca..fff1cfe6d54 100644 --- a/addons/hr_recruitment/views/hr_job_views.xml +++ b/addons/hr_recruitment/views/hr_job_views.xml @@ -16,19 +16,22 @@ + + -
+
-
+
+
@@ -39,24 +42,17 @@
-
-
- -
+
+ New Applications
+ Hired Employees
-
- - - Hired Employees - -
@@ -66,18 +62,19 @@
-
diff --git a/addons/hr_recruitment/views/hr_recruitment_templates.xml b/addons/hr_recruitment/views/hr_recruitment_templates.xml index ac00cd7c2ec..dd5e72ee93f 100644 --- a/addons/hr_recruitment/views/hr_recruitment_templates.xml +++ b/addons/hr_recruitment/views/hr_recruitment_templates.xml @@ -4,6 +4,7 @@ diff --git a/addons/hr_recruitment/views/hr_recruitment_views.xml b/addons/hr_recruitment/views/hr_recruitment_views.xml index dd11f066c78..b298ebc7bb1 100644 --- a/addons/hr_recruitment/views/hr_recruitment_views.xml +++ b/addons/hr_recruitment/views/hr_recruitment_views.xml @@ -62,7 +62,7 @@ - + Jobs - Recruitment Form hr.applicant @@ -202,7 +202,8 @@ hr.applicant - + + @@ -296,13 +297,13 @@
@@ -335,7 +336,7 @@
- + @@ -403,6 +404,9 @@ + + + @@ -466,7 +470,7 @@ -