1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU 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 General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields, osv
25
def _parse_risk_formula(formula, a, b, c):
26
"""Calculate the risk replacing the variables A, B, C into the formula."""
27
f = formula.replace('A', str(a)).replace('B', str(b)).replace('C', str(c))
30
class mgmtsystem_hazard_type(osv.osv):
32
_name = "mgmtsystem.hazard.type"
33
_description = "Type of hazard"
35
'name': fields.char('Type', size=50, required=True),
36
'description': fields.text('Description'),
39
mgmtsystem_hazard_type()
41
class mgmtsystem_hazard_risk_computation(osv.osv):
43
_name = "mgmtsystem.hazard.risk.computation"
44
_description = "Computation Risk"
46
'name': fields.char('Computation Risk', size=50, required=True),
47
'description': fields.text('Description'),
50
mgmtsystem_hazard_risk_computation()
52
class res_company(osv.osv):
53
_inherit = "res.company"
55
'risk_computation_id': fields.many2one('mgmtsystem.hazard.risk.computation', 'Risk Computation'),
60
class mgmtsystem_hazard_risk_type(osv.osv):
62
_name = "mgmtsystem.hazard.risk.type"
63
_description = "Risk type of the hazard"
65
'name': fields.char('Risk Type', size=50, required=True),
66
'description': fields.text('Description'),
69
mgmtsystem_hazard_risk_type()
71
class mgmtsystem_hazard_origin(osv.osv):
73
_name = "mgmtsystem.hazard.origin"
74
_description = "Origin of hazard"
76
'name': fields.char('Origin', size=50, required=True),
77
'description': fields.text('Description')
80
mgmtsystem_hazard_origin()
82
class mgmtsystem_hazard_hazard(osv.osv):
84
_name = "mgmtsystem.hazard.hazard"
85
_description = "Hazard"
87
'name': fields.char('Hazard', size=50, required=True),
88
'description': fields.text('Description'),
91
mgmtsystem_hazard_hazard()
93
class mgmtsystem_hazard_probability(osv.osv):
95
_name = "mgmtsystem.hazard.probability"
96
_description = "Probability of hazard"
98
'name': fields.char('Probability', size=50, required=True),
99
'value': fields.integer('Value', required=True),
100
'description': fields.text('Description')
103
mgmtsystem_hazard_probability()
105
class mgmtsystem_hazard_severity(osv.osv):
107
_name = "mgmtsystem.hazard.severity"
108
_description = "Severity of hazard"
110
'name': fields.char('Severity', size=50, required=True),
111
'value': fields.integer('Value', required=True),
112
'description': fields.text('Description')
115
mgmtsystem_hazard_severity()
117
class mgmtsystem_hazard_usage(osv.osv):
119
_name = "mgmtsystem.hazard.usage"
120
_description = "Usage of hazard"
122
'name': fields.char('Occupation / Usage', size=50, required=True),
123
'value': fields.integer('Value', required=True),
124
'description': fields.text('Description')
127
mgmtsystem_hazard_usage()
129
class mgmtsystem_hazard_control_measure(osv.osv):
131
_name = "mgmtsystem.hazard.control_measure"
132
_description = "Control Measure of hazard"
134
'name': fields.char('Control Measure', size=50, required=True),
135
'responsible_user_id': fields.many2one('res.users','Responsible', required=True),
136
'comments': fields.text('Comments'),
137
'hazard_id': fields.many2one('mgmtsystem.hazard', 'Hazard', ondelete='cascade', select=True),
140
mgmtsystem_hazard_control_measure()
142
class mgmtsystem_hazard_test(osv.osv):
144
_name = "mgmtsystem.hazard.test"
145
_description = "Implementation Tests of hazard"
147
'name': fields.char('Test', size=50, required=True),
148
'responsible_user_id': fields.many2one('res.users','Responsible', required=True),
149
'review_date': fields.date('Review Date', required=True),
150
'executed': fields.boolean('Executed'),
151
'hazard_id': fields.many2one('mgmtsystem.hazard', 'Hazard', ondelete='cascade', select=True),
154
mgmtsystem_hazard_test()
156
class mgmtsystem_hazard_residual_risk(osv.osv):
158
_name = "mgmtsystem.hazard.residual_risk"
159
_description = "Residual Risks of hazard"
161
def _compute_risk(self, cr, uid, ids, field_name, arg, context=None):
163
user = self.pool.get('res.users').browse(cr, uid, uid)
165
for obj in self.browse(cr, uid, ids):
166
if obj.probability_id and obj.severity_id and obj.usage_id:
167
mycompany = self.pool.get('res.company').browse(cr, uid, user.company_id.id, context)[0]
168
result[obj.id] = _parse_risk_formula(mycompany.risk_computation_id.name,
169
obj.probability_id.value,
170
obj.severity_id.value,
173
result[obj.id] = False
178
'name': fields.char('Name', size=50, required=True),
179
'probability_id': fields.many2one('mgmtsystem.hazard.probability','Probability', required=True),
180
'severity_id': fields.many2one('mgmtsystem.hazard.severity','Severity', required=True),
181
'usage_id': fields.many2one('mgmtsystem.hazard.usage','Occupation / Usage'),
182
'risk': fields.function(_compute_risk,string='Risk',type='integer'),
183
'acceptability': fields.boolean('Acceptability'),
184
'justification': fields.text('Justification'),
185
'hazard_id': fields.many2one('mgmtsystem.hazard', 'Hazard', ondelete='cascade', select=True),
188
mgmtsystem_hazard_residual_risk()
190
class mgmtsystem_hazard(osv.osv):
192
_name = "mgmtsystem.hazard"
193
_description = "Hazards of the health and safety management system"
195
def _compute_risk(self, cr, uid, ids, field_name, arg, context=None):
197
user = self.pool.get('res.users').browse(cr, uid, uid)
198
for obj in self.browse(cr, uid, ids):
199
# TODO: Use res.company.risk_computation_id to determine the risk computation
200
if obj.probability_id and obj.severity_id and obj.usage_id:
201
#result[obj.id] = obj.probability_id.value * obj.severity_id.value * obj.usage_id.value
202
mycompany = self.pool.get('res.company').browse(cr, uid, user.company_id.id, context)
203
result[obj.id] = _parse_risk_formula(mycompany.risk_computation_id.name,
204
obj.probability_id.value,
205
obj.severity_id.value,
208
result[obj.id] = False
213
'name': fields.char('Name', size=50, required=True),
214
'type_id': fields.many2one('mgmtsystem.hazard.type', 'Type', required=True),
215
'hazard_id': fields.many2one('mgmtsystem.hazard.hazard','Hazard', required=True),
216
'risk_type_id': fields.many2one('mgmtsystem.hazard.risk.type', 'Risk Type', required=True),
217
'origin_id': fields.many2one('mgmtsystem.hazard.origin', 'Origin', required=True),
218
'department_id': fields.many2one('hr.department', 'Department', required=True),
219
'responsible_user_id': fields.many2one('res.users','Responsible', required=True),
220
'analysis_date': fields.date('Date', required=True),
221
'probability_id': fields.many2one('mgmtsystem.hazard.probability','Probability'),
222
'severity_id': fields.many2one('mgmtsystem.hazard.severity','Severity'),
223
'usage_id': fields.many2one('mgmtsystem.hazard.usage','Occupation / Usage'),
224
'risk': fields.function(_compute_risk,string='Risk',type='integer'),
225
'acceptability': fields.boolean('Acceptability'),
226
'justification': fields.text('Justification'),
227
'control_measure_ids': fields.one2many('mgmtsystem.hazard.control_measure','hazard_id','Control Measures'),
228
'test_ids': fields.one2many('mgmtsystem.hazard.test','hazard_id','Implementation Tests'),
229
'residual_risk_ids': fields.one2many('mgmtsystem.hazard.residual_risk','hazard_id','Residual Risk Evaluations'),
234
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: