From c17bc5090d4819cfd7a8b5dd137cf8da66bad782 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Thu, 18 Dec 2014 14:56:56 +0100 Subject: [PATCH] [FIX] hr_recruitment: use utm_mixin to allow to track the job applicant. Remove old source_id Use hr.recruitment.source to generate link with utm and create alias with default value for utm [FIX] crm/utm: Fix bug with utm (ddac26cdbb3535239f5dbb41f5b464366065f3ba) Move demo into data Move ir_http to save the utm in the dispatch --- addons/crm/__init__.py | 1 - addons/hr_recruitment/__openerp__.py | 1 + addons/hr_recruitment/hr_recruitment.py | 52 +++++++++++++++++-- addons/hr_recruitment/hr_recruitment_data.xml | 20 ++----- addons/hr_recruitment/hr_recruitment_view.xml | 38 ++++++++++++-- addons/utm/__openerp__.py | 7 +-- addons/utm/models/__init__.py | 3 +- addons/{crm => utm/models}/ir_http.py | 0 addons/utm/models/utm.py | 2 +- addons/utm/{utm_demo.xml => utm_data.xml} | 0 .../controllers/main.py | 1 - 11 files changed, 95 insertions(+), 30 deletions(-) rename addons/{crm => utm/models}/ir_http.py (100%) rename addons/utm/{utm_demo.xml => utm_data.xml} (100%) diff --git a/addons/crm/__init__.py b/addons/crm/__init__.py index 6da405201fc..19e8d476633 100644 --- a/addons/crm/__init__.py +++ b/addons/crm/__init__.py @@ -23,7 +23,6 @@ import crm import crm_lead import sales_team import calendar_event -import ir_http import crm_phonecall import report import wizard diff --git a/addons/hr_recruitment/__openerp__.py b/addons/hr_recruitment/__openerp__.py index ac73ccbc830..20745f84c01 100644 --- a/addons/hr_recruitment/__openerp__.py +++ b/addons/hr_recruitment/__openerp__.py @@ -46,6 +46,7 @@ You can define the different phases of interviews and easily rate the applicant 'calendar', 'fetchmail', 'web_kanban_gauge', + 'utm', ], 'data': [ 'wizard/hr_recruitment_create_partner_job_view.xml', diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py index 919980b46df..0fd1b2ccb46 100644 --- a/addons/hr_recruitment/hr_recruitment.py +++ b/addons/hr_recruitment/hr_recruitment.py @@ -19,6 +19,7 @@ # ############################################################################## +import werkzeug from datetime import datetime from openerp import tools @@ -38,8 +39,54 @@ class hr_recruitment_source(osv.osv): """ Sources of HR Recruitment """ _name = "hr.recruitment.source" _description = "Source of Applicants" + _inherits = {"utm.source": "source_id"} + + def _get_url(self, cr, uid, ids, field_name, arg, context=None): + result = {} + imd = self.pool['ir.model.data'] + for source in self.browse(cr, uid, ids, context=context): + if not source.alias_id.id: + result[source.id] = '' + else: + result[source.id] = werkzeug.url_encode({ + 'utm_campaign': imd.xmlid_to_object(cr, SUPERUSER_ID, 'hr_recruitment.utm_campaign_job').name, + 'utm_medium': imd.xmlid_to_object(cr, SUPERUSER_ID, 'utm.utm_medium_website').name, + 'utm_source': source.source_id.name + }) + return result + + def create_alias(self, cr, uid, ids, context=None): + imd = self.pool['ir.model.data'] + for source in self.browse(cr, uid, ids, context=context): + alias_context = dict(context or {}, alias_model_name='hr.applicant', alias_parent_model_name='hr.job') + vals = { + 'alias_parent_thread_id': source.job_id.id, + 'alias_name': "%s+%s" % (source.job_id.alias_name or source.job_id.name, source.name), + 'alias_defaults': { + 'job_id': source.job_id.id, + 'campaign_id': imd.xmlid_to_res_id(cr, SUPERUSER_ID, 'hr_recruitment.utm_campaign_job'), + 'medium_id': imd.xmlid_to_res_id(cr, SUPERUSER_ID, 'utm.utm_medium_email'), + 'source_id': source.source_id.id, + }, + } + new_alias_id = self.pool['mail.alias'].create(cr, uid, vals, alias_context) + source.write({'alias_id': new_alias_id, 'name': source.source_id.name}) + return + + def _get_source(self, cr, uid, ids, context=None): + if ids: + return self.pool['hr.recruitment.source'].search(cr, uid, [('source_id', 'in', ids)], context=context) + return [] + _columns = { - 'name': fields.char('Source Name', required=True, translate=True), + 'source_id': fields.many2one('utm.source', 'Source', ondelete='cascade', required=True), + 'url': fields.function(_get_url, string='Url', type='char', store={ + 'hr.recruitment.source': (lambda self, cr, uid, ids, ctx: ids, ['source_id'], 20), + 'utm.source': (_get_source, ['name'], 20), + }), + 'email': fields.related('alias_id', 'alias_name', string='Email', readonly=True, type='char'), + 'job_id': fields.many2one('hr.job', 'Job ID'), + 'alias_id': fields.many2one('mail.alias', 'Alias ID'), } class hr_recruitment_stage(osv.osv): @@ -83,7 +130,7 @@ class hr_applicant(osv.Model): _name = "hr.applicant" _description = "Applicant" _order = "priority desc, id desc" - _inherit = ['mail.thread', 'ir.needaction_mixin'] + _inherit = ['mail.thread', 'ir.needaction_mixin', 'utm.mixin'] _track = { 'emp_id': { @@ -223,7 +270,6 @@ class hr_applicant(osv.Model): 'survey': fields.related('job_id', 'survey_id', type='many2one', relation='survey.survey', string='Survey'), 'response_id': fields.many2one('survey.user_input', "Response", ondelete='set null', oldname="response"), 'reference': fields.char('Referred By'), - 'source_id': fields.many2one('hr.recruitment.source', 'Source'), 'day_open': fields.function(_compute_day, string='Days to Open', multi='day_open', type="float", store={'hr.applicant': (lambda self, cr, uid, ids, c={}: ids, ['date_open'], 10)}), diff --git a/addons/hr_recruitment/hr_recruitment_data.xml b/addons/hr_recruitment/hr_recruitment_data.xml index 3093dea99ea..e5246ff6ad5 100644 --- a/addons/hr_recruitment/hr_recruitment_data.xml +++ b/addons/hr_recruitment/hr_recruitment_data.xml @@ -54,22 +54,6 @@ ${object.user_id.signature | safe}]]> - - - - LinkedIn - - - Monster - - - Word of Mouth - - - Company Website - - - @@ -182,5 +166,9 @@ Sales + + Job Campaign + + diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml index 6ae299af1c9..370a608c203 100644 --- a/addons/hr_recruitment/hr_recruitment_view.xml +++ b/addons/hr_recruitment/hr_recruitment_view.xml @@ -34,7 +34,6 @@ - Applicants @@ -53,7 +52,8 @@ - + + @@ -139,6 +139,7 @@ + @@ -337,6 +338,23 @@

+ + Jobs Sources + hr.recruitment.source + tree,form + [('job_id', '=', active_id)] + {'default_job_id': active_id} + +

+ Create here some alias... + That will allow you to track from where the applicant is coming from... +

+

+ Create email and url for each distinct source.
+ When the applicant will arrive, you will know from wich source the Job position is coming. +

+
+
@@ -419,6 +437,11 @@ type="object"> + @@ -654,7 +677,10 @@ hr.recruitment.source - + + + +