~savoirfairelinux-openerp/openerp-mgmtsystem/openupgrade70

« back to all changes in this revision

Viewing changes to mgmtsystem_hazard/mgmtsystem_hazard.py

  • Committer: Maxime Chambreuil
  • Date: 2012-10-17 03:20:09 UTC
  • mfrom: (0.1.19 openerp-mgmtsystem)
  • Revision ID: maxime.chambreuil@savoirfairelinux.com-20121017032009-z2yo25ft3yfbxmf5
[MERGE] with head of 6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#    
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2010 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
 
6
#
 
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.
 
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 General Public License for more details.
 
16
#
 
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/>.     
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import fields, osv
 
23
import time
 
24
 
 
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))
 
28
    return eval(f)
 
29
 
 
30
class mgmtsystem_hazard_type(osv.osv):
 
31
 
 
32
    _name = "mgmtsystem.hazard.type"
 
33
    _description = "Type of hazard"
 
34
    _columns = {
 
35
        'name': fields.char('Type', size=50, required=True),
 
36
        'description': fields.text('Description'),
 
37
    }
 
38
 
 
39
mgmtsystem_hazard_type()
 
40
 
 
41
class mgmtsystem_hazard_risk_computation(osv.osv):
 
42
 
 
43
    _name = "mgmtsystem.hazard.risk.computation"
 
44
    _description = "Computation Risk"
 
45
    _columns = {
 
46
        'name': fields.char('Computation Risk', size=50, required=True),
 
47
        'description': fields.text('Description'),
 
48
    }
 
49
 
 
50
mgmtsystem_hazard_risk_computation()
 
51
 
 
52
class res_company(osv.osv):
 
53
    _inherit = "res.company"
 
54
    _columns = {
 
55
        'risk_computation_id': fields.many2one('mgmtsystem.hazard.risk.computation', 'Risk Computation'),
 
56
    }
 
57
 
 
58
res_company()
 
59
 
 
60
class mgmtsystem_hazard_risk_type(osv.osv):
 
61
 
 
62
    _name = "mgmtsystem.hazard.risk.type"
 
63
    _description = "Risk type of the hazard"
 
64
    _columns = {
 
65
        'name': fields.char('Risk Type', size=50, required=True),
 
66
        'description': fields.text('Description'),
 
67
    }
 
68
 
 
69
mgmtsystem_hazard_risk_type()
 
70
 
 
71
class mgmtsystem_hazard_origin(osv.osv):
 
72
 
 
73
    _name = "mgmtsystem.hazard.origin"
 
74
    _description = "Origin of hazard"
 
75
    _columns = {
 
76
        'name': fields.char('Origin', size=50, required=True),
 
77
        'description': fields.text('Description')
 
78
    }
 
79
 
 
80
mgmtsystem_hazard_origin()
 
81
 
 
82
class mgmtsystem_hazard_hazard(osv.osv):
 
83
 
 
84
    _name = "mgmtsystem.hazard.hazard"
 
85
    _description = "Hazard"
 
86
    _columns = {
 
87
        'name': fields.char('Hazard', size=50, required=True),
 
88
        'description': fields.text('Description'),
 
89
    }
 
90
 
 
91
mgmtsystem_hazard_hazard()
 
92
 
 
93
class mgmtsystem_hazard_probability(osv.osv):
 
94
 
 
95
    _name = "mgmtsystem.hazard.probability"
 
96
    _description = "Probability of hazard"
 
97
    _columns = {
 
98
        'name': fields.char('Probability', size=50, required=True),
 
99
        'value': fields.integer('Value', required=True),
 
100
        'description': fields.text('Description')
 
101
    }
 
102
 
 
103
mgmtsystem_hazard_probability()
 
104
 
 
105
class mgmtsystem_hazard_severity(osv.osv):
 
106
 
 
107
    _name = "mgmtsystem.hazard.severity"
 
108
    _description = "Severity of hazard"
 
109
    _columns = {
 
110
        'name': fields.char('Severity', size=50, required=True),
 
111
        'value': fields.integer('Value', required=True),
 
112
        'description': fields.text('Description')
 
113
    }
 
114
 
 
115
mgmtsystem_hazard_severity()
 
116
 
 
117
class mgmtsystem_hazard_usage(osv.osv):
 
118
 
 
119
    _name = "mgmtsystem.hazard.usage"
 
120
    _description = "Usage of hazard"
 
121
    _columns = {
 
122
        'name': fields.char('Occupation / Usage', size=50, required=True),
 
123
        'value': fields.integer('Value', required=True),
 
124
        'description': fields.text('Description')
 
125
    }
 
126
 
 
127
mgmtsystem_hazard_usage()
 
128
 
 
129
class mgmtsystem_hazard_control_measure(osv.osv):
 
130
 
 
131
    _name = "mgmtsystem.hazard.control_measure"
 
132
    _description = "Control Measure of hazard"
 
133
    _columns = {
 
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),
 
138
    }
 
139
 
 
140
mgmtsystem_hazard_control_measure()
 
141
 
 
142
class mgmtsystem_hazard_test(osv.osv):
 
143
 
 
144
    _name = "mgmtsystem.hazard.test"
 
145
    _description = "Implementation Tests of hazard"
 
146
    _columns = {
 
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),
 
152
    }
 
153
 
 
154
mgmtsystem_hazard_test()
 
155
 
 
156
class mgmtsystem_hazard_residual_risk(osv.osv):
 
157
 
 
158
    _name = "mgmtsystem.hazard.residual_risk"
 
159
    _description = "Residual Risks of hazard"
 
160
 
 
161
    def _compute_risk(self, cr, uid, ids, field_name, arg, context=None):
 
162
        result = {}
 
163
        user = self.pool.get('res.users').browse(cr, uid, uid)
 
164
 
 
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,
 
171
                                                     obj.usage_id.value)
 
172
            else:
 
173
                result[obj.id] = False
 
174
 
 
175
        return result
 
176
    
 
177
    _columns = {
 
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),
 
186
    }
 
187
 
 
188
mgmtsystem_hazard_residual_risk()
 
189
 
 
190
class mgmtsystem_hazard(osv.osv):
 
191
 
 
192
    _name = "mgmtsystem.hazard"
 
193
    _description = "Hazards of the health and safety management system"
 
194
 
 
195
    def _compute_risk(self, cr, uid, ids, field_name, arg, context=None):
 
196
        result = {}
 
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,
 
206
                                                     obj.usage_id.value)
 
207
            else:
 
208
                result[obj.id] = False
 
209
 
 
210
        return result
 
211
 
 
212
    _columns = {
 
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'),
 
230
    }
 
231
 
 
232
mgmtsystem_hazard()
 
233
 
 
234
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: