4127
by Jordi Esteve
[ADD]: New module civil_engineering to manage civil engineering works |
1 |
# -*- coding: utf-8 -*-
|
2 |
##############################################################################
|
|
3 |
#
|
|
4 |
# civilengineering module for OpenERP
|
|
5 |
# Copyright (C) 2008 Zikzakmedia S.L. (http://zikzakmedia.com)
|
|
6 |
# Raimon Esteve <resteve@zikzakmedia.com> All Rights Reserved.
|
|
7 |
#
|
|
8 |
# This file is a part of civil_engineering
|
|
9 |
#
|
|
10 |
# civilengineering is free software: you can redistribute it and/or modify
|
|
11 |
# it under the terms of the GNU General Public License as published by
|
|
12 |
# the Free Software Foundation, either version 3 of the License, or
|
|
13 |
# (at your option) any later version.
|
|
14 |
#
|
|
15 |
# civilengineering is distributed in the hope that it will be useful,
|
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 |
# GNU General Public License for more details.
|
|
19 |
#
|
|
20 |
# You should have received a copy of the GNU General Public License
|
|
21 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22 |
#
|
|
23 |
##############################################################################
|
|
24 |
||
25 |
from osv import osv, fields |
|
26 |
import time |
|
27 |
import xmlrpclib |
|
28 |
from tools import config |
|
29 |
||
30 |
||
31 |
# Civil Engineering Work Class
|
|
32 |
class civil_engineering_workclass(osv.osv): |
|
33 |
_name = "civil_engineering.workclass" |
|
34 |
_description = "Civil Engineering Work Class" |
|
35 |
||
36 |
def name_get(self, cr, uid, ids, context=None): |
|
37 |
if not len(ids): |
|
38 |
return [] |
|
39 |
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) |
|
40 |
res = [] |
|
41 |
for record in reads: |
|
42 |
name = record['name'] |
|
43 |
if record['parent_id']: |
|
44 |
name = record['parent_id'][1]+' / '+name |
|
45 |
res.append((record['id'], name)) |
|
46 |
return res |
|
47 |
||
48 |
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): |
|
49 |
res = self.name_get(cr, uid, ids, context=context) |
|
50 |
return dict(res) |
|
51 |
||
52 |
def _check_recursion(self, cr, uid, ids): |
|
53 |
level = 100 |
|
54 |
while len(ids): |
|
55 |
cr.execute('select distinct parent_id from civil_engineering_workclass where id in ('+','.join(map(str,ids))+')') |
|
56 |
ids = filter(None, map(lambda x:x[0], cr.fetchall())) |
|
57 |
if not level: |
|
58 |
return False |
|
59 |
level -= 1 |
|
60 |
return True |
|
61 |
||
62 |
_columns = { |
|
63 |
'name':fields.char('Name', size=64), |
|
64 |
'parent_id': fields.many2one('civil_engineering.workclass', 'Parent Work Class', select=True), |
|
65 |
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Full Name'), |
|
66 |
'child_ids': fields.one2many('civil_engineering.workclass', 'parent_id', 'Child Work Class'), |
|
67 |
'active' : fields.boolean('Active', help="The active field allows you to hide the work class without removing it."), |
|
68 |
}
|
|
69 |
_constraints = [ |
|
70 |
(_check_recursion, 'Error ! You can not create recursive records.', ['parent_id']) |
|
71 |
]
|
|
72 |
_defaults = { |
|
73 |
'active' : lambda *a: 1, |
|
74 |
}
|
|
75 |
_order = 'parent_id,name' |
|
76 |
||
77 |
civil_engineering_workclass() |
|
78 |
||
79 |
||
80 |
# Civil Engineering Work Use
|
|
81 |
class civil_engineering_workuse(osv.osv): |
|
82 |
_name = "civil_engineering.workuse" |
|
83 |
_description = "Civil Engineering Work Use" |
|
84 |
||
85 |
def name_get(self, cr, uid, ids, context=None): |
|
86 |
if not len(ids): |
|
87 |
return [] |
|
88 |
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) |
|
89 |
res = [] |
|
90 |
for record in reads: |
|
91 |
name = record['name'] |
|
92 |
if record['parent_id']: |
|
93 |
name = record['parent_id'][1]+' / '+name |
|
94 |
res.append((record['id'], name)) |
|
95 |
return res |
|
96 |
||
97 |
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): |
|
98 |
res = self.name_get(cr, uid, ids, context=context) |
|
99 |
return dict(res) |
|
100 |
||
101 |
def _check_recursion(self, cr, uid, ids): |
|
102 |
level = 100 |
|
103 |
while len(ids): |
|
104 |
cr.execute('select distinct parent_id from civil_engineering_workuse where id in ('+','.join(map(str,ids))+')') |
|
105 |
ids = filter(None, map(lambda x:x[0], cr.fetchall())) |
|
106 |
if not level: |
|
107 |
return False |
|
108 |
level -= 1 |
|
109 |
return True |
|
110 |
||
111 |
_columns = { |
|
112 |
'name':fields.char('Name', size=64), |
|
113 |
'parent_id': fields.many2one('civil_engineering.workuse', 'Parent Work Use', select=True), |
|
114 |
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Full Name'), |
|
115 |
'child_ids': fields.one2many('civil_engineering.workuse', 'parent_id', 'Child Work Use'), |
|
116 |
'active' : fields.boolean('Active', help="The active field allows you to hide the Work Use without removing it."), |
|
117 |
}
|
|
118 |
_constraints = [ |
|
119 |
(_check_recursion, 'Error ! You can not create recursive records.', ['parent_id']) |
|
120 |
]
|
|
121 |
_defaults = { |
|
122 |
'active' : lambda *a: 1, |
|
123 |
}
|
|
124 |
_order = 'parent_id,name' |
|
125 |
||
126 |
civil_engineering_workuse() |
|
127 |
||
128 |
||
129 |
# Civil Engineering Structure Type
|
|
130 |
class civil_engineering_structuretype(osv.osv): |
|
131 |
_name = "civil_engineering.structuretype" |
|
132 |
_description = "Civil Engineering Structure Type" |
|
133 |
||
134 |
def name_get(self, cr, uid, ids, context=None): |
|
135 |
if not len(ids): |
|
136 |
return [] |
|
137 |
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) |
|
138 |
res = [] |
|
139 |
for record in reads: |
|
140 |
name = record['name'] |
|
141 |
if record['parent_id']: |
|
142 |
name = record['parent_id'][1]+' / '+name |
|
143 |
res.append((record['id'], name)) |
|
144 |
return res |
|
145 |
||
146 |
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): |
|
147 |
res = self.name_get(cr, uid, ids, context=context) |
|
148 |
return dict(res) |
|
149 |
||
150 |
def _check_recursion(self, cr, uid, ids): |
|
151 |
level = 100 |
|
152 |
while len(ids): |
|
153 |
cr.execute('select distinct parent_id from civil_engineering_structuretype where id in ('+','.join(map(str,ids))+')') |
|
154 |
ids = filter(None, map(lambda x:x[0], cr.fetchall())) |
|
155 |
if not level: |
|
156 |
return False |
|
157 |
level -= 1 |
|
158 |
return True |
|
159 |
||
160 |
_columns = { |
|
161 |
'name':fields.char('Name', size=64), |
|
162 |
'parent_id': fields.many2one('civil_engineering.structuretype', 'Parent Structure Type', select=True), |
|
163 |
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Full Name'), |
|
164 |
'child_ids': fields.one2many('civil_engineering.structuretype', 'parent_id', 'Child Structure Type'), |
|
165 |
'active' : fields.boolean('Active', help="The active field allows you to hide the Structure Type without removing it."), |
|
166 |
}
|
|
167 |
_constraints = [ |
|
168 |
(_check_recursion, 'Error ! You can not create recursive records.', ['parent_id']) |
|
169 |
]
|
|
170 |
_defaults = { |
|
171 |
'active' : lambda *a: 1, |
|
172 |
}
|
|
173 |
_order = 'parent_id,name' |
|
174 |
||
175 |
civil_engineering_structuretype() |
|
176 |
||
177 |
||
178 |
# Civil Engineering Foundation Type
|
|
179 |
class civil_engineering_foundationtype(osv.osv): |
|
180 |
_name = "civil_engineering.foundationtype" |
|
181 |
_description = "Civil Engineering Foundation Type" |
|
182 |
||
183 |
def name_get(self, cr, uid, ids, context=None): |
|
184 |
if not len(ids): |
|
185 |
return [] |
|
186 |
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) |
|
187 |
res = [] |
|
188 |
for record in reads: |
|
189 |
name = record['name'] |
|
190 |
if record['parent_id']: |
|
191 |
name = record['parent_id'][1]+' / '+name |
|
192 |
res.append((record['id'], name)) |
|
193 |
return res |
|
194 |
||
195 |
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): |
|
196 |
res = self.name_get(cr, uid, ids, context=context) |
|
197 |
return dict(res) |
|
198 |
||
199 |
def _check_recursion(self, cr, uid, ids): |
|
200 |
level = 100 |
|
201 |
while len(ids): |
|
202 |
cr.execute('select distinct parent_id from civil_engineering_foundationtype where id in ('+','.join(map(str,ids))+')') |
|
203 |
ids = filter(None, map(lambda x:x[0], cr.fetchall())) |
|
204 |
if not level: |
|
205 |
return False |
|
206 |
level -= 1 |
|
207 |
return True |
|
208 |
||
209 |
_columns = { |
|
210 |
'name':fields.char('Name', size=64), |
|
211 |
'parent_id': fields.many2one('civil_engineering.foundationtype', 'Parent Foundation Type', select=True), |
|
212 |
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Full Name'), |
|
213 |
'child_ids': fields.one2many('civil_engineering.foundationtype', 'parent_id', 'Child Foundation Type'), |
|
214 |
'active' : fields.boolean('Active', help="The active field allows you to hide the Foundation Type without removing it."), |
|
215 |
}
|
|
216 |
_constraints = [ |
|
217 |
(_check_recursion, 'Error ! You can not create recursive records.', ['parent_id']) |
|
218 |
]
|
|
219 |
_defaults = { |
|
220 |
'active' : lambda *a: 1, |
|
221 |
}
|
|
222 |
_order = 'parent_id,name' |
|
223 |
||
224 |
civil_engineering_foundationtype() |
|
225 |
||
226 |
||
227 |
# Civil Engineering Structural Model Abstraction
|
|
228 |
class civil_engineering_modelabstraction(osv.osv): |
|
229 |
_name = "civil_engineering.modelabstraction" |
|
230 |
_description = "Civil Engineering Model Structural" |
|
231 |
||
232 |
def name_get(self, cr, uid, ids, context=None): |
|
233 |
if not len(ids): |
|
234 |
return [] |
|
235 |
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) |
|
236 |
res = [] |
|
237 |
for record in reads: |
|
238 |
name = record['name'] |
|
239 |
if record['parent_id']: |
|
240 |
name = record['parent_id'][1]+' / '+name |
|
241 |
res.append((record['id'], name)) |
|
242 |
return res |
|
243 |
||
244 |
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): |
|
245 |
res = self.name_get(cr, uid, ids, context=context) |
|
246 |
return dict(res) |
|
247 |
||
248 |
def _check_recursion(self, cr, uid, ids): |
|
249 |
level = 100 |
|
250 |
while len(ids): |
|
251 |
cr.execute('select distinct parent_id from civil_engineering_modelabstraction where id in ('+','.join(map(str,ids))+')') |
|
252 |
ids = filter(None, map(lambda x:x[0], cr.fetchall())) |
|
253 |
if not level: |
|
254 |
return False |
|
255 |
level -= 1 |
|
256 |
return True |
|
257 |
||
258 |
_columns = { |
|
259 |
'name':fields.char('Name', size=64), |
|
260 |
'parent_id': fields.many2one('civil_engineering.modelabstraction', 'Parent Structural Model Abstraction', select=True), |
|
261 |
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Full Name'), |
|
262 |
'child_ids': fields.one2many('civil_engineering.modelabstraction', 'parent_id', 'Child Structural Model Abstraction'), |
|
263 |
'active' : fields.boolean('Active', help="The active field allows you to hide the Structural Model Abstraction without removing it."), |
|
264 |
}
|
|
265 |
_constraints = [ |
|
266 |
(_check_recursion, 'Error ! You can not create recursive records.', ['parent_id']) |
|
267 |
]
|
|
268 |
_defaults = { |
|
269 |
'active' : lambda *a: 1, |
|
270 |
}
|
|
271 |
_order = 'parent_id,name' |
|
272 |
||
273 |
civil_engineering_modelabstraction() |
|
274 |
||
275 |
||
276 |
# Civil Engineering Modeling Software
|
|
277 |
class civil_engineering_modelingsoftware(osv.osv): |
|
278 |
_name = "civil_engineering.modelingsoftware" |
|
279 |
_description = "Civil Engineering Modeling Software" |
|
280 |
||
281 |
def name_get(self, cr, uid, ids, context=None): |
|
282 |
if not len(ids): |
|
283 |
return [] |
|
284 |
reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) |
|
285 |
res = [] |
|
286 |
for record in reads: |
|
287 |
name = record['name'] |
|
288 |
if record['parent_id']: |
|
289 |
name = record['parent_id'][1]+' / '+name |
|
290 |
res.append((record['id'], name)) |
|
291 |
return res |
|
292 |
||
293 |
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): |
|
294 |
res = self.name_get(cr, uid, ids, context=context) |
|
295 |
return dict(res) |
|
296 |
||
297 |
def _check_recursion(self, cr, uid, ids): |
|
298 |
level = 100 |
|
299 |
while len(ids): |
|
300 |
cr.execute('select distinct parent_id from civil_engineering_modelingsoftware where id in ('+','.join(map(str,ids))+')') |
|
301 |
ids = filter(None, map(lambda x:x[0], cr.fetchall())) |
|
302 |
if not level: |
|
303 |
return False |
|
304 |
level -= 1 |
|
305 |
return True |
|
306 |
||
307 |
_columns = { |
|
308 |
'name':fields.char('Name', size=64), |
|
309 |
'parent_id': fields.many2one('civil_engineering.modelingsoftware', 'Parent Modeling Software', select=True), |
|
310 |
'complete_name': fields.function(_name_get_fnc, method=True, type="char", string='Full Name'), |
|
311 |
'child_ids': fields.one2many('civil_engineering.modelingsoftware', 'parent_id', 'Child Modeling Software'), |
|
312 |
'active' : fields.boolean('Active', help="The active field allows you to hide the Modeling Software without removing it."), |
|
313 |
}
|
|
314 |
_constraints = [ |
|
315 |
(_check_recursion, 'Error ! You can not create recursive records.', ['parent_id']) |
|
316 |
]
|
|
317 |
_defaults = { |
|
318 |
'active' : lambda *a: 1, |
|
319 |
}
|
|
320 |
_order = 'parent_id,name' |
|
321 |
||
322 |
civil_engineering_modelingsoftware() |
|
323 |
||
324 |
||
325 |
# Civil Engineering Area
|
|
326 |
class civil_engineering_area(osv.osv): |
|
327 |
_name = "civil_engineering.area" |
|
328 |
_description = "Civil Engineering Area" |
|
329 |
||
330 |
_columns = { |
|
331 |
'name':fields.char('Name', size=64, select=1, required=True), |
|
332 |
}
|
|
333 |
civil_engineering_area() |
|
334 |
||
335 |
||
336 |
# Civil Engineering Work
|
|
337 |
class civil_engineering_work(osv.osv): |
|
338 |
_name = "civil_engineering.work" |
|
339 |
_description = "Civil Engineering Work" |
|
340 |
||
341 |
_columns = { |
|
342 |
'name':fields.char('Work description', size=128, select=1, required=True), |
|
343 |
'workclass_id':fields.many2one('civil_engineering.workclass','Work Class', select=1, required=True), |
|
344 |
'location':fields.char('Location', size=64), |
|
345 |
'city':fields.char('City', size=64, select=1), |
|
346 |
'main_city':fields.char('Main city', size=64, select=1), |
|
347 |
'country_id':fields.many2one('res.country','Country', select=1), |
|
348 |
'state_id':fields.many2one('res.country.state','State',domain="[('country_id','=',country_id)]"), |
|
349 |
'workuse_id':fields.many2one('civil_engineering.workuse','Work Use', select=1, required=True), |
|
350 |
'constructed_area':fields.float('Constructed area', digits=(12,2), select=2), |
|
351 |
'floors_under_ground_level':fields.integer('Floors under ground level'), |
|
352 |
'floors_above_ground_level':fields.integer('Floors above ground level'), |
|
353 |
'work_construction_cost':fields.float('Work construction cost', digits=(12, int(config['price_accuracy'])), select=2), |
|
354 |
'structuretype_id':fields.many2one('civil_engineering.structuretype','Structure Type'), |
|
355 |
'foundationtype_id':fields.many2one('civil_engineering.foundationtype','Foundation Type'), |
|
356 |
'modelabstraction_id':fields.many2one('civil_engineering.modelabstraction','Structural Model Abstraction'), |
|
357 |
'distance_between_supports':fields.float('Distance between supports', digits=(12,2)), |
|
358 |
'modelingsoftware_id':fields.many2one('civil_engineering.modelingsoftware','Structure Modeling Software'), |
|
359 |
'structure_construction_cost':fields.float('Structure construction cost', digits=(12, int(config['price_accuracy']))), |
|
360 |
'work_owner':fields.many2one('res.partner', 'Work owner', select=2), |
|
361 |
'work_builder':fields.many2one('res.partner', 'Work builder', select=2), |
|
362 |
'architecture':fields.many2one('res.partner', 'Architecture', select=2), |
|
363 |
'civil_engineer':fields.many2one('res.partner', 'Civil engineer', select=2), |
|
364 |
'work_safety':fields.many2one('res.partner', 'Work safety', select=2), |
|
365 |
'project_manager':fields.many2one('res.partner', 'Project manager', select=2), |
|
366 |
'structural_engineering':fields.many2one('res.partner', 'Structural engineering', select=2), |
|
367 |
'plant_engineering':fields.many2one('res.partner', 'Plant engineering', select=2), |
|
368 |
'geotechnics':fields.many2one('res.partner', 'Geotechnics', select=2), |
|
369 |
'project_ids':fields.one2many('civil_engineering.work.project', 'work_id', 'Project'), |
|
370 |
}
|
|
371 |
||
372 |
def _default_workclass(self, cr, uid, context={}): |
|
373 |
if 'workclass_id' in context and context['workclass_id']: |
|
374 |
return context['workclass_id'] |
|
375 |
return [] |
|
376 |
||
377 |
def _default_workuse(self, cr, uid, context={}): |
|
378 |
if 'workuse_id' in context and context['workuse_id']: |
|
379 |
return context['workuse_id'] |
|
380 |
return [] |
|
381 |
||
382 |
def _default_structuretype(self, cr, uid, context={}): |
|
383 |
if 'structuretype_id' in context and context['structuretype_id']: |
|
384 |
return context['structuretype_id'] |
|
385 |
return [] |
|
386 |
||
387 |
def _default_foundationtype(self, cr, uid, context={}): |
|
388 |
if 'foundationtype_id' in context and context['foundationtype_id']: |
|
389 |
return context['foundationtype_id'] |
|
390 |
return [] |
|
391 |
||
392 |
def _default_modelabstraction(self, cr, uid, context={}): |
|
393 |
if 'modelabstraction_id' in context and context['modelabstraction_id']: |
|
394 |
return context['modelabstraction_id'] |
|
395 |
return [] |
|
396 |
||
397 |
def _default_modelingsoftware(self, cr, uid, context={}): |
|
398 |
if 'modelingsoftware_id' in context and context['modelingsoftware_id']: |
|
399 |
return context['modelingsoftware_id'] |
|
400 |
return [] |
|
401 |
||
402 |
_defaults = { |
|
403 |
'workclass_id': _default_workclass, |
|
404 |
'workuse_id': _default_workuse, |
|
405 |
'structuretype_id': _default_structuretype, |
|
406 |
'foundationtype_id': _default_foundationtype, |
|
407 |
'modelabstraction_id': _default_modelabstraction, |
|
408 |
'modelingsoftware_id': _default_modelingsoftware, |
|
409 |
}
|
|
410 |
civil_engineering_work() |
|
411 |
||
412 |
||
413 |
# Civil Engineering Work Project
|
|
414 |
class civil_engineering_work_project(osv.osv): |
|
415 |
_name = "civil_engineering.work.project" |
|
416 |
_description = "Civil Engineering Work Project" |
|
417 |
||
418 |
_columns = { |
|
419 |
'work_id':fields.many2one('civil_engineering.work', 'Work', select=True, required=True), |
|
420 |
'sequence':fields.integer('Sequence'), |
|
421 |
'area_id':fields.many2one('civil_engineering.area', 'Area', select=True, required=True), |
|
422 |
'project_id':fields.many2one('project.project', 'Project', select=True, required=True), |
|
423 |
}
|
|
424 |
||
425 |
def name_get(self, cr, uid, ids, context=None): |
|
426 |
if not len(ids): |
|
427 |
return [] |
|
428 |
res = [] |
|
429 |
for obj in self.browse(cr, uid, ids): |
|
430 |
res.append((obj.id, obj.work_id.name+'-'+obj.area_id.name+'-'+obj.project_id.name)) |
|
431 |
return res |
|
432 |
||
433 |
civil_engineering_work_project() |
|
434 |