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 ##############################################################################
22 from osv import fields, osv
23 from tools.translate import _
25 class hr_employee_category(osv.osv):
26 _name = "hr.employee.category"
27 _description = "Employee Category"
30 'name' : fields.char("Category", size=64, required=True),
31 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True),
32 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories')
35 def _check_recursion(self, cr, uid, ids):
38 cr.execute('select distinct parent_id from hr_employee_category where id=ANY(%s)',(ids,))
39 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
46 (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id'])
49 hr_employee_category()
51 class hr_employee_marital_status(osv.osv):
52 _name = "hr.employee.marital.status"
53 _description = "Employee Marital Status"
55 'name' : fields.char('Marital Status', size=30, required=True),
56 'description' : fields.text('Status Description'),
58 hr_employee_marital_status()
60 class hr_job(osv.osv):
61 def _no_of_employee(self, cr, uid, ids, name,args,context=None):
63 for emp in self.browse(cr, uid, ids):
64 res[emp.id] = len(emp.employee_ids or [])
68 _description = "Job Description"
70 'name': fields.char('Job Name', size=128, required=True, select=True),
71 'expected_employees':fields.integer('Expected Employees'),
72 'no_of_employee': fields.function(_no_of_employee, method=True, string='No of Employees', type='integer'),
73 'employee_ids':fields.one2many('hr.employee', 'job_id','Employees'),
74 'description': fields.text('Job Description'),
75 'requirements':fields.text('Requirements'),
76 'department_id':fields.many2one('hr.department','Department'),
77 'company_id': fields.many2one('res.company', 'Company'),
78 'state': fields.selection([('open','Open'),('old','Old'),('recruit','In Recruitement')], 'State', required=True),
81 'expected_employees': lambda *a: 1,
82 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'hr.job', context=c),
83 'state': lambda *args: 'open'
87 class hr_employee(osv.osv):
89 _description = "Employee"
90 _inherits = {'resource.resource':"resource_id"}
92 'country_id' : fields.many2one('res.country', 'Nationality'),
93 'birthday' : fields.date("Birthday"),
94 'ssnid': fields.char('SSN No', size=32, help='Social Security Number'),
95 'sinid': fields.char('SIN No', size=32),
96 'otherid': fields.char('Other ID', size=32),
97 'gender': fields.selection([('',''),('male','Male'),('female','Female')], 'Gender'),
98 'marital': fields.many2one('hr.employee.marital.status', 'Marital Status'),
100 'partner_id' : fields.related('company_id', 'partner_id', type='many2one', relation='res.partner', readonly=True),
102 'address_id': fields.many2one('res.partner.address', 'Working Address'),
103 'address_home_id': fields.many2one('res.partner.address', 'Home Address'),
104 'work_phone': fields.related('address_id', 'phone', type='char', string='Work Phone'),
105 'work_email': fields.related('address_id', 'email', type='char', size=240, string='Work E-mail'),
106 'work_location': fields.char('Office Location', size=32),
108 'notes': fields.text('Notes'),
109 'parent_id': fields.many2one('hr.employee', 'Manager', select=True),
110 'category_id' : fields.many2one('hr.employee.category', 'Category'),
111 'child_ids': fields.one2many('hr.employee', 'parent_id','Subordinates'),
112 'resource_id': fields.many2one('resource.resource','Resource',ondelete='cascade'),
113 'coach_id':fields.many2one('res.users','Coach'),
114 'job_id':fields.many2one('hr.job', 'Job'),
118 'active' : lambda *a: True,
121 def _check_recursion(self, cr, uid, ids):
124 cr.execute('select distinct parent_id from hr_employee where id =ANY(%s)',(ids,))
125 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
132 (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id'])
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: