[CLEAN] hr_recruitment: cleaned added code in res_config
- alias finding extgracted in its own method, and uses the new ir.model.data API xmlid_to_resid - simplified code of get_default_alias and set_default_alias - alias_domain default method calls the one defined in mail.alias to try to have only one method doing the trick bzr revid: tde@openerp.com-20140211112434-iuqy2a2mrm0pmaxq
This commit is contained in:
parent
7fd1a825a8
commit
7f662d3958
|
@ -2,7 +2,7 @@
|
|||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Business Applications
|
||||
# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
|
||||
# Copyright (C) 2004-Today OpenERP S.A. (<http://openerp.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
|
@ -19,9 +19,11 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
class hr_applicant_settings(osv.osv_memory):
|
||||
|
||||
class hr_applicant_settings(osv.TransientModel):
|
||||
_name = 'hr.config.settings'
|
||||
_inherit = ['hr.config.settings', 'fetchmail.config.settings']
|
||||
|
||||
|
@ -32,43 +34,44 @@ class hr_applicant_settings(osv.osv_memory):
|
|||
'fetchmail_applicants': fields.boolean('Create applicants from an incoming email account',
|
||||
fetchmail_model='hr.applicant', fetchmail_name='Incoming HR Applications',
|
||||
help='Allow applicants to send their job application to an email address (jobs@mycompany.com), '
|
||||
'and create automatically application documents in the system.'),
|
||||
'and create automatically application documents in the system.',
|
||||
deprecated='Will be removed with OpenERP v8, not applicable anymore. Use aliases instead.'),
|
||||
'alias_prefix': fields.char('Default Alias Name for Jobs'),
|
||||
'alias_domain' : fields.char('Alias Domain'),
|
||||
'alias_domain': fields.char('Alias Domain'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'alias_domain': lambda self, cr, uid, context:self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", context=context),
|
||||
'alias_domain': lambda self, cr, uid, context: self.pool['mail.alias']._get_alias_domain(cr, SUPERUSER_ID, [1], None, None)[1],
|
||||
}
|
||||
|
||||
def _find_default_job_alias_id(self, cr, uid, context=None):
|
||||
alias_id = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'hr_recruitment.mail_alias_jobs')
|
||||
if not alias_id:
|
||||
alias_ids = self.pool['mail.alias'].search(
|
||||
cr, uid, [
|
||||
('alias_model_id.model', '=', 'hr.applicant'),
|
||||
('alias_force_thread_id', '=', 0),
|
||||
('alias_parent_model_id.model', '=', 'hr.job'),
|
||||
('alias_parent_thread_id', '=', 0),
|
||||
('alias_defaults', '=', '{}')
|
||||
], context=context)
|
||||
alias_id = alias_ids and alias_ids[0] or False
|
||||
return alias_id
|
||||
|
||||
def get_default_alias_prefix(self, cr, uid, ids, context=None):
|
||||
alias_name = ''
|
||||
mail_alias = self.pool.get('mail.alias')
|
||||
try:
|
||||
alias_name = self.pool.get('ir.model.data').get_object(cr, uid, 'hr_recruitment', 'mail_alias_jobs').alias_name
|
||||
except Exception:
|
||||
alias_ids = mail_alias.search(cr, uid, [('alias_model_id.model', '=', 'hr.applicant'), ('alias_parent_model_id.model', '=', 'hr.job'), ('alias_defaults', '=', '{}')], context=context)
|
||||
if alias_ids:
|
||||
alias_name = mail_alias.browse(cr, uid, alias_ids[0], context=context).alias_name
|
||||
alias_name = False
|
||||
alias_id = self._find_default_job_alias_id(cr, uid, context=context)
|
||||
if alias_id:
|
||||
alias_name = self.pool['mail.alias'].browse(cr, uid, alias_id, context=context).alias_name
|
||||
return {'alias_prefix': alias_name}
|
||||
|
||||
def set_default_alias_prefix(self, cr, uid, ids, context=None):
|
||||
mail_alias = self.pool.get('mail.alias')
|
||||
record = self.browse(cr, uid, ids[0], context=context)
|
||||
default_alias_prefix = self.get_default_alias_prefix(cr, uid, ids, context=context)['alias_prefix']
|
||||
if record.alias_prefix != default_alias_prefix:
|
||||
try:
|
||||
alias = self.pool.get('ir.model.data').get_object(cr, uid, 'hr_recruitment', 'mail_alias_jobs')
|
||||
if alias:
|
||||
alias.write({'alias_name': record.alias_prefix})
|
||||
except Exception:
|
||||
alias_ids = mail_alias.search(cr, uid, [('alias_model_id.model', '=', 'hr.applicant'), ('alias_parent_model_id.model', '=', 'hr.job'), ('alias_defaults', '=', '{}')], context=context)
|
||||
if alias_ids:
|
||||
mail_alias.write(cr, uid, alias_ids[0], {'alias_name': record.alias_prefix}, context=context)
|
||||
else:
|
||||
context.update({
|
||||
'alias_model_name': 'hr.applicant',
|
||||
'alias_parent_model_name': 'hr.job'
|
||||
})
|
||||
mail_alias.create(cr, uid, {'alias_name': record.alias_prefix}, context=context)
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
alias_id = self._find_default_job_alias_id(cr, uid, context=context)
|
||||
if not alias_id:
|
||||
create_ctx = dict(context, alias_model_name='hr.applicant', alias_parent_model_name='hr.job')
|
||||
alias_id = self.pool['mail.alias'].create(cr, uid, {'alias_name': record.alias_prefix}, context=create_ctx)
|
||||
else:
|
||||
mail_alias.write(cr, uid, alias_id, {'alias_name': record.alias_prefix}, context=context)
|
||||
return True
|
||||
|
|
Loading…
Reference in New Issue