comparison Generic/base.py @ 25:189f8274aecd

gui. switch navigation menu on switch page
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Mon, 20 May 2019 13:18:33 +0200
parents 65e7ae0d0e63
children 16f91684686b
comparison
equal deleted inserted replaced
24:2b393934f1db 25:189f8274aecd
416 """setCode(code) 416 """setCode(code)
417 417
418 Sets the code, must be a valid code 418 Sets the code, must be a valid code
419 """ 419 """
420 if not utils.is_valid_code(code)[0]: 420 if not utils.is_valid_code(code)[0]:
421 raise ValueError( utils.mapping(_("Invalid code: $1"),(str(code),)) ) 421 raise ValueError(utils.mapping(_("Invalid code: $1"),(str(code),)))
422 self.__code = code 422 self.__code = code
423 423
424 def getSynonyms(self): 424 def getSynonyms(self):
425 return self.__synonyms 425 return self.__synonyms
426 426
1002 def getCertification(self): 1002 def getCertification(self):
1003 return self.__certification 1003 return self.__certification
1004 1004
1005 def setCertification(self, certification): 1005 def setCertification(self, certification):
1006 if not (certification is None or isinstance(certification, list)): 1006 if not (certification is None or isinstance(certification, list)):
1007 raise ValueError( _("Certification atribute must be a list or None") ) 1007 raise ValueError(_("Certification atribute must be a list or None"))
1008 self.__certification = certification 1008 self.__certification = certification
1009 1009
1010 def getRealCost(self): 1010 def getRealCost(self):
1011 return self.__real_cost 1011 return self.__real_cost
1012 1012
1026 def getCostPlanned(self): 1026 def getCostPlanned(self):
1027 return self.__cost_planned 1027 return self.__cost_planned
1028 1028
1029 def setCostPlanned(self, cost_planned): 1029 def setCostPlanned(self, cost_planned):
1030 if not (cost_planned is None or isinstance(cost_planned, list)): 1030 if not (cost_planned is None or isinstance(cost_planned, list)):
1031 raise ValueError( _("Cost Planned atribute must be a list or None") ) 1031 raise ValueError(_("Cost Planned atribute must be a list or None"))
1032 self.__cost_planned = cost_planned 1032 self.__cost_planned = cost_planned
1033 1033
1034 position = property(getPosition, setPosition, None, 1034 position = property(getPosition, setPosition, None,
1035 """Postion of the record in the budget 1035 """Postion of the record in the budget
1036 """) 1036 """)
1659 and the factor in a descomposition of a unit of work. 1659 and the factor in a descomposition of a unit of work.
1660 Default: 3 decimal places. 1660 Default: 3 decimal places.
1661 "DRA": Number of decimal places of the yield in a decompositon of a 1661 "DRA": Number of decimal places of the yield in a decompositon of a
1662 auxiliar element. 1662 auxiliar element.
1663 Number of decimal places of the result of the multiplication of 1663 Number of decimal places of the result of the multiplication of
1664 the yield and the factor in a descomposition of a auxilar element.Decimales 1664 the yield and the factor in a descomposition of a auxilar element.
1665 Default: 3 decimal places. 1665 Default: 3 decimal places.
1666 "DP": Number of decimal places of the price of a budget. 1666 "DP": Number of decimal places of the price of a budget.
1667 Default: 2 decimal places. 1667 Default: 2 decimal places.
1668 "DC": Number of decimal places of the price of a chapter or subchapter. 1668 "DC": Number of decimal places of the price of a chapter or subchapter.
1669 Default: 2 decimal places. 1669 Default: 2 decimal places.
1924 The Headers is the type of hierarchy of the prices 1924 The Headers is the type of hierarchy of the prices
1925 Each Title have a group of Prices and a Decimals definition 1925 Each Title have a group of Prices and a Decimals definition
1926 The records can have diferent prices for diferent ages, geografical 1926 The records can have diferent prices for diferent ages, geografical
1927 places, ... 1927 places, ...
1928 +-- __title_index: A integer. The active group of Prices and Decimals. 1928 +-- __title_index: A integer. The active group of Prices and Decimals.
1929 +-- __sheet_sections: sheet sections dictionary { sheet_code : sheet_title } 1929 +-- __sheet_sections: sheet sections dictionary
1930 { sheet_code : sheet_title }
1930 +-- __sheet_fields: sheet fields dictionary { field_code : field_title } 1931 +-- __sheet_fields: sheet fields dictionary { field_code : field_title }
1931 +-- __sheet_paragraphs: sheet paragraphs dictionary 1932 +-- __sheet_paragraphs: sheet paragraphs dictionary
1932 { paragraph_code : paragraph_text} 1933 { paragraph_code : paragraph_text}
1933 +-- __companys: Dictionary whith companys object 1934 +-- __companys: Dictionary whith companys object
1934 { company_code: company_object } 1935 { company_code: company_object }
2188 date[2] in range(32): 2189 date[2] in range(32):
2189 if date[1] != 0 and date[2] != 0: 2190 if date[1] != 0 and date[2] != 0:
2190 datetime.date(*date) 2191 datetime.date(*date)
2191 self.__date = date 2192 self.__date = date
2192 else: 2193 else:
2193 raise TypeError( utils.mapping(_("Invalid Date: $1"),(str(date),)) ) 2194 raise TypeError(utils.mapping(_("Invalid Date: $1"),(str(date),)))
2194 2195
2195 def setComment(self, comment): 2196 def setComment(self, comment):
2196 """setOwner(self, comment) 2197 """setOwner(self, comment)
2197 2198
2198 comment: text to comment the budged 2199 comment: text to comment the budged
2242 isinstance(certificate_date[1], int) and \ 2243 isinstance(certificate_date[1], int) and \
2243 isinstance(certificate_date[2], int): 2244 isinstance(certificate_date[2], int):
2244 datetime.date(*certificate_date) 2245 datetime.date(*certificate_date)
2245 self.__budgetCerficateDate = certificate_date 2246 self.__budgetCerficateDate = certificate_date
2246 else: 2247 else:
2247 raise ValueError( _("Budget certificate Date must be a valid Date.") ) 2248 _str = _("Budget certificate Date must be a valid Date.")
2249 raise ValueError(_str)
2248 2250
2249 def setTitleList(self, title_list): 2251 def setTitleList(self, title_list):
2250 """setTitleList(self, title_list) 2252 """setTitleList(self, title_list)
2251 2253
2252 title_list: [ "Header", ["Title1", "Title2", ... ] ] 2254 title_list: [ "Header", ["Title1", "Title2", ... ] ]
2479 if code is None: # No-estructured measures 2481 if code is None: # No-estructured measures
2480 code = self.getRoot() 2482 code = self.getRoot()
2481 if code == None: # No root 2483 if code == None: # No root
2482 print( "No-estructured measures. Adding root record " + 2484 print( "No-estructured measures. Adding root record " +
2483 str(self.setRecord("root", [], 0, "", "", [0.0,], [(1,1,1970)], 2485 str(self.setRecord("root", [], 0, "", "", [0.0,], [(1,1,1970)],
2484 0, "") )) 2486 0, "") ).encode("utf8"))
2485 code = self.getRoot() 2487 code = self.getRoot()
2486 2488
2487 if not utils.is_valid_code(code)[0]: 2489 if not utils.is_valid_code(code)[0]:
2488 raise ValueError( utils.mapping(_("Invalid parent code: $1"), 2490 raise ValueError( utils.mapping(_("Invalid parent code: $1"),
2489 (str(code),)) ) 2491 (str(code),)) )
2497 _all_parent_list = self.getAllParents(code) + [ code ] 2499 _all_parent_list = self.getAllParents(code) + [ code ]
2498 _all_child_list = self.getAllchildren(child_code) + [ child_code ] 2500 _all_child_list = self.getAllchildren(child_code) + [ child_code ]
2499 for _parent_code in _all_parent_list: 2501 for _parent_code in _all_parent_list:
2500 if _parent_code in _all_child_list: 2502 if _parent_code in _all_child_list:
2501 # TODO: change return to except 2503 # TODO: change return to except
2502 print(utils.mapping(_("Circular Decomposition, parent code: "\ 2504 _str = _("Circular Decomposition, parent code: "\
2503 "$1, child code: $2, repeated code: $3"), 2505 "$1, child code: $2, repeated code: $3")
2504 (str(code), str(child_code), str(_parent_code))) ) 2506 print(utils.mapping(_str, (str(code), str(child_code),
2507 str(_parent_code))).encode("utf8") )
2505 return 2508 return
2506 2509
2507 # Creating reference to parent code in child record 2510 # Creating reference to parent code in child record
2508 if child_code in self.__records: 2511 if child_code in self.__records:
2509 _child_record = self.__records[child_code] 2512 _child_record = self.__records[child_code]
2518 # if the code exits retake previous values. 2521 # if the code exits retake previous values.
2519 _record = self.__records[code] 2522 _record = self.__records[code]
2520 _child_number = len(_record.children) 2523 _child_number = len(_record.children)
2521 if position == -1: # New child 2524 if position == -1: # New child
2522 position = _child_number 2525 position = _child_number
2523 if position == -2: # No-estructured measures or empty position (error in FIEBDC file) 2526 # No-estructured measures or empty position (error in FIEBDC file)
2527 if position == -2:
2524 positions = _record.getChildPositions(child_code) 2528 positions = _record.getChildPositions(child_code)
2525 if len(positions) == 1: 2529 if len(positions) == 1:
2526 position = positions[0] 2530 position = positions[0]
2527 print(utils.mapping(_("No-estructured measure or empty position. Parent Code: "\ 2531 _str = _("No-estructured measure or empty position. " \
2528 "$1, Child code: $2, Position: $3"),(str(code), str(child_code), str(position))) ) 2532 "Parent Code: $1, Child code: $2, Position: $3")
2533 print(utils.mapping(_str,(str(code), str(child_code),
2534 str(position))).encode("utf8") )
2529 else: 2535 else:
2530 position = _child_number 2536 position = _child_number
2531 print(utils.mapping(_("No-estructured measure or empty position. "\ 2537 _str = _("No-estructured measure or empty position. "\
2532 "Repeated child in unspecified position. "\ 2538 "Repeated child in unspecified position. "\
2533 "It is impossible to determine the position. "\ 2539 "It is impossible to determine the position. "\
2534 "New child is added in the decomposition. "\ 2540 "New child is added in the decomposition. "\
2535 "Parent code: $1, Child code: $2, Position: $3"),(str(code), str(child_code), str(position))) ) 2541 "Parent code: $1, Child code: $2, Position: $3")
2542 print(utils.mapping(_str,(str(code), str(child_code),
2543 str(position))).encode("utf8") )
2536 if position == _child_number: 2544 if position == _child_number:
2537 # The record do not have the child 2545 # The record do not have the child
2538 if not isinstance(factor, float): factor = 1.0 2546 if not isinstance(factor, float): factor = 1.0
2539 if not isinstance(yield_, float): yield_ = 1.0 2547 if not isinstance(yield_, float): yield_ = 1.0
2540 if not isinstance(total, float): total = 0.0 2548 if not isinstance(total, float): total = 0.0
2566 _record.recordType) 2574 _record.recordType)
2567 if isinstance(label, str) and label != "" : 2575 if isinstance(label, str) and label != "" :
2568 _measure.label = label 2576 _measure.label = label
2569 else: 2577 else:
2570 # TODO: change return for except 2578 # TODO: change return for except
2571 print(utils.mapping(_("Error: Invalid child position in " 2579 _str = _("Error: Invalid child position in "
2572 "decomposition. Parent code: $1 Child code: $2 "\ 2580 "decomposition. Parent code: $1 Child code: $2 "\
2573 "Position: $3"), (str(code), str(child_code), str(position))) ) 2581 "Position: $3")
2582 print(utils.mapping(_str, (str(code), str(child_code),
2583 str(position))).encode("utf8") )
2574 return 2584 return
2575 else: 2585 else:
2576 if child_code == "" : 2586 if child_code == "" :
2577 print(utils.mapping(_("Error: Empty child code. Parent code: "\ 2587 _str = _("Error: Empty child code. Parent code: "\
2578 "$1 Position: $2"), (str(code), str(position))) ) 2588 "$1 Position: $2")
2589 print(utils.mapping(_str, (str(code),
2590 str(position))).encode("utf8") )
2579 return 2591 return
2580 if position == -1: 2592 if position == -1:
2581 position = 0 2593 position = 0
2582 elif position != 0: 2594 elif position != 0:
2583 print(utils.mapping(_("Error: Invalid child position in "\ 2595 _str = _("Error: Invalid child position in "\
2584 "decomposition. Parent code: $1 Child code: $2 "\ 2596 "decomposition. Parent code: $1 Child code: $2 "\
2585 "Position: $3"), (str(code), str(child_code), str(position))) ) 2597 "Position: $3")
2598 print(utils.mapping(_str, (str(code), str(child_code),
2599 str(position))).encode("utf8") )
2586 return 2600 return
2587 if not isinstance(factor, float): 2601 if not isinstance(factor, float):
2588 factor = 1.0 2602 factor = 1.0
2589 if not isinstance(yield_, float): 2603 if not isinstance(yield_, float):
2590 yield_ = 1.0 2604 yield_ = 1.0
2674 code: the parent record code 2688 code: the parent record code
2675 text: the descripion text 2689 text: the descripion text
2676 Sests the description text of a record 2690 Sests the description text of a record
2677 """ 2691 """
2678 if not utils.is_valid_code(code)[0]: 2692 if not utils.is_valid_code(code)[0]:
2679 raise ValueError( utils.mapping(_("Invalid record: $1"), (str(code),)) ) 2693 _str = _("Invalid record: $1")
2694 raise ValueError( utils.mapping(_str, (str(code),)) )
2680 if not code in self.__records: 2695 if not code in self.__records:
2681 _record = self.setRecord(code, [], "", "", "", [], [], 2696 _record = self.setRecord(code, [], "", "", "", [], [],
2682 "", "") 2697 "", "")
2683 _record.text = text 2698 _record.text = text
2684 else: 2699 else:
2737 if hierarchy == 0 : 2752 if hierarchy == 0 :
2738 # is the root record 2753 # is the root record
2739 if self.__root is None: 2754 if self.__root is None:
2740 self.__root = code 2755 self.__root = code
2741 else: 2756 else:
2742 print(_("Only can be one root record") ) 2757 print(_("Only can be one root record").encode("utf8") )
2743 return 2758 return
2744 # TODO: If the root is created in settree. No-estructured measures 2759 # TODO: If the root is created in settree.
2760 # No-estructured measures
2745 # TODO Rewrite root values 2761 # TODO Rewrite root values
2746 # retake previous values. 2762 # retake previous values.
2747 # TODO: test synonyms 2763 # TODO: test synonyms
2748 _budget = self 2764 _budget = self
2749 if not code in self.__records: 2765 if not code in self.__records:
2974 2990
2975 def setSheetParagraphs(self, paragraph_dict): 2991 def setSheetParagraphs(self, paragraph_dict):
2976 if not isinstance(paragraph_dict, dict): 2992 if not isinstance(paragraph_dict, dict):
2977 raise ValueError( _("The paragraph dict must be a dictionary") ) 2993 raise ValueError( _("The paragraph dict must be a dictionary") )
2978 for paragraph_code in paragraph_dict.keys(): 2994 for paragraph_code in paragraph_dict.keys():
2979 self.setSheetParagraph( paragraph_code, paragraph_dict[paragraph_code]) 2995 self.setSheetParagraph(paragraph_code,
2996 paragraph_dict[paragraph_code])
2980 2997
2981 def setSheetRecord(self, record_code, field, section_dict): 2998 def setSheetRecord(self, record_code, field, section_dict):
2982 if not isinstance(record_code, str): 2999 if not isinstance(record_code, str):
2983 raise ValueError( _("The record_code code must be a string") ) 3000 raise ValueError( _("The record_code code must be a string") )
2984 if not isinstance(field, str): 3001 if not isinstance(field, str):
2986 if not isinstance(section_dict, dict): 3003 if not isinstance(section_dict, dict):
2987 raise ValueError( _("The section dict must be a dictionary") ) 3004 raise ValueError( _("The section dict must be a dictionary") )
2988 #-# 3005 #-#
2989 # TODO: Add a empty record? 3006 # TODO: Add a empty record?
2990 if not self.hasRecord(record_code): 3007 if not self.hasRecord(record_code):
2991 print(utils.mapping(_("Error: The budget do not have this record "\ 3008 _str = _("Error: The budget do not have this record "\
2992 "code and can not be added the sheet text in the field $1. "\ 3009 "code and can not be added the sheet text in the field $1. "\
2993 "Record Code: $2"), ( str(field), str(record_code))) ) 3010 "Record Code: $2")
3011 print(utils.mapping(_str, ( str(field),
3012 str(record_code))).encode("utf8") )
2994 return 3013 return
2995 #-# 3014 #-#
2996 if not self.hasSheetField(field): 3015 if not self.hasSheetField(field):
2997 self.setSheetField(field, "") 3016 self.setSheetField(field, "")
2998 for section, paragraph in section_dict.iteritems(): 3017 for section, paragraph in section_dict.iteritems():
3012 #-# 3031 #-#
3013 # TODO: Add a empty record? 3032 # TODO: Add a empty record?
3014 if not self.hasRecord(record_code): 3033 if not self.hasRecord(record_code):
3015 print(utils.mapping(_("Error: The budget do not have the record "\ 3034 print(utils.mapping(_("Error: The budget do not have the record "\
3016 "code $1 and can not be added the file: $2"), 3035 "code $1 and can not be added the file: $2"),
3017 (str(record_code), str(filepath))) ) 3036 (str(record_code), str(filepath))).encode("utf8") )
3018 return 3037 return
3019 #-# 3038 #-#
3020 _record = self.getRecord(record_code) 3039 _record = self.getRecord(record_code)
3021 _record.addFile(filepath, type_, description) 3040 _record.addFile(filepath, type_, description)
3022 3041
3150 "string") ) 3169 "string") )
3151 if not self.hasRecord(record_code): 3170 if not self.hasRecord(record_code):
3152 print(utils.mapping(_("Error: The budget do not have the record "\ 3171 print(utils.mapping(_("Error: The budget do not have the record "\
3153 "code $1 and can not be added the Parametric select comment: "\ 3172 "code $1 and can not be added the Parametric select comment: "\
3154 "$2"), 3173 "$2"),
3155 (str(record_code), str(comment))) ) 3174 (str(record_code), str(comment))).encode("utf8") )
3156 return 3175 return
3157 _record = self.getRecord(record_code) 3176 _record = self.getRecord(record_code)
3158 if not isinstance(_record, ParametricRecord): 3177 if not isinstance(_record, ParametricRecord):
3159 print(utils.mapping(_("Error: The Record $1 is not a "\ 3178 print(utils.mapping(_("Error: The Record $1 is not a "\
3160 "Parametric Record and can not have Parametric comment"), 3179 "Parametric Record and can not have Parametric comment"),
3161 (str(record_code),)) ) 3180 (str(record_code),)).encode("utf8") )
3162 else: 3181 else:
3163 _record.select_comment = comment 3182 _record.select_comment = comment
3164 3183
3165 def setParametricSummary(self, record_code, summary): 3184 def setParametricSummary(self, record_code, summary):
3166 """setParametricSummary(self, record_code, summary) 3185 """setParametricSummary(self, record_code, summary)
3172 if not isinstance(summary, str): 3191 if not isinstance(summary, str):
3173 raise ValueError( _("The summary record must be a string") ) 3192 raise ValueError( _("The summary record must be a string") )
3174 if not self.hasRecord(record_code): 3193 if not self.hasRecord(record_code):
3175 print(utils.mapping(_("Error: The budget do not have the record "\ 3194 print(utils.mapping(_("Error: The budget do not have the record "\
3176 "code $1 and can not be seted the summary: $2"), 3195 "code $1 and can not be seted the summary: $2"),
3177 (str(record_code), str(summary))) ) 3196 (str(record_code), str(summary))).encode("utf8") )
3178 return 3197 return
3179 _record = self.getRecord(record_code) 3198 _record = self.getRecord(record_code)
3180 if not isinstance(_record, ParametricRecord): 3199 if not isinstance(_record, ParametricRecord):
3181 print(utils.mapping(_("Error: The Record $1 is not a "\ 3200 print(utils.mapping(_("Error: The Record $1 is not a "\
3182 "Parametric Record and can not have Parametric summary"), 3201 "Parametric Record and can not have Parametric summary"),
3183 (str(record_code),)) ) 3202 (str(record_code),)).encode("utf8") )
3184 else: 3203 else:
3185 self.getRecord(record_code).parametric_summary = summary 3204 self.getRecord(record_code).parametric_summary = summary
3186 3205
3187 def setParametricText(self, record_code, text): 3206 def setParametricText(self, record_code, text):
3188 """setParametricText(self, record_code, text) 3207 """setParametricText(self, record_code, text)
3194 if not isinstance(text, str): 3213 if not isinstance(text, str):
3195 raise ValueError( _("The text record must be a string") ) 3214 raise ValueError( _("The text record must be a string") )
3196 if not self.hasRecord(record_code): 3215 if not self.hasRecord(record_code):
3197 print(utils.mapping(_("Error: The budget do not have the record "\ 3216 print(utils.mapping(_("Error: The budget do not have the record "\
3198 "code $1 and can not be seted the text: $2"), 3217 "code $1 and can not be seted the text: $2"),
3199 (str(record_code), str(text))) ) 3218 (str(record_code), str(text))).encode("utf8") )
3200 return 3219 return
3201 _record = self.getRecord(record_code) 3220 _record = self.getRecord(record_code)
3202 if not isinstance(_record, ParametricRecord): 3221 if not isinstance(_record, ParametricRecord):
3203 print(utils.mapping(_("Error: The Record $1 is not a "\ 3222 print(utils.mapping(_("Error: The Record $1 is not a "\
3204 "Parametric Record and can not have Parametric text"), 3223 "Parametric Record and can not have Parametric text"),
3205 (str(record_code),)) ) 3224 (str(record_code),)).encode("utf8") )
3206 else: 3225 else:
3207 self.getRecord(record_code).parametric_text = text 3226 self.getRecord(record_code).parametric_text = text
3208 3227
3209 3228
3210 class Office(object): 3229 class Office(object):
3724 def setHierarchy(self, hierarchy): 3743 def setHierarchy(self, hierarchy):
3725 if not hierarchy in [-1, 0 , 1 ,2, ""]: 3744 if not hierarchy in [-1, 0 , 1 ,2, ""]:
3726 raise ValueError( utils.mapping(_("Invalid Hierarchy ($1) "\ 3745 raise ValueError( utils.mapping(_("Invalid Hierarchy ($1) "\
3727 "The hierarchy must be -1, 0, 1, 2"), (str(hierarchy),)) ) 3746 "The hierarchy must be -1, 0, 1, 2"), (str(hierarchy),)) )
3728 elif hierarchy == "": 3747 elif hierarchy == "":
3729 print("Hierarchy temporarily set to an empty string") 3748 print("Hierarchy temporarily set to an empty string".encode("utf8"))
3730 #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget 3749 #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget
3731 self.__hierarchy = hierarchy 3750 self.__hierarchy = hierarchy
3732 3751
3733 def getType(self): 3752 def getType(self):
3734 return self.__type 3753 return self.__type