Mercurial > pyarq-presupuestos
comparison Generic/base.py @ 17:a7b9f7e7dfa4
Improvements importing FIEBDC files
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Sat, 02 Nov 2013 19:26:09 +0100 |
parents | 2ac1551ad2ab |
children | 7bd4ca56607d |
comparison
equal
deleted
inserted
replaced
16:60bc5117926c | 17:a7b9f7e7dfa4 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 ## File base.py | 3 ## File base.py |
4 ## This file is part of pyArq-Presupuestos. | 4 ## This file is part of pyArq-Presupuestos. |
5 ## | 5 ## |
6 ## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez | 6 ## Copyright (C) 2010-2013 Miguel Ángel Bárcena Rodríguez |
7 ## <miguelangel@obraencurso.es> | 7 ## <miguelangel@obraencurso.es> |
8 ## | 8 ## |
9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify | 9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify |
10 ## it under the terms of the GNU General Public License as published by | 10 ## it under the terms of the GNU General Public License as published by |
11 ## the Free Software Foundation, either version 3 of the License, or | 11 ## the Free Software Foundation, either version 3 of the License, or |
301 {get/set}Sheet | 301 {get/set}Sheet |
302 {get/set}Files | 302 {get/set}Files |
303 addFile | 303 addFile |
304 {get/set}Labels | 304 {get/set}Labels |
305 addLabel | 305 addLabel |
306 getChildPositions: | |
306 """ | 307 """ |
307 __slots__ = ["_Record__code", "_Record__synonyms", | 308 __slots__ = ["_Record__code", "_Record__synonyms", |
308 "_Record__recordType", "_Record__unit", | 309 "_Record__recordType", "_Record__unit", |
309 "_Record__summary", "_Record__prices", | 310 "_Record__summary", "_Record__prices", |
310 "_Record__parents", "_Record__children", | 311 "_Record__parents", "_Record__children", |
330 self.__sheet = tuple[9] | 331 self.__sheet = tuple[9] |
331 self.__files = tuple[10] | 332 self.__files = tuple[10] |
332 self.__labels = tuple[11] | 333 self.__labels = tuple[11] |
333 | 334 |
334 def __init__(self, decimals, code, synonyms, hierarchy, unit, summary, | 335 def __init__(self, decimals, code, synonyms, hierarchy, unit, summary, |
335 prices, type, subtype, parents=[], text=""): | 336 prices, type_, subtype, parents=[], text=""): |
336 self.code = code | 337 self.code = code |
337 self.synonyms = synonyms | 338 self.synonyms = synonyms |
338 self.recordType = (hierarchy, type, subtype) | 339 self.recordType = (hierarchy, type_, subtype) |
339 self.unit = unit | 340 self.unit = unit |
340 self.summary = summary | 341 self.summary = summary |
341 self.setPrices(prices, decimals) | 342 self.setPrices(prices, decimals) |
342 self.parents = parents | 343 self.parents = parents |
343 self.children = [] | 344 self.children = [] |
540 for _measure in _measure_list: | 541 for _measure in _measure_list: |
541 _measurerecordCode = _record_code | 542 _measurerecordCode = _record_code |
542 self.__children = children | 543 self.__children = children |
543 | 544 |
544 def appendChild(self, child_code, decimals, factor=0.0, yield_=0.0, | 545 def appendChild(self, child_code, decimals, factor=0.0, yield_=0.0, |
545 measure=0.0, measure_list=[], type ="", label=""): | 546 measure=0.0, measure_list=[], type_ ="", label=""): |
546 """appendChildren(self, child_code, factor=0.0, yield_=0.0, | 547 """appendChildren(self, child_code, factor=0.0, yield_=0.0, |
547 measure=0.0, measure_list=[], type ="", label="")) | 548 measure=0.0, measure_list=[], type_ ="", label="")) |
548 | 549 |
549 position: | 550 position: |
550 child_code: | 551 child_code: |
551 factor: | 552 factor: |
552 yield_: | 553 yield_: |
553 measure: | 554 measure: |
554 measure_list: | 555 measure_list: |
555 type: | 556 type_: |
556 label: | 557 label: |
557 | 558 |
558 Append a child to the list of children | 559 Append a child to the list of children |
559 """ | 560 """ |
560 _measure = Measure(decimals, self.recordType, | 561 _measure = Measure(decimals, self.recordType, |
561 measure, [], label, factor, yield_) | 562 measure, [], label, factor, yield_) |
562 if len(measure_list) > 0: | 563 if len(measure_list) > 0: |
563 measure.buildMeasure(_measure, measure_list, type, decimals, | 564 _measure.buildMeasure( measure_list, type_, decimals, |
564 self.recordType) | 565 self.recordType) |
565 _position = len(self.__children) | 566 _position = len(self.__children) |
566 _child = Decomposition(_position, child_code, [_measure]) | 567 _child = Decomposition(_position, child_code, [_measure]) |
567 self.__children.append(_child) | 568 self.__children.append(_child) |
568 return _child | 569 return _child |
613 _file_path = file[0] | 614 _file_path = file[0] |
614 _type = file[1] | 615 _type = file[1] |
615 _description = file[2] | 616 _description = file[2] |
616 if not os.path.exists(file[0]): | 617 if not os.path.exists(file[0]): |
617 raise ValueError, _("Incorrect path") | 618 raise ValueError, _("Incorrect path") |
618 _file = File(file_path, type, description) | 619 _file = File(file_path, type_, description) |
619 _files.append(_file) | 620 _files.append(_file) |
620 else: | 621 else: |
621 raise ValueError, utils.mapping(_( | 622 raise ValueError, utils.mapping(_( |
622 "file must be a list or a File object: $1"),str(file)) | 623 "file must be a list or a File object: $1"),str(file)) |
623 self.__files = _files | 624 self.__files = _files |
624 | 625 |
625 | 626 |
626 def addFile(self, file_path, type, description): | 627 def addFile(self, file_path, type_, description): |
627 """addFile(self, file_path, type, description) | 628 """addFile(self, file_path, type_, description) |
628 | 629 |
629 Add a file to a record instance | 630 Add a file to a record instance |
630 """ | 631 """ |
631 if not os.path.exists(file_path): | 632 if not os.path.exists(file_path): |
632 raise ValueError, _("Incorrect path") | 633 raise ValueError, _("Incorrect path") |
634 _isin = False | 635 _isin = False |
635 for _ofile in self.__files: | 636 for _ofile in self.__files: |
636 if _ofile.name == _name: | 637 if _ofile.name == _name: |
637 _isin = True | 638 _isin = True |
638 if not _isin: | 639 if not _isin: |
639 _file = File(_name, type, description) | 640 _file = File(_name, type_, description) |
640 self.__files.append(_file) | 641 self.__files.append(_file) |
641 | 642 |
642 def getLabels(self): | 643 def getLabels(self): |
643 return self.__labels | 644 return self.__labels |
644 | 645 |
664 """ | 665 """ |
665 if not isinstance(label, str): | 666 if not isinstance(label, str): |
666 raise ValueError, _("Label must be a string") | 667 raise ValueError, _("Label must be a string") |
667 if not label in self.__labels: | 668 if not label in self.__labels: |
668 self.__labels.append(label) | 669 self.__labels.append(label) |
670 | |
671 def getChildPositions(self, child_code): | |
672 """getChildPath(self, child_code): | |
673 | |
674 Try to return positions of a childcode | |
675 """ | |
676 children = self.children | |
677 positions = [] | |
678 for child in children: | |
679 if child.code == child_code: | |
680 positions.append(child.position) | |
681 return positions | |
669 | 682 |
670 recordType = property(getRecordType, setRecordType, None, | 683 recordType = property(getRecordType, setRecordType, None, |
671 """Record Type object | 684 """Record Type object |
672 """) | 685 """) |
673 code = property(getCode, setCode, None, | 686 code = property(getCode, setCode, None, |
705 | 718 |
706 Description: | 719 Description: |
707 Parametric Record object | 720 Parametric Record object |
708 Constructor: | 721 Constructor: |
709 base.ParametricRecord(code, synonyms, hierarchy, unit, summary, prices, | 722 base.ParametricRecord(code, synonyms, hierarchy, unit, summary, prices, |
710 type, subtype, text="") | 723 type_, subtype, text="") |
711 Ancestry: | 724 Ancestry: |
712 +-- object | 725 +-- object |
713 +-- Record | 726 +-- Record |
714 +-- ParametricRecord | 727 +-- ParametricRecord |
715 Atributes: | 728 Atributes: |
761 self.__vars = tuple[17] | 774 self.__vars = tuple[17] |
762 self.__parametric_summary = tuple[18] | 775 self.__parametric_summary = tuple[18] |
763 self.__parametric_text = tuple[19] | 776 self.__parametric_text = tuple[19] |
764 | 777 |
765 def __init__(self, budget, code, synonyms, hierarchy, unit, summary, | 778 def __init__(self, budget, code, synonyms, hierarchy, unit, summary, |
766 prices, type, subtype, parents=[], text=""): | 779 prices, type_, subtype, parents=[], text=""): |
767 Record.__init__(self, budget, code, synonyms, hierarchy, unit, summary, | 780 Record.__init__(self, budget, code, synonyms, hierarchy, unit, summary, |
768 prices, type, subtype, parents=[], text="") | 781 prices, type_, subtype, parents=[], text="") |
769 self.__parameters = {} | 782 self.__parameters = {} |
770 self.__select_comment = "" | 783 self.__select_comment = "" |
771 self.__vars = {} | 784 self.__vars = {} |
772 self.parametric_summary = "" | 785 self.parametric_summary = "" |
773 self.parametric_text = "" | 786 self.parametric_text = "" |
1089 """) | 1102 """) |
1090 fixed = property(getFixed, setFixed,None, | 1103 fixed = property(getFixed, setFixed,None, |
1091 """If fixed is True the yield is not calculated from measure | 1104 """If fixed is True the yield is not calculated from measure |
1092 """) | 1105 """) |
1093 | 1106 |
1094 def buildMeasure(self, list_lines, type, decimals, recordType): | 1107 def buildMeasure(self, list_lines, type_, decimals, recordType): |
1095 """setMeasure(self, list_lines, type, decimals) | 1108 """setMeasure(self, list_lines, type_, decimals) |
1096 | 1109 |
1097 list_lines: list of measure lines | 1110 list_lines: list of measure lines |
1098 [ [linetype, comment, units, length, width, height, formula], ... ] | 1111 [ [linetype, comment, units, length, width, height, formula], ... ] |
1099 linetype: | 1112 linetype: |
1100 #-#empty string -> Normal | 1113 #-#empty string -> Normal |
1127 _width, _height = _line[4], _line[5] | 1140 _width, _height = _line[4], _line[5] |
1128 _formula = _line[6] | 1141 _formula = _line[6] |
1129 _measure_line = MeasureLine(decimals, _type, _comment, _units, | 1142 _measure_line = MeasureLine(decimals, _type, _comment, _units, |
1130 _length, _width, _height, _formula) | 1143 _length, _width, _height, _formula) |
1131 _lines.append(_measure_line) | 1144 _lines.append(_measure_line) |
1132 if type == "M": | 1145 |
1146 if type_ == "M": | |
1133 self.lines = _lines | 1147 self.lines = _lines |
1134 elif type == "A": | 1148 elif type_ == "A": |
1135 self.lines.extend(_lines) | 1149 self.lines.extend(_lines) |
1136 else: | 1150 else: |
1137 raise ValueError, utils.mapping(_("Type must be M or A. Type: $1"), | 1151 raise ValueError, utils.mapping(_("Type must be M or A. Type: $1"), |
1138 (type,)) | 1152 (type_,)) |
1139 self.calculateMeasure(decimals, recordType) | 1153 self.calculateMeasure(decimals, recordType) |
1140 | 1154 |
1141 def calculateMeasure(self, decimals, recordType): | 1155 def calculateMeasure(self, decimals, recordType): |
1142 #TODO: round acumulated_subtotal and parcial_subtotal | 1156 #TODO: round acumulated_subtotal and parcial_subtotal |
1143 if len(self.lines) > 0: | 1157 if len(self.lines) > 0: |
1163 """base.MeasureLine: | 1177 """base.MeasureLine: |
1164 | 1178 |
1165 Description: | 1179 Description: |
1166 MeasureLine object | 1180 MeasureLine object |
1167 Constructor: | 1181 Constructor: |
1168 base.MeasureLine(budget, type, comment, units, length, width, height, | 1182 base.MeasureLine(budget, type_, comment, units, length, width, height, |
1169 formula) | 1183 formula) |
1170 Ancestry: | 1184 Ancestry: |
1171 +-- object | 1185 +-- object |
1172 +-- MeasureLine | 1186 +-- MeasureLine |
1173 Atributes: | 1187 Atributes: |
1189 "parcial_subtotal" | 1203 "parcial_subtotal" |
1190 "acumulated_subtotal" | 1204 "acumulated_subtotal" |
1191 Methods: | 1205 Methods: |
1192 __getstate__(self) | 1206 __getstate__(self) |
1193 __setstate__(self, tuple) | 1207 __setstate__(self, tuple) |
1194 __init__(self, decimals, type, comment, units, length, width, height, | 1208 __init__(self, decimals, type_, comment, units, length, width, height, |
1195 formula) | 1209 formula) |
1196 {get/set}LineType | 1210 {get/set}LineType |
1197 {get/set}Comment | 1211 {get/set}Comment |
1198 {get/set}Units | 1212 {get/set}Units |
1199 {get/set}Length | 1213 {get/set}Length |
1229 self.__width = tuple[4] | 1243 self.__width = tuple[4] |
1230 self.__height = tuple[5] | 1244 self.__height = tuple[5] |
1231 self.__formula = tuple[6] | 1245 self.__formula = tuple[6] |
1232 self.__parcial = tuple[7] | 1246 self.__parcial = tuple[7] |
1233 #self.calculateParcial() | 1247 #self.calculateParcial() |
1234 def __init__(self, decimals, type, comment, units, length, width, height, | 1248 def __init__(self, decimals, type_, comment, units, length, width, height, |
1235 formula): | 1249 formula): |
1236 self.__parcial = 0.0 | 1250 self.__parcial = 0.0 |
1237 self.__parcial_subtotal = 0.0 | 1251 self.__parcial_subtotal = 0.0 |
1238 self.__acumulated_subtotal = 0.0 | 1252 self.__acumulated_subtotal = 0.0 |
1239 self.lineType = type | 1253 self.lineType = type_ |
1240 self.comment = comment | 1254 self.comment = comment |
1241 self.setUnits(units, decimals) | 1255 self.setUnits(units, decimals) |
1242 self.setLength(length, decimals) | 1256 self.setLength(length, decimals) |
1243 self.setWidth(width, decimals) | 1257 self.setWidth(width, decimals) |
1244 self.setHeight(height, decimals) | 1258 self.setHeight(height, decimals) |
1304 else: | 1318 else: |
1305 _parcial = self.eval_formula() | 1319 _parcial = self.eval_formula() |
1306 _parcial = round(_parcial, _DS) | 1320 _parcial = round(_parcial, _DS) |
1307 self.__parcial = _parcial | 1321 self.__parcial = _parcial |
1308 | 1322 |
1309 def setLineType(self, type): | 1323 def setLineType(self, type_): |
1310 if not type in [0, 1, 2, 3]: | 1324 if not type_ in [0, 1, 2, 3]: |
1311 raise ValueError, utils.mapping(_("Invalid measure line type ($1)"), | 1325 raise ValueError, utils.mapping(_("Invalid measure line type ($1)"), |
1312 (str(type),)) | 1326 (str(type_),)) |
1313 self.__lineType = type | 1327 self.__lineType = type_ |
1314 def setComment(self, comment): | 1328 def setComment(self, comment): |
1315 if not isinstance(comment, str): | 1329 if not isinstance(comment, str): |
1316 raise ValueError, utils.mapping(_("Measure Comment must be a "\ | 1330 raise ValueError, utils.mapping(_("Measure Comment must be a "\ |
1317 "string ($1)"), (str(comment),)) | 1331 "string ($1)"), (str(comment),)) |
1318 self.__comment = comment | 1332 self.__comment = comment |
2003 date[2] in range(32): | 2017 date[2] in range(32): |
2004 if date[1] != 0 and date[2] != 0: | 2018 if date[1] != 0 and date[2] != 0: |
2005 datetime.date(*date) | 2019 datetime.date(*date) |
2006 self.__date = date | 2020 self.__date = date |
2007 else: | 2021 else: |
2008 raise TypeError, _("Invalid Date: %s" % str(date)) | 2022 raise TypeError, utils.mapping(_("Invalid Date: $1"),(str(date),)) |
2009 | 2023 |
2010 def setComment(self, comment): | 2024 def setComment(self, comment): |
2011 """setOwner(self, comment) | 2025 """setOwner(self, comment) |
2012 | 2026 |
2013 comment: text to comment the budged | 2027 comment: text to comment the budged |
2254 #_DF = measure.getDF(self.getDecimals()) | 2268 #_DF = measure.getDF(self.getDecimals()) |
2255 _factor = ("%." + str(_DF) + "f" ) % measure.factor | 2269 _factor = ("%." + str(_DF) + "f" ) % measure.factor |
2256 return _factor | 2270 return _factor |
2257 | 2271 |
2258 def setTree(self, code, child_code, position, factor, yield_, total, | 2272 def setTree(self, code, child_code, position, factor, yield_, total, |
2259 list_lines, label, type): | 2273 list_lines, label, type_): |
2260 """setTree(self, code, child_code, position, factor,yield_, total, | 2274 """setTree(self, code, child_code, position, factor,yield_, total, |
2261 list_lines, label, type) | 2275 list_lines, label, type_) |
2262 | 2276 |
2263 code: the parent record code | 2277 code: the parent record code |
2264 child_code: child record code | 2278 child_code: child record code |
2265 position: position of child record in record parent record | 2279 position: position of child record in record parent record |
2266 decomposition. Position == -1 -> new child | 2280 decomposition. Position == -1 -> new child |
2280 units: Number of Units (a) | 2294 units: Number of Units (a) |
2281 length: Length (b) | 2295 length: Length (b) |
2282 width: Width (c) | 2296 width: Width (c) |
2283 height: Height (d) | 2297 height: Height (d) |
2284 label: Record Identifiers that are used by some measure programs. | 2298 label: Record Identifiers that are used by some measure programs. |
2285 type: type of action | 2299 type_: type of action |
2286 M: Set measure | 2300 M: Set measure |
2287 A: Add measure | 2301 A: Add measure |
2288 Sets the decomposition of a record in a child record | 2302 Sets the decomposition of a record in a child record |
2289 """ | 2303 """ |
2304 if code is None: # No-estructured measures | |
2305 code = self.getRoot() | |
2306 if code == None: # No root | |
2307 print "No-estructured measures. Adding root record", | |
2308 self.setRecord("root", [], 0, "", "", [0.0,], [(1,1,1970)], | |
2309 0, "") | |
2310 code = self.getRoot() | |
2311 | |
2290 if not utils.is_valid_code(code)[0]: | 2312 if not utils.is_valid_code(code)[0]: |
2291 raise ValueError, utils.mapping(_("Invalid parent code: $1"), | 2313 raise ValueError, utils.mapping(_("Invalid parent code: $1"), |
2292 (code,)) | 2314 (code,)) |
2293 if not utils.is_valid_code(child_code)[0]: | 2315 if not utils.is_valid_code(child_code)[0]: |
2294 raise ValueError, utils.mapping(_("Invalid child code: $1"), | 2316 raise ValueError, utils.mapping(_("Invalid child code: $1 $2"), |
2295 (code,)) | 2317 (code,child_code)) |
2296 if not isinstance(position, int): | 2318 if not isinstance(position, int): |
2297 raise ValueError, utils.mapping(_("Invalid position in measure "\ | 2319 raise ValueError, utils.mapping(_("Invalid position in measure "\ |
2298 "$1, in code $2"), (parent_code, position)) | 2320 "$1, in code $2"), (parent_code, position)) |
2299 # Test circular references | 2321 # Test circular references |
2300 _all_parent_list = self.getAllParents(code) + [ code ] | 2322 _all_parent_list = self.getAllParents(code) + [ code ] |
2304 # TODO: change return to except | 2326 # TODO: change return to except |
2305 print utils.mapping(_("Circular Decomposition, parent code: "\ | 2327 print utils.mapping(_("Circular Decomposition, parent code: "\ |
2306 "$1, child code: $2, repeated code: $3"), | 2328 "$1, child code: $2, repeated code: $3"), |
2307 (code, child_code, _parent_code)) | 2329 (code, child_code, _parent_code)) |
2308 return | 2330 return |
2331 | |
2309 # Creating reference to parent code in child record | 2332 # Creating reference to parent code in child record |
2310 if child_code in self.__records: | 2333 if child_code in self.__records: |
2311 _child_record = self.__records[child_code] | 2334 _child_record = self.__records[child_code] |
2312 else: | 2335 else: |
2313 _child_record = self.setRecord(child_code, [], -1, "", "", [], [], | 2336 _child_record = self.setRecord(child_code, [], -1, "", "", [], [], |
2318 child_code = self.__records[child_code].code | 2341 child_code = self.__records[child_code].code |
2319 if code in self.__records: | 2342 if code in self.__records: |
2320 # if the code exits retake previous values. | 2343 # if the code exits retake previous values. |
2321 _record = self.__records[code] | 2344 _record = self.__records[code] |
2322 _child_number = len(_record.children) | 2345 _child_number = len(_record.children) |
2323 if position == -1: | 2346 if position == -1: # New child |
2324 position = _child_number | 2347 position = _child_number |
2348 if position == -2: # No-estructured measures or empty position (error in FIEBDC file) | |
2349 positions = _record.getChildPositions(child_code) | |
2350 if len(positions) == 1: | |
2351 position = positions[0] | |
2352 print utils.mapping(_("No-estructured measure or empty position. Parent Code: "\ | |
2353 "$1, Child code: $2, Position: $3"),(code, child_code, position)) | |
2354 else: | |
2355 position = _child_number | |
2356 print utils.mapping(_("No-estructured measure or empty position. "\ | |
2357 "Repeated child in unspecified position. "\ | |
2358 "It is impossible to determine the position. "\ | |
2359 "New child is added in the decomposition. "\ | |
2360 "Parent code: $1, Child code: $2, Position: $3"),(code, child_code, position)) | |
2325 if position == _child_number: | 2361 if position == _child_number: |
2326 # The record do not have the child | 2362 # The record do not have the child |
2327 if not isinstance(factor, float): factor = 1.0 | 2363 if not isinstance(factor, float): factor = 1.0 |
2328 if not isinstance(yield_, float): yield_ = 1.0 | 2364 if not isinstance(yield_, float): yield_ = 1.0 |
2329 if not isinstance(total, float): total = 0.0 | 2365 if not isinstance(total, float): total = 0.0 |
2330 if not isinstance(list_lines, list): list_lines = [] | 2366 if not isinstance(list_lines, list): list_lines = [] |
2331 _child = _record.appendChild(child_code, self.getDecimals(), | 2367 _child = _record.appendChild(child_code, self.getDecimals(), |
2332 factor, yield_, total, list_lines, type, label) | 2368 factor, yield_, total, list_lines, type_, label) |
2333 elif position < _child_number: | 2369 elif position < _child_number: |
2334 # The record have the child | 2370 # The record have the child |
2335 _child = _record.children[position] | 2371 _child = _record.children[position] |
2336 if child_code != "" and child_code != _child.code: | 2372 if child_code != "" and child_code != _child.code: |
2337 _child.code = child_code | 2373 _child.code = child_code |
2349 if total != "": | 2385 if total != "": |
2350 if not isinstance(total, float): | 2386 if not isinstance(total, float): |
2351 yield_ = 0.0 | 2387 yield_ = 0.0 |
2352 _measure.setMeasure(total, self.getDecimals()) | 2388 _measure.setMeasure(total, self.getDecimals()) |
2353 if isinstance(list_lines, list) and len(list_lines) > 0: | 2389 if isinstance(list_lines, list) and len(list_lines) > 0: |
2354 _measure.buildMeasure(list_lines, type, self.getDecimals(), | 2390 _measure.buildMeasure(list_lines, type_, self.getDecimals(), |
2355 _record.recordType) | 2391 _record.recordType) |
2356 if isinstance(label, str) and label != "" : | 2392 if isinstance(label, str) and label != "" : |
2357 _measure.label = label | 2393 _measure.label = label |
2358 else: | 2394 else: |
2359 # TODO: change return for except | 2395 # TODO: change return for except |
2372 print utils.mapping(_("Error: Invalid child position in "\ | 2408 print utils.mapping(_("Error: Invalid child position in "\ |
2373 "decomposition. Parent code: $1 Child code: $2 "\ | 2409 "decomposition. Parent code: $1 Child code: $2 "\ |
2374 "Position: $3"), (code, child_code, position)) | 2410 "Position: $3"), (code, child_code, position)) |
2375 return | 2411 return |
2376 if not isinstance(factor, float): | 2412 if not isinstance(factor, float): |
2377 factor == 1.0 | 2413 factor = 1.0 |
2378 if not isinstance(yield_, float): | 2414 if not isinstance(yield_, float): |
2379 yield_ = 1.0 | 2415 yield_ = 1.0 |
2416 if not isinstance(total, float): | |
2417 total = 1.0 | |
2380 _record = self.setRecord(code, [], "", "", "", [], [], | 2418 _record = self.setRecord(code, [], "", "", "", [], [], |
2381 "", "") | 2419 "", "") |
2382 _child = _record.appendChild(child_code, self.getDecimals(), | 2420 _child = _record.appendChild(child_code, self.getDecimals(), |
2383 factor, yield_, total, list_lines, type, label) | 2421 factor, yield_, total, list_lines, type_, label) |
2384 _child.budgetMeasures[0] = measure | |
2385 | 2422 |
2386 def eval_formula(self, formula, a, b, c, d): | 2423 def eval_formula(self, formula, a, b, c, d): |
2387 """eval_formula(self, formula, a, b, c, d) | 2424 """eval_formula(self, formula, a, b, c, d) |
2388 | 2425 |
2389 formula: | 2426 formula: |
2472 else: | 2509 else: |
2473 _record = self.__records[code] | 2510 _record = self.__records[code] |
2474 _record.text = text | 2511 _record.text = text |
2475 | 2512 |
2476 def setRecord(self, code, synonyms, hierarchy, unit, summary, price, date, | 2513 def setRecord(self, code, synonyms, hierarchy, unit, summary, price, date, |
2477 type, subtype): | 2514 type_, subtype): |
2478 """setRecord(self, code, synonyms, hierarchy, unit, summary, price, | 2515 """setRecord(self, code, synonyms, hierarchy, unit, summary, price, |
2479 date, type, subtype) | 2516 date, type_, subtype) |
2480 | 2517 |
2481 code: Code string | 2518 code: Code string |
2482 synonyms: List of synonym codes of the record | 2519 synonyms: List of synonym codes of the record |
2483 hierarchy: | 2520 hierarchy: |
2484 0 -> root | 2521 0 -> root |
2486 2 -> Other | 2523 2 -> Other |
2487 unit: unit of measure record | 2524 unit: unit of measure record |
2488 summary: Short description of a record | 2525 summary: Short description of a record |
2489 price: List of prices | 2526 price: List of prices |
2490 date: List of dates | 2527 date: List of dates |
2491 "type" and "subtype": | 2528 "type_" and "subtype": |
2492 0 Without classifying | 2529 0 Without classifying |
2493 EA Auxiliary element | 2530 EA Auxiliary element |
2494 EU Unitary element | 2531 EU Unitary element |
2495 EC Complex element | 2532 EC Complex element |
2496 EF Functional element | 2533 EF Functional element |
2527 if self.__root is None: | 2564 if self.__root is None: |
2528 self.__root = code | 2565 self.__root = code |
2529 else: | 2566 else: |
2530 print _("Only can be one root record") | 2567 print _("Only can be one root record") |
2531 return | 2568 return |
2569 # TODO: If the root is created in settree. No-estructured measures | |
2570 # TODO Rewrite root values | |
2532 # retake previous values. | 2571 # retake previous values. |
2533 # TODO: test synonyms | 2572 # TODO: test synonyms |
2534 _budget = self | 2573 _budget = self |
2535 if not code in self.__records: | 2574 if not code in self.__records: |
2536 if code[-1] == "$": | 2575 if code[-1] == "$": |
2537 _record = ParametricRecord(_budget.getDecimals(), code, | 2576 _record = ParametricRecord(_budget.getDecimals(), code, |
2538 synonyms, hierarchy, | 2577 synonyms, hierarchy, |
2539 unit, summary, [], type, subtype, | 2578 unit, summary, [], type_, subtype, |
2540 [], "") | 2579 [], "") |
2541 else: | 2580 else: |
2542 _record = Record(_budget.getDecimals(), code, synonyms, | 2581 _record = Record(_budget.getDecimals(), code, synonyms, |
2543 hierarchy, unit, | 2582 hierarchy, unit, |
2544 summary, [], type, subtype,[], "") | 2583 summary, [], type_, subtype,[], "") |
2545 self.__records[code] = _record | 2584 self.__records[code] = _record |
2546 _prices = [[price[i], date[i]] for i in range(len(price))] | 2585 _prices = [[price[i], date[i]] for i in range(len(price))] |
2547 _record.setPrices(_prices, self.getDecimals()) | 2586 _record.setPrices(_prices, self.getDecimals()) |
2548 else: | 2587 else: |
2549 _record = self.__records[code] | 2588 _record = self.__records[code] |
2557 #TODO: test empty price list | 2596 #TODO: test empty price list |
2558 if len(price) == 0 or price[0] == "": | 2597 if len(price) == 0 or price[0] == "": |
2559 _prices = _record.prices | 2598 _prices = _record.prices |
2560 else: | 2599 else: |
2561 _prices = [ [price[i], date[i]] for i in range(len(price))] | 2600 _prices = [ [price[i], date[i]] for i in range(len(price))] |
2562 if type == "": | 2601 if type_ == "": |
2563 type = _record.recordType.type | 2602 type_ = _record.recordType.type |
2564 _record.synonyms = synonyms | 2603 _record.synonyms = synonyms |
2565 _record.unit = unit | 2604 _record.unit = unit |
2566 _record.summary = summary | 2605 _record.summary = summary |
2567 _record.setPrices(_prices, self.getDecimals()) | 2606 _record.setPrices(_prices, self.getDecimals()) |
2568 _record.recordType.hierarchy = hierarchy | 2607 _record.recordType.hierarchy = hierarchy |
2569 _record.recordType.type = type | 2608 _record.recordType.type = type_ |
2570 _record.recordType.subtype = subtype | 2609 _record.recordType.subtype = subtype |
2571 return _record | 2610 return _record |
2572 | 2611 |
2573 def hasRecord(self,code): | 2612 def hasRecord(self,code): |
2574 """hasRecord(self,code) | 2613 """hasRecord(self,code) |
2745 self.setSheetParagraph(paragraph,"") | 2784 self.setSheetParagraph(paragraph,"") |
2746 if not self.hasSheetSection(section): | 2785 if not self.hasSheetSection(section): |
2747 self.setSheetSection(section, "") | 2786 self.setSheetSection(section, "") |
2748 _sheet = self.getRecord(record_code).getSheet() | 2787 _sheet = self.getRecord(record_code).getSheet() |
2749 _sheet.addSection(field, section, paragraph) | 2788 _sheet.addSection(field, section, paragraph) |
2750 def addFile(self, record_code, filepath, type, description): | 2789 def addFile(self, record_code, filepath, type_, description): |
2751 if not isinstance(record_code, str): | 2790 if not isinstance(record_code, str): |
2752 raise ValueError, _("The record_code code must be a string") | 2791 raise ValueError, _("The record_code code must be a string") |
2753 if not isinstance(filepath, str): | 2792 if not isinstance(filepath, str): |
2754 raise ValueError, _("The filename must be a string") | 2793 raise ValueError, _("The filename must be a string") |
2755 #-# | 2794 #-# |
2759 "code $1 and can not be added the file: $2"), | 2798 "code $1 and can not be added the file: $2"), |
2760 (record_code, filepath)) | 2799 (record_code, filepath)) |
2761 return | 2800 return |
2762 #-# | 2801 #-# |
2763 _record = self.getRecord(record_code) | 2802 _record = self.getRecord(record_code) |
2764 _record.addFile(filepath, type, description) | 2803 _record.addFile(filepath, type_, description) |
2765 def setCompany(self, company_code, sumamary, name, offices, | 2804 def setCompany(self, company_code, sumamary, name, offices, |
2766 cif, web, email): | 2805 cif, web, email): |
2767 if not isinstance(company_code, str): | 2806 if not isinstance(company_code, str): |
2768 raise ValueError, _("The company code must be a string") | 2807 raise ValueError, _("The company code must be a string") |
2769 if not isinstance(sumamary, str): | 2808 if not isinstance(sumamary, str): |
3016 self.__country = tuple[6] | 3055 self.__country = tuple[6] |
3017 self.__phone = tuple[7] | 3056 self.__phone = tuple[7] |
3018 self.__fax = tuple[8] | 3057 self.__fax = tuple[8] |
3019 self.__contact_person = tuple[9] | 3058 self.__contact_person = tuple[9] |
3020 | 3059 |
3021 def __init__(self, type, subname, address, postal_code, town, province, | 3060 def __init__(self, type_, subname, address, postal_code, town, province, |
3022 country, phone, fax, contact_person): | 3061 country, phone, fax, contact_person): |
3023 self.officeType = type | 3062 self.officeType = type_ |
3024 self.subname = subname | 3063 self.subname = subname |
3025 self.address = address | 3064 self.address = address |
3026 self.postal_code = postal_code | 3065 self.postal_code = postal_code |
3027 self.town = town | 3066 self.town = town |
3028 self.province = province | 3067 self.province = province |
3030 self.phone = phone | 3069 self.phone = phone |
3031 self.fax = fax | 3070 self.fax = fax |
3032 self.contact_person = contact_person | 3071 self.contact_person = contact_person |
3033 def getOfficeType(self): | 3072 def getOfficeType(self): |
3034 return self.__officeType | 3073 return self.__officeType |
3035 def setOfficeType(self, type): | 3074 def setOfficeType(self, type_): |
3036 self.__officeType = type | 3075 self.__officeType = type_ |
3037 def getSubname(self): | 3076 def getSubname(self): |
3038 return self.__subname | 3077 return self.__subname |
3039 def setSubname(self, subname): | 3078 def setSubname(self, subname): |
3040 self.__subname = subname | 3079 self.__subname = subname |
3041 def getAddress(self): | 3080 def getAddress(self): |
3247 """base.Company: | 3286 """base.Company: |
3248 | 3287 |
3249 Description: | 3288 Description: |
3250 File object | 3289 File object |
3251 Constructor: | 3290 Constructor: |
3252 base.File(name, type, description) | 3291 base.File(name, type_, description) |
3253 Ancestry: | 3292 Ancestry: |
3254 +-- object | 3293 +-- object |
3255 +-- File | 3294 +-- File |
3256 Atributes: | 3295 Atributes: |
3257 "name": name | 3296 "name": name |
3258 "fileType": type of file | 3297 "fileType": type of file |
3259 "description": description file | 3298 "description": description file |
3260 Methods: | 3299 Methods: |
3261 __getstate__(self) | 3300 __getstate__(self) |
3262 __setstate__(self, tuple) | 3301 __setstate__(self, tuple) |
3263 __init__(self, path,type, description) | 3302 __init__(self, path,type_, description) |
3264 {get/set}Name | 3303 {get/set}Name |
3265 {get/set}FileType | 3304 {get/set}FileType |
3266 {get/set}Description | 3305 {get/set}Description |
3267 getValues | 3306 getValues |
3268 """ | 3307 """ |
3278 ) | 3317 ) |
3279 def __setstate__(self,tuple): | 3318 def __setstate__(self,tuple): |
3280 self.__name = tuple[0] | 3319 self.__name = tuple[0] |
3281 self.__fileType = tuple[1] | 3320 self.__fileType = tuple[1] |
3282 self.__description = tuple[2] | 3321 self.__description = tuple[2] |
3283 def __init__(self, name, type, description): | 3322 def __init__(self, name, type_, description): |
3284 self.name = name | 3323 self.name = name |
3285 self.fileType = type | 3324 self.fileType = type_ |
3286 self.description = description | 3325 self.description = description |
3287 def getName(self): | 3326 def getName(self): |
3288 return self.__name | 3327 return self.__name |
3289 def setName(self, name): | 3328 def setName(self, name): |
3290 self.__name = name | 3329 self.__name = name |
3291 def getFileType(self): | 3330 def getFileType(self): |
3292 return self.__fileType | 3331 return self.__fileType |
3293 def setFileType(self, type): | 3332 def setFileType(self, type_): |
3294 self.__fileType = type | 3333 self.__fileType = type_ |
3295 def getDescription(self): | 3334 def getDescription(self): |
3296 return self.__description | 3335 return self.__description |
3297 def setDescription(self, description): | 3336 def setDescription(self, description): |
3298 self.__description = description | 3337 self.__description = description |
3299 def getValues(self): | 3338 def getValues(self): |
3354 2->Other -> 0 -> None,EA,EU,EC,EF,PA | 3393 2->Other -> 0 -> None,EA,EU,EC,EF,PA |
3355 1 -> None,H | 3394 1 -> None,H |
3356 2 -> None,Q,% | 3395 2 -> None,Q,% |
3357 3 -> None,MC,MCr,MM,MS,ME,MCu,Mal,ML,M | 3396 3 -> None,MC,MCr,MM,MS,ME,MCu,Mal,ML,M |
3358 Constructor: | 3397 Constructor: |
3359 base.File(hierarchy,type,subtype) | 3398 base.File(hierarchy,type_,subtype) |
3360 Ancestry: | 3399 Ancestry: |
3361 +-- object | 3400 +-- object |
3362 +-- RecordType | 3401 +-- RecordType |
3363 Atributes: | 3402 Atributes: |
3364 "hierarchy": hierarchy | 3403 "hierarchy": hierarchy |
3383 ) | 3422 ) |
3384 def __setstate__(self,tuple): | 3423 def __setstate__(self,tuple): |
3385 self.__hierarchy = tuple[0] | 3424 self.__hierarchy = tuple[0] |
3386 self.__type = tuple[1] | 3425 self.__type = tuple[1] |
3387 self.__subtype = tuple[2] | 3426 self.__subtype = tuple[2] |
3388 def __init__(self, hierarchy, type, subtype): | 3427 def __init__(self, hierarchy, type_, subtype): |
3389 self.hierarchy = hierarchy | 3428 self.hierarchy = hierarchy |
3390 self.type = type | 3429 self.type = type_ |
3391 self.subtype = subtype | 3430 self.subtype = subtype |
3392 def getHierarchy(self): | 3431 def getHierarchy(self): |
3393 return self.__hierarchy | 3432 return self.__hierarchy |
3394 def setHierarchy(self, hierarchy): | 3433 def setHierarchy(self, hierarchy): |
3395 if not hierarchy in [-1, 0 , 1 ,2]: | 3434 if not hierarchy in [-1, 0 , 1 ,2, ""]: |
3396 raise ValueError, utils.mapping(_("Invalid Hierarchy ($1) "\ | 3435 raise ValueError, utils.mapping(_("Invalid Hierarchy ($1) "\ |
3397 "The hierarchy must be -1, 0, 1 or 2"), (str(hierarchy))) | 3436 "The hierarchy must be -1, 0, 1, 2"), (str(hierarchy),)) |
3437 elif hierarchy == "": | |
3438 print "Hierarchy temporarily set to an empty string" | |
3439 #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget | |
3398 self.__hierarchy = hierarchy | 3440 self.__hierarchy = hierarchy |
3399 def getType(self): | 3441 def getType(self): |
3400 return self.__type | 3442 return self.__type |
3401 def setType(self, type): | 3443 def setType(self, type_): |
3402 if not type in ["", 0, 1, 2, 3] : | 3444 if not type_ in ["", 0, 1, 2, 3] : |
3403 raise ValueError, utils.mapping(_("Invalid type ($1),"\ | 3445 raise ValueError, utils.mapping(_("Invalid type ($1),"\ |
3404 "the type must be (empty string,0,1,2,3)"),(str(type))) | 3446 "the type must be (empty string,0,1,2,3)"),(str(type_)),) |
3405 self.__type = type | 3447 self.__type = type_ |
3406 def getSubtype(self): | 3448 def getSubtype(self): |
3407 return self.__subtype | 3449 return self.__subtype |
3408 def setSubtype(self, subtype): | 3450 def setSubtype(self, subtype): |
3409 if not subtype in ["", "OB", "PU", "EA", "EU", "EC", "EF", "PA", "H", | 3451 if not subtype in ["", "OB", "PU", "EA", "EU", "EC", "EF", "PA", "H", |
3410 "Q", "%", "MC", "MCr", "MM", "MS", "ME", "MCu", | 3452 "Q", "%", "MC", "MCr", "MM", "MS", "ME", "MCu", |
3411 "Mal","ML","M"]: | 3453 "Mal","ML","M"]: |
3412 raise ValueError, utils.mapping(_("Invalid subtype ($1), The "\ | 3454 raise ValueError, utils.mapping(_("Invalid subtype ($1), The "\ |
3413 "subtype must one in (empty string, EA, "\ | 3455 "subtype must one in (empty string, EA, "\ |
3414 "EU, EC, EF, OB, PA, PU, H, Q, %, MC, MCr, "\ | 3456 "EU, EC, EF, OB, PA, PU, H, Q, %, MC, MCr, "\ |
3415 "MM, MS, ME, MCu, MAl, ML, M)"), (str(subtype))) | 3457 "MM, MS, ME, MCu, MAl, ML, M)"), (str(subtype),)) |
3416 self.__subtype = subtype | 3458 self.__subtype = subtype |
3417 hierarchy = property(getHierarchy, setHierarchy, None, | 3459 hierarchy = property(getHierarchy, setHierarchy, None, |
3418 """Record Hierarchy | 3460 """Record Hierarchy |
3419 -1 -> temporarily unfixed | 3461 -1 -> temporarily unfixed |
3420 0 -> root | 3462 0 -> root |