1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
24 from osv import fields, osv
26 from tools.translate import _
30 class hr_employee_category(osv.osv):
32 def name_get(self, cr, uid, ids, context=None):
35 reads = self.read(cr, uid, ids, ['name','parent_id'], context)
39 if record['parent_id']:
40 name = record['parent_id'][1]+' / '+name
41 res.append((record['id'], name))
44 def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context):
45 res = self.name_get(cr, uid, ids, context)
48 _name = "hr.employee.category"
49 _description = "Employee Category"
51 'name': fields.char("Category", size=64, required=True),
52 'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Name'),
53 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
54 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
57 def _check_recursion(self, cr, uid, ids, context=None):
60 cr.execute('select distinct parent_id from hr_employee_category where id IN %s', (tuple(ids), ))
61 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
68 (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
71 hr_employee_category()
73 class hr_employee_marital_status(osv.osv):
74 _name = "hr.employee.marital.status"
75 _description = "Employee Marital Status"
77 'name': fields.char('Marital Status', size=32, required=True),
78 'description': fields.text('Status Description'),
81 hr_employee_marital_status()
83 class hr_job(osv.osv):
85 def _no_of_employee(self, cr, uid, ids, name, args, context=None):
87 for job in self.browse(cr, uid, ids, context):
88 res[job.id] = len(job.employee_ids or [])
91 def _no_of_recruitement(self, cr, uid, ids, name, args, context=None):
93 for job in self.browse(cr, uid, ids, context):
94 res[job.id] = job.expected_employees - job.no_of_employee
98 _description = "Job Description"
100 'name': fields.char('Job Name', size=128, required=True, select=True),
101 'expected_employees': fields.integer('Expected Employees', help='Required number of Employees in total for that job.'),
102 'no_of_employee': fields.function(_no_of_employee, method=True, string="No of Employee", help='Number of employee with that job.'),
103 'no_of_recruitment': fields.function(_no_of_recruitement, method=True, string='Expected in Recruitment', readonly=True),
104 'employee_ids': fields.one2many('hr.employee', 'job_id', 'Employees'),
105 'description': fields.text('Job Description'),
106 'requirements': fields.text('Requirements'),
107 'department_id': fields.many2one('hr.department', 'Department'),
108 'company_id': fields.many2one('res.company', 'Company'),
109 'state': fields.selection([('open', 'In Position'),('old', 'Old'),('recruit', 'In Recruitement')], 'State', readonly=True, required=True),
112 'expected_employees': 1,
113 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.job', context=c),
117 def on_change_expected_employee(self, cr, uid, ids, expected_employee, no_of_employee, context=None):
121 if expected_employee:
122 result['no_of_recruitment'] = expected_employee - no_of_employee
123 return {'value': result}
125 def job_old(self, cr, uid, ids, *args):
126 self.write(cr, uid, ids, {'state': 'old'})
129 def job_recruitement(self, cr, uid, ids, *args):
130 self.write(cr, uid, ids, {'state': 'recruit'})
133 def job_open(self, cr, uid, ids, *args):
134 self.write(cr, uid, ids, {'state': 'open'})
139 class hr_employee(osv.osv):
140 _name = "hr.employee"
141 _description = "Employee"
142 _inherits = {'resource.resource': "resource_id"}
144 'country_id': fields.many2one('res.country', 'Nationality'),
145 'birthday': fields.date("Date of Birth"),
146 'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
147 'sinid': fields.char('SIN No', size=32, help="Social Insurance Number"),
148 'identification_id': fields.char('Identification No', size=32),
149 'gender': fields.selection([('male', 'Male'),('female', 'Female')], 'Gender'),
150 'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
151 'department_id':fields.many2one('hr.department', 'Department'),
152 'address_id': fields.many2one('res.partner.address', 'Working Address'),
153 'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
154 'partner_id': fields.related('address_home_id', 'partner_id', type='many2one', relation='res.partner', readonly=True, help="Partner that is related to the current employee. Accounting transaction will be written on this partner belongs to employee."),
155 'bank_account_id':fields.many2one('res.partner.bank', 'Bank Account', domain="[('partner_id','=',partner_id)]", help="Employee bank salary account"),
156 'work_phone': fields.related('address_id', 'phone', type='char', size=32, string='Work Phone', readonly=True),
157 'work_email': fields.related('address_id', 'email', type='char', size=240, string='Work E-mail'),
158 'work_location': fields.char('Office Location', size=32),
159 'notes': fields.text('Notes'),
160 'parent_id': fields.related('department_id', 'manager_id', relation='hr.employee', string='Manager', type='many2one', store=True, select=True, readonly=True, help="It is linked with manager of Department"),
161 'category_ids': fields.many2many('hr.employee.category', 'employee_category_rel','category_id','emp_id','Category'),
162 'child_ids': fields.one2many('hr.employee', 'parent_id', 'Subordinates'),
163 'resource_id': fields.many2one('resource.resource', 'Resource', ondelete='cascade', required=True),
164 'coach_id': fields.many2one('hr.employee', 'Coach'),
165 'job_id': fields.many2one('hr.job', 'Job'),
166 'photo': fields.binary('Photo'),
167 'passport_id':fields.char('Passport', size=64)
170 def onchange_company(self, cr, uid, ids, company, context=None):
173 company_id = self.pool.get('res.company').browse(cr,uid,company)
174 address = self.pool.get('res.partner').address_get(cr, uid, [company_id.partner_id.id], ['default'])
175 address_id = address and address['default'] or False
176 return {'value': {'address_id' : address_id}}
178 def onchange_user(self, cr, uid, ids, user_id, context=None):
181 work_email = self.pool.get('res.users').browse(cr, uid, user_id).user_email
182 return {'value': {'work_email' : work_email}}
184 def _get_photo(self, cr, uid, context=None):
185 res_path = addons.get_module_resource("hr","image/photo.png")
186 return open(res_path,'rb').read().encode('base64')
191 'address_id': lambda self,cr,uid,c: self.pool.get('res.partner.address').browse(cr, uid, uid, c).partner_id.id
194 def _check_recursion(self, cr, uid, ids, context=None):
197 cr.execute('SELECT DISTINCT parent_id FROM hr_employee WHERE id IN %s AND parent_id!=id',(tuple(ids),))
198 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
204 def _check_department_id(self, cr, uid, ids, context=None):
205 for emp in self.browse(cr, uid, ids, context=context):
206 if emp.department_id.manager_id and emp.id == emp.department_id.manager_id.id:
211 (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id']),
212 (_check_department_id, 'Error ! You cannot select a department for which the employee is the manager.', ['department_id']),
217 class hr_department(osv.osv):
218 _description = "Department"
219 _inherit = 'hr.department'
221 'manager_id': fields.many2one('hr.employee', 'Manager'),
222 'member_ids': fields.one2many('hr.employee', 'department_id', 'Members'),
227 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: