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 ##############################################################################
23 from openerp.osv import fields, osv
25 class hr_employee(osv.osv):
27 _description = "Employee"
28 _inherit = "hr.employee"
30 def _get_latest_contract(self, cr, uid, ids, field_name, args, context=None):
32 obj_contract = self.pool.get('hr.contract')
33 for emp in self.browse(cr, uid, ids, context=context):
34 contract_ids = obj_contract.search(cr, uid, [('employee_id','=',emp.id),], order='date_start', context=context)
36 res[emp.id] = contract_ids[-1:][0]
42 'manager': fields.boolean('Is a Manager'),
43 'medic_exam': fields.date('Medical Examination Date'),
44 'place_of_birth': fields.char('Place of Birth', size=30),
45 'children': fields.integer('Number of Children'),
46 'vehicle': fields.char('Company Vehicle', size=64),
47 'vehicle_distance': fields.integer('Home-Work Dist.', help="In kilometers"),
48 'contract_ids': fields.one2many('hr.contract', 'employee_id', 'Contracts'),
49 'contract_id':fields.function(_get_latest_contract, string='Contract', type='many2one', relation="hr.contract", help='Latest contract of the employee'),
53 class hr_contract_type(osv.osv):
54 _name = 'hr.contract.type'
55 _description = 'Contract Type'
57 'name': fields.char('Contract Type', size=32, required=True),
60 class hr_contract(osv.osv):
62 _description = 'Contract'
64 'name': fields.char('Contract Reference', size=64, required=True),
65 'employee_id': fields.many2one('hr.employee', "Employee", required=True),
66 'department_id': fields.related('employee_id','department_id', type='many2one', relation='hr.department', string="Department", readonly=True),
67 'type_id': fields.many2one('hr.contract.type', "Contract Type", required=True),
68 'job_id': fields.many2one('hr.job', 'Job Title'),
69 'date_start': fields.date('Start Date', required=True),
70 'date_end': fields.date('End Date'),
71 'trial_date_start': fields.date('Trial Start Date'),
72 'trial_date_end': fields.date('Trial End Date'),
73 'working_hours': fields.many2one('resource.calendar','Working Schedule'),
74 'wage': fields.float('Wage', digits=(16,2), required=True, help="Basic Salary of the employee"),
75 'advantages': fields.text('Advantages'),
76 'notes': fields.text('Notes'),
77 'permit_no': fields.char('Work Permit No', size=256, required=False, readonly=False),
78 'visa_no': fields.char('Visa No', size=64, required=False, readonly=False),
79 'visa_expire': fields.date('Visa Expire Date'),
82 def _get_type(self, cr, uid, context=None):
83 type_ids = self.pool.get('hr.contract.type').search(cr, uid, [('name', '=', 'Employee')])
84 return type_ids and type_ids[0] or False
87 'date_start': lambda *a: time.strftime("%Y-%m-%d"),
91 def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
93 return {'value': {'job_id': False}}
94 emp_obj = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
97 job_id = emp_obj.job_id.id
98 return {'value': {'job_id': job_id}}
100 def _check_dates(self, cr, uid, ids, context=None):
101 for contract in self.read(cr, uid, ids, ['date_start', 'date_end'], context=context):
102 if contract['date_start'] and contract['date_end'] and contract['date_start'] > contract['date_end']:
107 (_check_dates, 'Error! Contract start-date must be less than contract end-date.', ['date_start', 'date_end'])
110 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: