[IMP] hr_payroll:removed 'advantages_net' and 'advantages_gross' fields from hr.contract
[odoo/odoo.git] / addons / hr_contract / hr_contract.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 import time
22
23 from osv import fields, osv
24
25 class hr_employee(osv.osv):
26     _name = "hr.employee"
27     _description = "Employee"
28     _inherit = "hr.employee"
29
30     def _get_latest_contract(self, cr, uid, ids, field_name, args, context=None):
31         res = {}
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)
35             if contract_ids:
36                 res[emp.id] = contract_ids[-1:][0]
37             else:
38                 res[emp.id] = False
39         return res
40
41     _columns = {
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 Distance', help="In kilometers"),
48         'contract_ids': fields.one2many('hr.contract', 'employee_id', 'Contracts'),
49         'contract_id':fields.function(_get_latest_contract, method=True, string='Contract', type='many2one', relation="hr.contract", help='Latest contract of the employee'),
50     }
51
52 hr_employee()
53
54 class hr_passport(osv.osv):
55     """
56     Employee Passport
57     Passport based Contracts for Employees
58     """
59
60     _inherit = 'hr.passport'
61     _description = 'Passport Detail'
62     _columns = {
63         'contracts_ids': fields.one2many('hr.contract', 'passport_id', 'Contracts', required=False, readonly=True),
64     }
65
66 hr_passport()
67
68 #Contract wage type period name
69 class hr_contract_wage_type_period(osv.osv):
70     _name='hr.contract.wage.type.period'
71     _description='Wage Period'
72     _columns = {
73         'name': fields.char('Period Name', size=50, required=True, select=True),
74         'factor_days': fields.float('Hours in the period', digits=(12,4), required=True, help='This field is used by the timesheet system to compute the price of an hour of work wased on the contract of the employee')
75     }
76     _defaults = {
77         'factor_days': 168.0
78     }
79 hr_contract_wage_type_period()
80
81 #Contract wage type (hourly, daily, monthly, ...)
82 class hr_contract_wage_type(osv.osv):
83     _name = 'hr.contract.wage.type'
84     _description = 'Wage Type'
85     _columns = {
86         'name': fields.char('Wage Type Name', size=50, required=True, select=True),
87         'period_id': fields.many2one('hr.contract.wage.type.period', 'Wage Period', required=True),
88         'factor_type': fields.float('Factor for hour cost', digits=(12,4), required=True, help='This field is used by the timesheet system to compute the price of an hour of work based on the contract of the employee')
89     }
90     _defaults = {
91         'factor_type': 1.8
92     }
93 hr_contract_wage_type()
94
95
96 class hr_contract_type(osv.osv):
97     _name = 'hr.contract.type'
98     _description = 'Contract Type'
99     _columns = {
100         'name': fields.char('Contract Type', size=32, required=True),
101     }
102 hr_contract_type()
103
104 class hr_contract(osv.osv):
105     _name = 'hr.contract'
106     _description = 'Contract'
107     _columns = {
108         'name': fields.char('Contract Reference', size=32, required=True),
109         'employee_id': fields.many2one('hr.employee', "Employee", required=True),
110         'department_id': fields.related('employee_id','department_id', type='many2one', relation='hr.department', string="Department", readonly=True),
111         'type_id': fields.many2one('hr.contract.type', "Contract Type", required=True),
112         'job_id': fields.many2one('hr.job', 'Job Title'),
113         'date_start': fields.date('Start Date', required=True),
114         'date_end': fields.date('End Date'),
115         'trial_date_start': fields.date('Trial Start Date'),
116         'trial_date_end': fields.date('Trial End Date'),
117         'working_hours': fields.many2one('resource.calendar','Working Schedule'),
118         'wage': fields.float('Wage', digits=(16,2), required=True, help="Basic Salary of the employee"),
119         'advantages': fields.text('Advantages'),
120         'notes': fields.text('Notes'),
121         'permit_no': fields.char('Work Permit No', size=256, required=False, readonly=False),
122         'passport_id': fields.many2one('hr.passport', 'Passport No', required=False),
123         'visa_no': fields.char('Visa No', size=64, required=False, readonly=False),
124         'visa_expire': fields.date('Visa Expire Date'),
125     }
126     _defaults = {
127         'date_start': lambda *a: time.strftime("%Y-%m-%d"),
128     }
129
130     def _check_dates(self, cr, uid, ids, context=None):
131         for contract in self.read(cr, uid, ids, ['date_start', 'date_end'], context=context):
132              if contract['date_start'] and contract['date_end'] and contract['date_start'] > contract['date_end']:
133                  return False
134         return True
135
136     _constraints = [
137         (_check_dates, 'Error! contract start-date must be lower then contract end-date.', ['date_start', 'date_end'])
138     ]
139 hr_contract()
140
141 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: