-
Notifications
You must be signed in to change notification settings - Fork 28
/
hr_utilization.py
175 lines (148 loc) · 6.48 KB
/
hr_utilization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# -*- coding: utf-8 -*-
#
#
# Authors: Stéphane Bidoul & Olivier Laurent
# Copyright (c) 2012 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
from openerp import models, fields, api
from openerp.tools.translate import _
class res_company(models.Model):
_inherit = "res.company"
fulltime_calendar_id = fields.Many2one(
"resource.calendar", "Full-time Calendar", required=False,
help="Calendar used as the full working time reference"
" of the company.")
class resource_calendar(models.Model):
_inherit = "resource.calendar"
def name_get(self, cr, uid, ids, context=None):
if not ids:
return []
res = []
for cal in self.browse(cr, uid, ids, context=context):
if cal.company_id:
name = "%s (%s)" % (cal.name, cal.company_id.name)
else:
name = cal.name
res.append((cal.id, name))
return res
leave_ids = fields.One2many('resource.calendar.leaves', 'calendar_id',
'Closing Days')
class hr_utilization_configuration(models.Model):
_name = 'hr.utilization.configuration'
def _get_column_list(self, configuration_column_ids):
''' Build a list of columns '''
result = []
for configuration_column_id in configuration_column_ids:
result.append(configuration_column_id.column_id.short_name)
return ", ".join(result) or False
@api.one
@api.depends('configuration_column_ids')
def _column_list(self):
''' Build a set of columns lists '''
self.column_list = self._get_column_list(self.configuration_column_ids)
def copy(self, cr, uid, id, defaults, context=None):
previous_name = self.browse(cr, uid, id, context=context).name
copy_name = _('Copy of %s') % previous_name
new_name = copy_name
n = 0
while True:
existing_ids = self.search(
cr, uid, [('name', '=', new_name)], context=context)
if not existing_ids:
break
n += 1
new_name = '%s (%s)' % (copy_name, n)
defaults['name'] = new_name
return super(hr_utilization_configuration, self).copy(
cr, uid, id, defaults, context=context)
name = fields.Char('Utilization Configuration Name', size=128,
required=True)
with_fte = fields.Boolean('With Full-time Equivalent Column',
required=True, default=True)
configuration_column_ids = fields.One2many(
'hr.utilization.configuration.column',
'configuration_id',
'List of Columns to Print')
column_list = fields.Char(compute='_column_list', string='Columns')
_sql_constraints = [
('unique_name', 'unique(name)', 'Configuration name must be unique'),
]
_order = "name"
class hr_utilization_configuration_column(models.Model):
_name = 'hr.utilization.configuration.column'
_rec_name = 'column_id'
column_id = fields.Many2one('hr.utilization.column', 'Column',
required=True, ondelete='cascade')
configuration_id = fields.Many2one('hr.utilization.configuration',
'Configuration', required=True,
ondelete='cascade')
sequence = fields.Integer('Sequence', required=True)
_order = "sequence"
class hr_utilization_column(models.Model):
_name = 'hr.utilization.column'
def _get_analytic_account_list(self, analytic_accounts):
''' Build a list of analytic accounts codes '''
return ", ".join([r.display_name for r in analytic_accounts])
@api.one
@api.depends('analytic_account_ids')
def _analytic_account_list(self):
''' Build a set of analytic accounts codes lists '''
self.analytic_account_list = self._get_analytic_account_list(
self.analytic_account_ids)
def copy(self, cr, uid, id, defaults, context=None):
source = self.browse(cr, uid, id, context=context)
previous_name = source.name
previous_short_name = source.short_name
copy_name = _('Copy of %s') % previous_name
new_name = copy_name
n = 0
while True:
new_short_name = '%s-%s' % (n, previous_short_name)
existing_ids = self.search(
cr, uid, ['|',
('name', '=', new_name),
('short_name', '=', new_short_name)],
context=context)
if not existing_ids:
break
n += 1
new_name = '%s (%s)' % (copy_name, n)
defaults['name'] = new_name
defaults['short_name'] = new_short_name
return super(hr_utilization_column, self).copy(
cr, uid, id, defaults, context=context)
name = fields.Char('Column Name', size=128, required=True)
short_name = fields.Char('Report Column Name', size=15, required=True)
analytic_account_ids = fields.Many2many('account.analytic.account',
string='Analytic accounts')
analytic_account_list = fields.Char(compute='_analytic_account_list',
string='Analytic accounts')
_sql_constraints = [
('unique_name', 'unique(name)', 'Column name must be unique'),
('unique_name', 'unique(short_name)',
'Column short name must be unique'),
]
_order = "name"