+ 'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
+ 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."""
+
+ # disable the unique alias_id not null constraint, to avoid spurious warning during
+ # super.auto_init. We'll reinstall it afterwards.
+ self._columns['alias_id'].required = False
+
+ super(hr_job,self)._auto_init(cr, context=context)
+
+ registry = RegistryManager.get(cr.dbname)
+ mail_alias = registry.get('mail.alias')
+ hr_jobs = registry.get('hr.job')
+ jobs_no_alias = hr_jobs.search(cr, SUPERUSER_ID, [('alias_id', '=', False)])
+ # Use read() not browse(), to avoid prefetching uninitialized inherited fields
+ for job_data in hr_jobs.read(cr, SUPERUSER_ID, jobs_no_alias, ['name']):
+ alias_id = mail_alias.create_unique_alias(cr, SUPERUSER_ID, {'alias_name': 'job+'+job_data['name'],
+ 'alias_defaults': {'job_id': job_data['id']}},
+ model_name='hr.applicant')
+ hr_jobs.write(cr, SUPERUSER_ID, job_data['id'], {'alias_id': alias_id})
+ _logger.info('Mail alias created for hr.job %s (uid %s)', job_data['name'], job_data['id'])
+
+ # Finally attempt to reinstate the missing constraint
+ try:
+ cr.execute('ALTER TABLE hr_job ALTER COLUMN alias_id SET NOT NULL')
+ except Exception:
+ _logger.warning("Table '%s': unable to set a NOT NULL constraint on column '%s' !\n"\
+ "If you want to have it, you should update the records and execute manually:\n"\
+ "ALTER TABLE %s ALTER COLUMN %s SET NOT NULL",
+ self._table, 'alias_id', self._table, 'alias_id')
+
+ self._columns['alias_id'].required = True
+
+ 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
+
+ def unlink(self, cr, uid, ids, context=None):
+ # Cascade-delete mail aliases as well, as they should not exist without the job position.
+ mail_alias = self.pool.get('mail.alias')
+ alias_ids = [job.alias_id.id for job in self.browse(cr, uid, ids, context=context) if job.alias_id]
+ res = super(hr_job, self).unlink(cr, uid, ids, context=context)
+ mail_alias.unlink(cr, uid, alias_ids, context=context)
+ return res
+
+ def action_print_survey(self, cr, uid, ids, context=None):
+ if context is None:
+ context = {}
+ datas = {}
+ record = self.browse(cr, uid, ids, context=context)[0]
+ if record.survey_id:
+ datas['ids'] = [record.survey_id.id]
+ datas['model'] = 'survey.print'
+ context.update({'response_id': [0], 'response_no': 0,})
+ return {
+ 'type': 'ir.actions.report.xml',
+ 'report_name': 'survey.form',
+ 'datas': datas,
+ 'context' : context,
+ 'nodestroy':True,
+ }
+
+class applicant_category(osv.osv):
+ """ Category of applicant """
+ _name = "hr.applicant_category"
+ _description = "Category of applicant"
+ _columns = {
+ 'name': fields.char('Name', size=64, required=True, translate=True),