[FIX] stock: packages menuitem hidden by the right group. sale_stock: fixed bug ...
[odoo/odoo.git] / addons / hr_recruitment / res_config.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Business Applications
5 #    Copyright (C) 2004-Today OpenERP S.A. (<http://openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp import SUPERUSER_ID
23 from openerp.osv import fields, osv
24
25
26 class hr_applicant_settings(osv.TransientModel):
27     _name = 'hr.config.settings'
28     _inherit = ['hr.config.settings', 'fetchmail.config.settings']
29
30     _columns = {
31         'module_document': fields.boolean('Allow the automatic indexation of resumes',
32             help='Manage your CV\'s and motivation letter related to all applicants.\n'
33                  '-This installs the module document_ftp. This will install the knowledge management  module in order to allow you to search using specific keywords through  the content of all documents (PDF, .DOCx...)'),
34         'fetchmail_applicants': fields.boolean('Create applicants from an incoming email account',
35             fetchmail_model='hr.applicant', fetchmail_name='Incoming HR Applications',   
36             help='Allow applicants to send their job application to an email address (jobs@mycompany.com), '
37                  'and create automatically application documents in the system.',
38             deprecated='Will be removed with OpenERP v8, not applicable anymore. Use aliases instead.'),
39         'alias_prefix': fields.char('Default Alias Name for Jobs'),
40         'alias_domain': fields.char('Alias Domain'),
41     }
42
43     _defaults = {
44         'alias_domain': lambda self, cr, uid, context: self.pool['mail.alias']._get_alias_domain(cr, SUPERUSER_ID, [1], None, None)[1],
45     }
46
47     def _find_default_job_alias_id(self, cr, uid, context=None):
48         alias_id = self.pool['ir.model.data'].xmlid_to_res_id(cr, uid, 'hr_recruitment.mail_alias_jobs')
49         if not alias_id:
50             alias_ids = self.pool['mail.alias'].search(
51                 cr, uid, [
52                     ('alias_model_id.model', '=', 'hr.applicant'),
53                     ('alias_force_thread_id', '=', False),
54                     ('alias_parent_model_id.model', '=', 'hr.job'),
55                     ('alias_parent_thread_id', '=', False),
56                     ('alias_defaults', '=', '{}')
57                 ], context=context)
58             alias_id = alias_ids and alias_ids[0] or False
59         return alias_id
60
61     def get_default_alias_prefix(self, cr, uid, ids, context=None):
62         alias_name = False
63         alias_id = self._find_default_job_alias_id(cr, uid, context=context)
64         if alias_id:
65             alias_name = self.pool['mail.alias'].browse(cr, uid, alias_id, context=context).alias_name
66         return {'alias_prefix': alias_name}
67
68     def set_default_alias_prefix(self, cr, uid, ids, context=None):
69         mail_alias = self.pool.get('mail.alias')
70         for record in self.browse(cr, uid, ids, context=context):
71             alias_id = self._find_default_job_alias_id(cr, uid, context=context)
72             if not alias_id:
73                 create_ctx = dict(context, alias_model_name='hr.applicant', alias_parent_model_name='hr.job')
74                 alias_id = self.pool['mail.alias'].create(cr, uid, {'alias_name': record.alias_prefix}, context=create_ctx)
75             else:
76                 mail_alias.write(cr, uid, alias_id, {'alias_name': record.alias_prefix}, context=context)
77         return True