diff --git a/addons/hr_recruitment/hr_recruitment.py b/addons/hr_recruitment/hr_recruitment.py
index b0b60db6bd5..b7348957736 100644
--- a/addons/hr_recruitment/hr_recruitment.py
+++ b/addons/hr_recruitment/hr_recruitment.py
@@ -504,29 +504,18 @@ class hr_job(osv.osv):
help="Email alias for this job position. New emails will automatically "
"create new applicants for this job position."),
}
- _defaults = {
- 'alias_domain': False, # always hide alias during creation
- }
def _auto_init(self, cr, context=None):
"""Installation hook to create aliases for all jobs and avoid constraint errors."""
- self.pool.get('mail.alias').migrate_to_alias(cr, self._name, self._table, super(hr_job,self)._auto_init,
+ self.pool.get('mail.alias').migrate_to_alias(cr, self._name, self._table, super(hr_job, self)._auto_init,
self._columns['alias_id'], 'name', alias_prefix='job+', alias_defaults={'job_id': 'id'}, context=context)
def create(self, cr, uid, vals, context=None):
- mail_alias = self.pool.get('mail.alias')
- if not vals.get('alias_id'):
- vals.pop('alias_name', None) # prevent errors during copy()
- alias_id = mail_alias.create_unique_alias(cr, uid,
- # Using '+' allows using subaddressing for those who don't
- # have a catchall domain setup.
- {'alias_name': 'jobs+'+vals['name']},
- model_name="hr.applicant",
- context=context)
- vals['alias_id'] = alias_id
- res = super(hr_job, self).create(cr, uid, vals, context)
- mail_alias.write(cr, uid, [vals['alias_id']], {"alias_defaults": {'job_id': res}}, context)
- return res
+ create_context = dict(context, alias_model_name=self._name)
+ job_id = super(hr_job, self).create(cr, uid, vals, context=create_context)
+ job = self.browse(cr, uid, job_id, context=context)
+ self.pool.get('mail.alias').write(cr, uid, [job.alias_id.id], {"alias_defaults": {'job_id': job_id}}, context)
+ return job_id
def unlink(self, cr, uid, ids, context=None):
# Cascade-delete mail aliases as well, as they should not exist without the job position.
@@ -544,15 +533,16 @@ class hr_job(osv.osv):
if record.survey_id:
datas['ids'] = [record.survey_id.id]
datas['model'] = 'survey.print'
- context.update({'response_id': [0], 'response_no': 0,})
+ context.update({'response_id': [0], 'response_no': 0})
return {
'type': 'ir.actions.report.xml',
'report_name': 'survey.form',
'datas': datas,
- 'context' : context,
- 'nodestroy':True,
+ 'context': context,
+ 'nodestroy': True,
}
+
class applicant_category(osv.osv):
""" Category of applicant """
_name = "hr.applicant_category"
diff --git a/addons/hr_recruitment/hr_recruitment_view.xml b/addons/hr_recruitment/hr_recruitment_view.xml
index b531677d538..10c42637e46 100644
--- a/addons/hr_recruitment/hr_recruitment_view.xml
+++ b/addons/hr_recruitment/hr_recruitment_view.xml
@@ -315,13 +315,13 @@
-
-
+
+ %%
+
+
-
- @
-
+ %%
+ @
diff --git a/addons/mail/mail_alias.py b/addons/mail/mail_alias.py
index dad69fd8be3..51f9d36ab8d 100644
--- a/addons/mail/mail_alias.py
+++ b/addons/mail/mail_alias.py
@@ -39,6 +39,7 @@ def remove_accents(input_str):
nkfd_form = unicodedata.normalize('NFKD', input_str)
return u''.join([c for c in nkfd_form if not unicodedata.combining(c)])
+
class mail_alias(osv.Model):
"""A Mail Alias is a mapping of an email address with a given OpenERP Document
model. It is used by OpenERP's mail gateway when processing incoming emails
@@ -47,7 +48,7 @@ class mail_alias(osv.Model):
of that alias. If the message is a reply it will be attached to the
existing discussion on the corresponding record, otherwise a new
record of the corresponding model will be created.
-
+
This is meant to be used in combination with a catch-all email configuration
on the company's mail server, so that as soon as a new mail.alias is
created, it becomes immediately usable and OpenERP will accept email for it.
@@ -63,7 +64,7 @@ class mail_alias(osv.Model):
return dict.fromkeys(ids, domain or "")
_columns = {
- 'alias_name': fields.char('Alias', required=True,
+ 'alias_name': fields.char('Alias',
help="The name of the email alias, e.g. 'jobs' "
"if you want to catch emails for
",),
'alias_model_id': fields.many2one('ir.model', 'Aliased Model', required=True, ondelete="cascade",
@@ -147,7 +148,8 @@ class mail_alias(osv.Model):
return new_name
def migrate_to_alias(self, cr, child_model_name, child_table_name, child_model_auto_init_fct,
- alias_id_column, alias_key, alias_prefix = '', alias_force_key = '', alias_defaults = {}, context=None):
+ alias_id_column, alias_key, alias_prefix='', alias_force_key='', alias_defaults={},
+ alias_generate_name=False, context=None):
""" Installation hook to create aliases for all users and avoid constraint errors.
:param child_model_name: model name of the child class (i.e. res.users)
@@ -156,14 +158,12 @@ class mail_alias(osv.Model):
(i.e. super(res_users,self)._auto_init(cr, context=context))
:param alias_id_column: alias_id column (i.e. self._columns['alias_id'])
:param alias_key: name of the column used for the unique name (i.e. 'login')
- :param alias_prefix: prefix for the unique name (i.e. 'jobs' + ...)
:param alias_force_key': name of the column for force_thread_id;
if empty string, not taken into account
:param alias_defaults: dict, keys = mail.alias columns, values = child
model column name used for default values (i.e. {'job_id': 'id'})
"""
-
- # disable the unique alias_id not null constraint, to avoid spurious warning during
+ # disable the unique alias_id not null constraint, to avoid spurious warning during
# super.auto_init. We'll reinstall it afterwards.
alias_id_column.required = False
@@ -173,16 +173,18 @@ class mail_alias(osv.Model):
registry = RegistryManager.get(cr.dbname)
mail_alias = registry.get('mail.alias')
child_class_model = registry.get(child_model_name)
- no_alias_ids = child_class_model.search(cr, SUPERUSER_ID, [('alias_id', '=', False)], context={'active_test':False})
+ no_alias_ids = child_class_model.search(cr, SUPERUSER_ID, [('alias_id', '=', False)], context={'active_test': False})
# Use read() not browse(), to avoid prefetching uninitialized inherited fields
for obj_data in child_class_model.read(cr, SUPERUSER_ID, no_alias_ids, [alias_key]):
- alias_vals = {'alias_name': '%s%s' % (alias_prefix, obj_data[alias_key]) }
+ alias_vals = {'alias_name': False}
+ if alias_generate_name:
+ alias_vals['alias_name'] = '%s%s' % (alias_prefix, obj_data[alias_key])
if alias_force_key:
alias_vals['alias_force_thread_id'] = obj_data[alias_force_key]
- alias_vals['alias_defaults'] = dict( (k, obj_data[v]) for k, v in alias_defaults.iteritems())
- alias_id = mail_alias.create_unique_alias(cr, SUPERUSER_ID, alias_vals, model_name=child_model_name)
+ alias_vals['alias_defaults'] = dict((k, obj_data[v]) for k, v in alias_defaults.iteritems())
+ alias_id = mail_alias.create(cr, SUPERUSER_ID, alias_vals, {'alias_model_name': child_model_name})
child_class_model.write(cr, SUPERUSER_ID, obj_data['id'], {'alias_id': alias_id})
- _logger.info('Mail alias created for %s %s (uid %s)', child_model_name, obj_data[alias_key], obj_data['id'])
+ _logger.info('Mail alias created for %s %s (id %s)', child_model_name, obj_data[alias_key], obj_data['id'])
# Finally attempt to reinstate the missing constraint
try:
@@ -196,19 +198,36 @@ class mail_alias(osv.Model):
# set back the unique alias_id constraint
alias_id_column.required = True
- def create_unique_alias(self, cr, uid, vals, model_name=None, context=None):
- """Creates an email.alias record according to the values provided in ``vals``,
- with 2 alterations: the ``alias_name`` value may be suffixed in order to
- make it unique (and certain unsafe characters replaced), and
- he ``alias_model_id`` value will set to the model ID of the ``model_name``
- value, if provided,
+ def create(self, cr, uid, vals, context=None):
+ """ Creates an email.alias record according to the values provided in ``vals``,
+ with 2 alterations: the ``alias_name`` value may be suffixed in order to
+ make it unique (and certain unsafe characters replaced), and
+ he ``alias_model_id`` value will set to the model ID of the ``model_name``
+ context value, if provided.
"""
+ if context is None:
+ context = {}
+ model_name = context.get('alias_model_name')
# when an alias name appears to already be an email, we keep the local part only
- alias_name = remove_accents(vals['alias_name']).lower().split('@')[0]
- alias_name = re.sub(r'[^\w+.]+', '-', alias_name)
- alias_name = self._find_unique(cr, uid, alias_name, context=context)
- vals['alias_name'] = alias_name
+ if vals.get('alias_name'):
+ alias_name = remove_accents(vals['alias_name']).lower().split('@')[0]
+ alias_name = re.sub(r'[^\w+.]+', '-', alias_name)
+ alias_name = self._find_unique(cr, uid, alias_name, context=context)
+ vals['alias_name'] = alias_name
if model_name:
model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', model_name)], context=context)[0]
vals['alias_model_id'] = model_id
- return self.create(cr, uid, vals, context=context)
+ res = super(mail_alias, self).create(cr, uid, vals, context=context)
+ return res
+
+ def open_document(self, cr, uid, ids, context=None):
+ alias = self.browse(cr, uid, ids, context=context)[0]
+ if not alias.alias_model_id or not alias.alias_force_thread_id:
+ return False
+ return {
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': alias.alias_model_id.model,
+ 'res_id': alias.alias_force_thread_id,
+ 'type': 'ir.actions.act_window',
+ }
diff --git a/addons/mail/mail_alias_view.xml b/addons/mail/mail_alias_view.xml
index e0d8e173ebc..53b673b51b6 100644
--- a/addons/mail/mail_alias_view.xml
+++ b/addons/mail/mail_alias_view.xml
@@ -9,7 +9,6 @@
@@ -44,8 +45,10 @@
+
+
-
+
@@ -55,6 +58,10 @@
Aliases
mail.alias
+ {
+ 'search_default_active': True,
+ }
+