Mercurial > pyarq-presupuestos
comparison Generic/base.py @ 26:16f91684686b default tip
Upgrade to python 3. Keep python 2/3 compatibility
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Tue, 18 Jun 2019 17:50:23 +0200 |
parents | 189f8274aecd |
children |
comparison
equal
deleted
inserted
replaced
25:189f8274aecd | 26:16f91684686b |
---|---|
261 +-- __labels": Label dictionary { "label": [ "code", ], } | 261 +-- __labels": Label dictionary { "label": [ "code", ], } |
262 """ | 262 """ |
263 | 263 |
264 # Modules | 264 # Modules |
265 # python 2/3 compatibility | 265 # python 2/3 compatibility |
266 #from __future__ import absolute_import, division, print_function, unicode_literals | 266 from __future__ import absolute_import, division, print_function, unicode_literals |
267 from builtins import str as text | |
268 from six import text_type | |
267 | 269 |
268 import re | 270 import re |
269 import datetime | 271 import datetime |
270 import os | 272 import os |
271 | 273 |
275 | 277 |
276 | 278 |
277 # Translatable global Vars | 279 # Translatable global Vars |
278 | 280 |
279 authors = ["Miguel Ángel Bárcena Rodríguez"] | 281 authors = ["Miguel Ángel Bárcena Rodríguez"] |
280 copyright = "Copyright \xc2\xa9 2019 Autoras de Pyarq Presupuestos" | 282 copyright = "Copyright © 2019 Autoras de Pyarq Presupuestos" |
281 website = "http://pyarq.obraencurso.es/pyarq-Presupuestos" | 283 website = "http://pyarq.obraencurso.es/pyarq-Presupuestos" |
282 website_label = "pyarq Presupuestos Web" | 284 website_label = "pyarq Presupuestos Web" |
283 comments = _(""" | 285 comments = _(""" |
284 A free program of measurements, budgets and control of construction sites. | 286 A free program of measurements, budgets and control of construction sites. |
285 In beta development, still there is not a fully functional version. | 287 In beta development, still there is not a fully functional version. |
416 """setCode(code) | 418 """setCode(code) |
417 | 419 |
418 Sets the code, must be a valid code | 420 Sets the code, must be a valid code |
419 """ | 421 """ |
420 if not utils.is_valid_code(code)[0]: | 422 if not utils.is_valid_code(code)[0]: |
421 raise ValueError(utils.mapping(_("Invalid code: $1"),(str(code),))) | 423 _uni = utils.mapping(_("Invalid code: $1"),(code,)) |
424 _str = _uni.encode("utf-8") | |
425 raise ValueError(_str) | |
422 self.__code = code | 426 self.__code = code |
423 | 427 |
424 def getSynonyms(self): | 428 def getSynonyms(self): |
425 return self.__synonyms | 429 return self.__synonyms |
426 | 430 |
431 synonyms must fulfill: | 435 synonyms must fulfill: |
432 - must be a list | 436 - must be a list |
433 - the items must be valid codes | 437 - the items must be valid codes |
434 """ | 438 """ |
435 if not isinstance(synonyms, list): | 439 if not isinstance(synonyms, list): |
436 raise TypeError( utils.mapping(_("Synonyms ($1) must be a list, " \ | 440 _tuni = _("Synonyms ($1) must be a list, code: $2") |
437 "code: $2"), (str(synonyms), str(self.__code))) ) | 441 _uni = utils.mapping(_tuni, (synonyms, self.__code)) |
442 _str = _uni.encode("utf-8") | |
443 raise TypeError(_str) | |
438 for code in synonyms: | 444 for code in synonyms: |
439 if not utils.is_valid_code(code)[0]: | 445 if not utils.is_valid_code(code)[0]: |
440 raise ValueError( utils.mapping(_("Invalid Code in synomyms "\ | 446 _tuni = _("Invalid Code in synomyms list ($1) code: $2") |
441 "list ($1) code: $2"), (str(code), str(self.__code))) ) | 447 _uni = utils.mapping(_tuni, (code, self.__code)) |
448 _str = _uni.encode("utf-8") | |
449 raise ValueError(_str) | |
442 self.__synonyms = synonyms | 450 self.__synonyms = synonyms |
443 | 451 |
444 def getRecordType(self): | 452 def getRecordType(self): |
445 return self.__recordType | 453 return self.__recordType |
446 | 454 |
465 """setUnit(unit) | 473 """setUnit(unit) |
466 | 474 |
467 Set the unit of measure | 475 Set the unit of measure |
468 The unit must be a string. | 476 The unit must be a string. |
469 """ | 477 """ |
470 if not isinstance(unit, str): | 478 if not isinstance(unit, text_type): |
471 raise TypeError( utils.mapping(_("Unit ($1) must be a string: $2"), | 479 _tuni = _("Unit ($1) must be a text string: $2") |
472 (str(unit), str(self.__code))) ) | 480 _uni = utils.mapping(_tuni, (unit, self.__code)) |
481 _str = _uni.encode("utf-8") | |
482 raise TypeError(_str) | |
473 self.__unit = unit | 483 self.__unit = unit |
474 | 484 |
475 def getSummary(self): | 485 def getSummary(self): |
476 return self.__summary | 486 return self.__summary |
477 | 487 |
479 """setSummary(summary) | 489 """setSummary(summary) |
480 | 490 |
481 Set the summary of a record | 491 Set the summary of a record |
482 The summary must be a string. | 492 The summary must be a string. |
483 """ | 493 """ |
484 if not isinstance(summary, str): | 494 if not isinstance(summary, text_type): |
485 raise TypeError( utils.mapping(_("Summary ($1) must be a string: "\ | 495 _tuni = _("Summary ($1) must be a text string: $1") |
486 "$1"), (str(summary), str(self.__code))) ) | 496 _uni = utils.mapping(_tuni, (summary, self.__code)) |
497 _str = _uni.encode("utf-8") | |
498 raise TypeError(_str) | |
487 self.__summary = summary | 499 self.__summary = summary |
488 | 500 |
489 def getPrices(self): | 501 def getPrices(self): |
490 return self.__prices | 502 return self.__prices |
491 | 503 |
497 - it must be a list | 509 - it must be a list |
498 - the items must be a list with two items | 510 - the items must be a list with two items |
499 - the first item: price must be a float | 511 - the first item: price must be a float |
500 """ | 512 """ |
501 if not isinstance(prices, list): | 513 if not isinstance(prices, list): |
502 raise TypeError( utils.mapping(_("Prices ($1) must be a list: $2"), | 514 _tuni = _("Prices ($1) must be a list: $2") |
503 (str(prices), str(self.__code))) ) | 515 _uni = utils.mapping(_tuni, (text(prices), self.__code)) |
516 _str = _uni.encode("utf-8") | |
517 raise TypeError(_str) | |
504 for index in range(len(prices)): | 518 for index in range(len(prices)): |
505 _price_date = prices[index] | 519 _price_date = prices[index] |
506 _price_date = self._validate_price_date(_price_date, decimals) | 520 _price_date = self._validate_price_date(_price_date, decimals) |
507 prices[index] = _price_date | 521 prices[index] = _price_date |
508 self.__prices = prices | 522 self.__prices = prices |
518 price_date = self._validate_price_date(price_date, decimals) | 532 price_date = self._validate_price_date(price_date, decimals) |
519 self.__prices.append(price_date) | 533 self.__prices.append(price_date) |
520 | 534 |
521 def _validate_price_date(self, price_date, decimals): | 535 def _validate_price_date(self, price_date, decimals): |
522 if not isinstance(price_date, list) and len(price_date) == 2: | 536 if not isinstance(price_date, list) and len(price_date) == 2: |
523 raise ValueError( utils.mapping(_("Price ($1) must be a list"\ | 537 _tuni = _("Price ($1) must be a list with two items: $2") |
524 " with two items: $2"), (str(price_date), str(self.__code))) ) | 538 _uni = utils.mapping(_tuni, (text(price_date), self.__code)) |
539 _str = _uni.encode("utf-8") | |
540 raise ValueError(_str) | |
525 _price = price_date[0] | 541 _price = price_date[0] |
526 _date = price_date[1] | 542 _date = price_date[1] |
527 if not isinstance(_price, float): | 543 if not isinstance(_price, float): |
528 raise TypeError( utils.mapping(_("Price must be a float "\ | 544 _tuni = ("Price must be a float number: $1") |
529 "number: $1"), (str(_price),)) ) | 545 _uni = utils.mapping(_tuni, (text(_price),)) |
546 _str = _uni.encode("utf-8") | |
547 raise TypeError(_str) | |
530 _D = abs(decimals.getD(self.recordType)) | 548 _D = abs(decimals.getD(self.recordType)) |
531 _price = round(_price, _D) | 549 _price = round(_price, _D) |
532 price_date[0] = _price | 550 price_date[0] = _price |
533 # TODO: validate date | 551 # TODO: validate date |
534 return price_date | 552 return price_date |
535 | 553 |
536 def getPrice(self, index_price): | 554 def getPrice(self, index_price): |
537 if len(self.__prices) <= index_price: | 555 if len(self.__prices) <= index_price: |
538 raise IndexError( _("The record do not have this Price. Code: %s" | 556 _tuni = _("The record do not have this Price. Code: $1") |
539 % self.__code) ) | 557 _uni = utils.mapping(_tuni, (self.__code,)) |
558 _str = _uni.encode("utf-8") | |
559 raise IndexError(_str) | |
540 return self.__prices[index_price][0] | 560 return self.__prices[index_price][0] |
541 | 561 |
542 def getDate(self, index_price): | 562 def getDate(self, index_price): |
543 if len(self.__prices) <= index_price: | 563 if len(self.__prices) <= index_price: |
544 raise IndexError( _("The record do not have this Price") ) | 564 _tuni = _("The record do not have this Price") |
565 _str = _tuni.encode("utf-8") | |
566 raise IndexError(_str) | |
545 return self.__prices[index_price][1] | 567 return self.__prices[index_price][1] |
546 | 568 |
547 def getParents(self): | 569 def getParents(self): |
548 return self.__parents | 570 return self.__parents |
549 | 571 |
550 def setParents(self,parents): | 572 def setParents(self, parents): |
551 """setParents(parents) | 573 """setParents(parents) |
552 | 574 |
553 Sets the list of parents codes of the record. | 575 Sets the list of parents codes of the record. |
554 parents must fulfill | 576 parents must fulfill |
555 - it must be a list | 577 - it must be a list |
556 - the items must be valid codes | 578 - the items must be valid codes |
557 """ | 579 """ |
558 if not isinstance(parents, list): | 580 if not isinstance(parents, list): |
559 raise TypeError( utils.mapping(_("Parents ($1) must be a list: $2"), | 581 _tuni = _("Parents ($1) must be a list: $2") |
560 (str(parents), str(self.__code))) ) | 582 _uni = utils.mapping(_tuni, (text(parents), self.__code)) |
583 _str = _uni.encode("utf-8") | |
584 raise TypeError(_str) | |
561 for parent in parents: | 585 for parent in parents: |
562 if not utils.is_valid_code(parent)[0]: | 586 if not utils.is_valid_code(parent)[0]: |
563 raise ValueError(utils.mapping(_("Invalid parent code ($1) " \ | 587 _tuni = _("Invalid parent code ($1) in the record: $2") |
564 "in the record: $2"), (str(padre), str(self.__code))) ) | 588 _uni = utils.mapping(_tuni, (padre, self.__code)) |
589 _str = _uni.encode("utf-8") | |
590 raise ValueError(_str) | |
565 self.__parents = parents | 591 self.__parents = parents |
566 | 592 |
567 def appendParent(self, parent): | 593 def appendParent(self, parent): |
568 """appendParent(parent) | 594 """appendParent(parent) |
569 | 595 |
570 parent must be a valid code | 596 parent must be a valid code |
571 Append a parent to the list of parents codes of the record. | 597 Append a parent to the list of parents codes of the record. |
572 | 598 |
573 """ | 599 """ |
574 if not utils.is_valid_code(parent)[0]: | 600 if not utils.is_valid_code(parent)[0]: |
575 raise ValueError( utils.mapping(_("Invalid parent code ($1) " \ | 601 _tuni = _("Invalid parent code ($1) in the record: $2") |
576 "in the record: $2"), (str(parent), str(self.__code))) ) | 602 _uni = utils.mapping(_tuni, (parent, self.__code)) |
603 _str = _uni.encode("utf-8") | |
604 raise ValueError(_str) | |
577 self.__parents.append(parent) | 605 self.__parents.append(parent) |
578 | 606 |
579 def getchildren(self): | 607 def getchildren(self): |
580 return self.__children | 608 return self.__children |
581 | 609 |
586 children must fulfill | 614 children must fulfill |
587 - it must be a list | 615 - it must be a list |
588 - the items must be instances of Decomposition class | 616 - the items must be instances of Decomposition class |
589 """ | 617 """ |
590 if not isinstance(children, list): | 618 if not isinstance(children, list): |
591 raise TypeError( utils.mapping(_("children ($1) must be a list, "\ | 619 _tuni = _("children ($1) must be a list, record: $2") |
592 "record: $2"), (str(children), str(self.__code))) ) | 620 _uni = utils.mapping(_tuni, (text(children), self.__code)) |
621 _str = _uni.encode("utf-8") | |
622 raise TypeError(_str) | |
593 for _child in children: | 623 for _child in children: |
594 if not isinstance(_child, Decomposition): | 624 if not isinstance(_child, Decomposition): |
595 raise ValueError( utils.mapping(_("child ($1) must be a "\ | 625 _tuni = _("child ($1) must be a Decomposition object, record: $2") |
596 "Decomposition object, record: $2"), | 626 _uni = utils.mapping(_tuni, (text(_child), self.__code)) |
597 (str(_child), str(self.__code))) ) | 627 _str = _uni.encode("utf-8") |
628 raise ValueError(_str) | |
598 _record_code = self.code | 629 _record_code = self.code |
599 for _measure_list in [_child.budgetMeasures, _child.certification, | 630 for _measure_list in [_child.budgetMeasures, _child.certification, |
600 _child.real_cost, _child.cost_goals, | 631 _child.real_cost, _child.cost_goals, |
601 _child.cost_planned]: | 632 _child.cost_planned]: |
602 if isinstance(_measure_list, list): | 633 if isinstance(_measure_list, list): |
643 """setText(text) | 674 """setText(text) |
644 | 675 |
645 Sets the text of the record | 676 Sets the text of the record |
646 It must be a string | 677 It must be a string |
647 """ | 678 """ |
648 if not isinstance(text, str): | 679 if not isinstance(text, text_type): |
649 raise TypeError( utils.mapping(_("Text ($1) must be a string, "\ | 680 _tuni = _("Text ($1) must be a text string, record: $2") |
650 "record: $2"), (str(text), str(self.__code))) ) | 681 _uni = utils.mapping(_tuni, (text, self.__code)) |
682 _str = _uni.encode("utf-8") | |
683 raise TypeError(_str) | |
651 self.__text = text | 684 self.__text = text |
652 | 685 |
653 def getSheet(self): | 686 def getSheet(self): |
654 return self.__sheet | 687 return self.__sheet |
655 | 688 |
657 """setSheet(sheet) | 690 """setSheet(sheet) |
658 | 691 |
659 Sets the sheet of condition object | 692 Sets the sheet of condition object |
660 """ | 693 """ |
661 if not isinstance(sheet, Sheet): | 694 if not isinstance(sheet, Sheet): |
662 raise ValueError( _("sheet must be a Sheet instance") ) | 695 _tuni = _("sheet must be a Sheet instance") |
696 _str = _tuni.encode("utf-8") | |
697 raise ValueError(_str) | |
663 self.__sheet = sheet | 698 self.__sheet = sheet |
664 | 699 |
665 def getFiles(self): | 700 def getFiles(self): |
666 return self.__files | 701 return self.__files |
667 | 702 |
669 """setFiles(files) | 704 """setFiles(files) |
670 | 705 |
671 Sets the files list | 706 Sets the files list |
672 """ | 707 """ |
673 if not isinstance(files, list): | 708 if not isinstance(files, list): |
674 raise ValueError( utils.mapping(_("files must be a list: $1"), | 709 _tuni = _("files must be a list: $1") |
675 str(files)) ) | 710 _uni = utils.mapping(_tuni, text(files)) |
711 _str = _uni.encode("utf-8") | |
712 raise ValueError(_str) | |
676 _files = [] | 713 _files = [] |
677 for file in files: | 714 for file in files: |
678 if isinstance(file, File): | 715 if isinstance(file, File): |
679 _files.append(file) | 716 _files.append(file) |
680 elif isinstance(file, list): | 717 elif isinstance(file, list): |
681 _file_path = file[0] | 718 _file_path = file[0] |
682 _type = file[1] | 719 _type = file[1] |
683 _description = file[2] | 720 _description = file[2] |
684 if not os.path.exists(file[0]): | 721 if not os.path.exists(file[0]): |
685 raise ValueError( _("Incorrect path") ) | 722 _tuni = _("Incorrect path") |
723 _str = _tuni.encode("utf-8") | |
724 raise ValueError(_str) | |
686 _file = File(file_path, type_, description) | 725 _file = File(file_path, type_, description) |
687 _files.append(_file) | 726 _files.append(_file) |
688 else: | 727 else: |
689 raise ValueError( utils.mapping(_( | 728 _tuni = _("file must be a list or a File object: $1") |
690 "file must be a list or a File object: $1"),str(file)) ) | 729 _uni = utils.mapping(_tuni, file) |
730 _str = _uni.encode("utf-8") | |
731 raise ValueError(_str) | |
691 self.__files = _files | 732 self.__files = _files |
692 | 733 |
693 def addFile(self, file_path, type_, description): | 734 def addFile(self, file_path, type_, description): |
694 """addFile(file_path, type_, description) | 735 """addFile(file_path, type_, description) |
695 | 736 |
696 Add a file to a record instance | 737 Add a file to a record instance |
697 """ | 738 """ |
698 if not os.path.exists(file_path): | 739 if not os.path.exists(file_path): |
699 raise ValueError( _("Incorrect path") ) | 740 _tuni = _("Incorrect path") |
741 _str = _tuni.encode("utf-8") | |
742 raise ValueError(_str) | |
700 _name = os.path.basename(file_path) | 743 _name = os.path.basename(file_path) |
701 _isin = False | 744 _isin = False |
702 for _ofile in self.__files: | 745 for _ofile in self.__files: |
703 if _ofile.name == _name: | 746 if _ofile.name == _name: |
704 _isin = True | 747 _isin = True |
713 """setLabels(labels) | 756 """setLabels(labels) |
714 | 757 |
715 Sets the labels list of a record | 758 Sets the labels list of a record |
716 """ | 759 """ |
717 if not isinstance(labels, list): | 760 if not isinstance(labels, list): |
718 raise ValueError( _("labels must be a list") ) | 761 _tuni = _("labels must be a list") |
762 _str = _tuni.encode("utf-8") | |
763 raise ValueError(_str) | |
719 _labels = [] | 764 _labels = [] |
720 for _label in labels: | 765 for _label in labels: |
721 if isinstance(_label, str): | 766 if isinstance(_label, text_type): |
722 _labels.append(_label) | 767 _labels.append(_label) |
723 else: | 768 else: |
724 raise ValueError( _("label must be a string") ) | 769 _tuni = _("label must be a text string") |
770 _str = _tuni.encode("utf-8") | |
771 raise ValueError(_str) | |
725 self.__labels = _labels | 772 self.__labels = _labels |
726 | 773 |
727 def addLabel(self, label): | 774 def addLabel(self, label): |
728 """addLabel(label) | 775 """addLabel(label) |
729 | 776 |
730 Add a label to a record instance | 777 Add a label to a record instance |
731 """ | 778 """ |
732 if not isinstance(label, str): | 779 if not isinstance(label, text_type): |
733 raise ValueError( _("Label must be a string") ) | 780 _tuni = _("Label must be a text string") |
781 _str = _tuni.encode("utf-8") | |
782 raise ValueError(_str) | |
734 if not label in self.__labels: | 783 if not label in self.__labels: |
735 self.__labels.append(label) | 784 self.__labels.append(label) |
736 | 785 |
737 def getChildPositions(self, child_code): | 786 def getChildPositions(self, child_code): |
738 """getChildPath(child_code): | 787 """getChildPath(child_code): |
976 def getPosition(self): | 1025 def getPosition(self): |
977 return self.__position | 1026 return self.__position |
978 | 1027 |
979 def setPosition(self, position): | 1028 def setPosition(self, position): |
980 if not isinstance(position, int): | 1029 if not isinstance(position, int): |
981 raise ValueError( _("Position must be a integer") ) | 1030 _tuni = _("Position must be a integer") |
1031 _str = _tuni.encode("utf-8") | |
1032 raise ValueError(_str) | |
982 self.__position = position | 1033 self.__position = position |
983 | 1034 |
984 def getCode(self): | 1035 def getCode(self): |
985 return self.__code | 1036 return self.__code |
986 | 1037 |
990 def getBudgetMeasures(self): | 1041 def getBudgetMeasures(self): |
991 return self.__budgetMeasures | 1042 return self.__budgetMeasures |
992 | 1043 |
993 def setBudgetMeasures(self, budgetMeasures): | 1044 def setBudgetMeasures(self, budgetMeasures): |
994 if not isinstance(budgetMeasures, list): | 1045 if not isinstance(budgetMeasures, list): |
995 raise ValueError( _("BudgetMeasures atribute must be a list") ) | 1046 _tuni = _("BudgetMeasures atribute must be a list") |
1047 _str = _tuni.encode("utf-8") | |
1048 raise ValueError(_str) | |
996 for _measure in budgetMeasures: | 1049 for _measure in budgetMeasures: |
997 if not isinstance(_measure, Measure): | 1050 if not isinstance(_measure, Measure): |
998 raise ValueError( _("BudgetMeasures item must be a Measure "/ | 1051 _tuni = _("BudgetMeasures item must be a Measure object") |
999 "object") ) | 1052 _str = _tuni.encode("utf-8") |
1053 raise ValueError(_str) | |
1000 self.__budgetMeasures = budgetMeasures | 1054 self.__budgetMeasures = budgetMeasures |
1001 | 1055 |
1002 def getCertification(self): | 1056 def getCertification(self): |
1003 return self.__certification | 1057 return self.__certification |
1004 | 1058 |
1005 def setCertification(self, certification): | 1059 def setCertification(self, certification): |
1006 if not (certification is None or isinstance(certification, list)): | 1060 if not (certification is None or isinstance(certification, list)): |
1007 raise ValueError(_("Certification atribute must be a list or None")) | 1061 _tuni = _("Certification atribute must be a list or None") |
1062 _str = _tuni.encode("utf-8") | |
1063 raise ValueError(_str) | |
1008 self.__certification = certification | 1064 self.__certification = certification |
1009 | 1065 |
1010 def getRealCost(self): | 1066 def getRealCost(self): |
1011 return self.__real_cost | 1067 return self.__real_cost |
1012 | 1068 |
1013 def setRealCost(self, real_cost): | 1069 def setRealCost(self, real_cost): |
1014 if not (real_cost is None or isinstance(real_cost, list)): | 1070 if not (real_cost is None or isinstance(real_cost, list)): |
1015 raise ValueError( _("Real cost atribute must be a list or None") ) | 1071 _tuni =_("Real cost atribute must be a list or None") |
1072 _str = _tuni.encode("utf-8") | |
1073 raise ValueError(_str) | |
1016 self.__real_cost = real_cost | 1074 self.__real_cost = real_cost |
1017 | 1075 |
1018 def getCostGoals(self): | 1076 def getCostGoals(self): |
1019 return self.__cost_goals | 1077 return self.__cost_goals |
1020 | 1078 |
1021 def setCostGoals(self, cost_goals): | 1079 def setCostGoals(self, cost_goals): |
1022 if not (cost_goals is None or isinstance(cost_goals, list)): | 1080 if not (cost_goals is None or isinstance(cost_goals, list)): |
1023 raise ValueError( _("Cost goals atribute must be a list or None") ) | 1081 _tuni = _("Cost goals atribute must be a list or None") |
1082 _str = _tuni.encode("utf-8") | |
1083 raise ValueError(_str) | |
1024 self.__cost_goals = cost_goals | 1084 self.__cost_goals = cost_goals |
1025 | 1085 |
1026 def getCostPlanned(self): | 1086 def getCostPlanned(self): |
1027 return self.__cost_planned | 1087 return self.__cost_planned |
1028 | 1088 |
1029 def setCostPlanned(self, cost_planned): | 1089 def setCostPlanned(self, cost_planned): |
1030 if not (cost_planned is None or isinstance(cost_planned, list)): | 1090 if not (cost_planned is None or isinstance(cost_planned, list)): |
1031 raise ValueError(_("Cost Planned atribute must be a list or None")) | 1091 _tuni = _("Cost Planned atribute must be a list or None") |
1092 _str = _tuni.encode("utf-8") | |
1093 raise ValueError(_str) | |
1032 self.__cost_planned = cost_planned | 1094 self.__cost_planned = cost_planned |
1033 | 1095 |
1034 position = property(getPosition, setPosition, None, | 1096 position = property(getPosition, setPosition, None, |
1035 """Postion of the record in the budget | 1097 """Postion of the record in the budget |
1036 """) | 1098 """) |
1119 def getMeasure(self): | 1181 def getMeasure(self): |
1120 return self.__measure | 1182 return self.__measure |
1121 | 1183 |
1122 def setMeasure(self, measure, decimals): | 1184 def setMeasure(self, measure, decimals): |
1123 if not isinstance(measure, float): | 1185 if not isinstance(measure, float): |
1124 raise ValueError( utils.mapping(_("Measure must be a float "\ | 1186 _tuni = _("Measure must be a float number. Type: $1") |
1125 "number. Type: $1"), (type(measure),)) ) | 1187 _uni = utils.mapping(_tuni, (type(measure),)) |
1188 _str = _uni.encode("utf-8") | |
1189 raise ValueError(_str) | |
1126 # TODO: test after | 1190 # TODO: test after |
1127 _DS = abs(decimals.DS) | 1191 _DS = abs(decimals.DS) |
1128 measure = round(measure, _DS) | 1192 measure = round(measure, _DS) |
1129 self.__measure = measure | 1193 self.__measure = measure |
1130 | 1194 |
1131 def getLines(self): | 1195 def getLines(self): |
1132 return self.__lines | 1196 return self.__lines |
1133 | 1197 |
1134 def setLines(self, lines): | 1198 def setLines(self, lines): |
1135 if not isinstance(lines, list): | 1199 if not isinstance(lines, list): |
1136 raise ValueError( _("Lines must be a list") ) | 1200 _tuni = _("Lines must be a list") |
1201 _str = _tuni.encode("utf-8") | |
1202 raise ValueError(_str) | |
1137 for _line in lines: | 1203 for _line in lines: |
1138 if not isinstance(_line, MeasureLine): | 1204 if not isinstance(_line, MeasureLine): |
1139 raise ValueError( _("Line must be a MeasureLine objetc") ) | 1205 _tuni = _("Line must be a MeasureLine objetc") |
1206 _str = _tuni.encode("utf-8") | |
1207 raise ValueError(_str) | |
1140 self.__lines = lines | 1208 self.__lines = lines |
1141 | 1209 |
1142 def getLabel(self): | 1210 def getLabel(self): |
1143 return self.__label | 1211 return self.__label |
1144 | 1212 |
1145 def setLabel(self, label): | 1213 def setLabel(self, label): |
1146 self.__label = label | 1214 self.__label = label |
1147 | 1215 |
1148 def setFactor(self, factor, decimals, recordType): | 1216 def setFactor(self, factor, decimals, recordType): |
1149 if not isinstance(factor, float): | 1217 if not isinstance(factor, float): |
1150 raise ValueError( utils.mapping(_("Factor must be a float number "\ | 1218 _tuni = _("Factor must be a float number |$1|") |
1151 "|$1|"), (str(factor),)) ) | 1219 _uni = utils.mapping(_tuni, (text(factor),)) |
1220 _str = _uni.encode("utf-8") | |
1221 raise ValueError(_str) | |
1152 # TODO: test after | 1222 # TODO: test after |
1153 _DF = abs(decimals.getDF(recordType)) | 1223 _DF = abs(decimals.getDF(recordType)) |
1154 factor = round(factor, _DF) | 1224 factor = round(factor, _DF) |
1155 self.__factor = factor | 1225 self.__factor = factor |
1156 | 1226 |
1157 def getFactor(self): | 1227 def getFactor(self): |
1158 return self.__factor | 1228 return self.__factor |
1159 | 1229 |
1160 def setYield(self, yield_, decimals, recordType): | 1230 def setYield(self, yield_, decimals, recordType): |
1161 if not isinstance(yield_, float): | 1231 if not isinstance(yield_, float): |
1162 raise ValueError( _("Yield must be a float number") ) | 1232 _tuni = _("Yield must be a float number") |
1233 _str = _tuni.encode("utf-8") | |
1234 raise ValueError(_str) | |
1163 # TODO: test after | 1235 # TODO: test after |
1164 _DR = abs(decimals.getDR(recordType)) | 1236 _DR = abs(decimals.getDR(recordType)) |
1165 yield_ = round(yield_, _DR) | 1237 yield_ = round(yield_, _DR) |
1166 self.__yield_ = yield_ | 1238 self.__yield_ = yield_ |
1167 | 1239 |
1168 def getYield(self): | 1240 def getYield(self): |
1169 return self.__yield_ | 1241 return self.__yield_ |
1170 | 1242 |
1171 def setFixed(self, fixed, decimals): | 1243 def setFixed(self, fixed, decimals): |
1172 if not isinstance(fixed, bool): | 1244 if not isinstance(fixed, bool): |
1173 raise ValueError( _("Fixed must be boolean object") ) | 1245 _tuni = _("Fixed must be boolean object") |
1246 _str = _tuni.encode("utf-8") | |
1247 raise ValueError(_str) | |
1174 self.__fixed = fixed | 1248 self.__fixed = fixed |
1175 self.updateYield(decimals) | 1249 self.updateYield(decimals) |
1176 | 1250 |
1177 def getFixed(self): | 1251 def getFixed(self): |
1178 return self.__fixed | 1252 return self.__fixed |
1238 if type_ == "M": | 1312 if type_ == "M": |
1239 self.lines = _lines | 1313 self.lines = _lines |
1240 elif type_ == "A": | 1314 elif type_ == "A": |
1241 self.lines.extend(_lines) | 1315 self.lines.extend(_lines) |
1242 else: | 1316 else: |
1243 raise ValueError( utils.mapping(_("Type must be M or A. Type: $1"), | 1317 _tuni = _("Type must be M or A. Type: $1") |
1244 (str(type_),)) ) | 1318 _uni = utils.mapping(_tuni, (type_,)) |
1319 _str = _uni.encode("utf-8") | |
1320 raise ValueError(_str) | |
1245 self.calculateMeasure(decimals, recordType) | 1321 self.calculateMeasure(decimals, recordType) |
1246 | 1322 |
1247 def calculateMeasure(self, decimals, recordType): | 1323 def calculateMeasure(self, decimals, recordType): |
1248 #TODO: round acumulated_subtotal and parcial_subtotal | 1324 #TODO: round acumulated_subtotal and parcial_subtotal |
1249 if len(self.lines) > 0: | 1325 if len(self.lines) > 0: |
1382 def getAcumulatedSubtotal(self): | 1458 def getAcumulatedSubtotal(self): |
1383 return self.__acumulated_subtotal | 1459 return self.__acumulated_subtotal |
1384 | 1460 |
1385 def setParcialSubtotal(self, parcial_subtotal, decimals): | 1461 def setParcialSubtotal(self, parcial_subtotal, decimals): |
1386 if not isinstance(parcial_subtotal, float): | 1462 if not isinstance(parcial_subtotal, float): |
1387 raise ValueError( utils.mapping(_(" Parcial Subtotal must be a "\ | 1463 _tuni = _("Parcial Subtotal must be a float number. Parcial: $1") |
1388 "float number. Parcial: $1"), (str(parcial_subtotal),)) ) | 1464 _uni = utils.mapping(_tuni, (text(parcial_subtotal),)) |
1465 _str = _uni.encode("utf-8") | |
1466 raise ValueError(_str) | |
1389 _DS = abs(decimals.DS) | 1467 _DS = abs(decimals.DS) |
1390 parcial_subtotal = round(parcial_subtotal, _DS) | 1468 parcial_subtotal = round(parcial_subtotal, _DS) |
1391 self.__parcial_subtotal = parcial_subtotal | 1469 self.__parcial_subtotal = parcial_subtotal |
1392 | 1470 |
1393 def setAcumulatedSubtotal(self, acumulated_subtotal, decimals): | 1471 def setAcumulatedSubtotal(self, acumulated_subtotal, decimals): |
1394 if not isinstance(acumulated_subtotal, float): | 1472 if not isinstance(acumulated_subtotal, float): |
1395 raise ValueError( utils.mapping(_(" Acumulated Subtotal must be "\ | 1473 _tuni = _("Acumulated Subtotal must be a float number. Parcial: $1") |
1396 "a float number. Parcial: $1"), | 1474 _uni = utils.mapping(_tuni, (text(acumulated_subtotal),)) |
1397 (str(acumulated_subtotal),)) ) | 1475 _str = _uni.encode("utf-8") |
1476 raise ValueError(_str) | |
1398 _DS = abs(decimals.DS) | 1477 _DS = abs(decimals.DS) |
1399 acumulated_subtotal = round(acumulated_subtotal, _DS) | 1478 acumulated_subtotal = round(acumulated_subtotal, _DS) |
1400 self.__acumulated_subtotal = acumulated_subtotal | 1479 self.__acumulated_subtotal = acumulated_subtotal |
1401 | 1480 |
1402 def calculateParcial(self, decimals): | 1481 def calculateParcial(self, decimals): |
1426 _parcial = round(_parcial, _DS) | 1505 _parcial = round(_parcial, _DS) |
1427 self.__parcial = _parcial | 1506 self.__parcial = _parcial |
1428 | 1507 |
1429 def setLineType(self, type_): | 1508 def setLineType(self, type_): |
1430 if not type_ in [0, 1, 2, 3]: | 1509 if not type_ in [0, 1, 2, 3]: |
1431 raise ValueError( utils.mapping(_("Invalid measure line type ($1)"), | 1510 _tuni = _("Invalid measure line type ($1)") |
1432 (str(type_),)) ) | 1511 _uni = utils.mapping(_tuni, (type_,)) |
1512 _str = _uni.encode("utf-8") | |
1513 raise ValueError(_str) | |
1433 self.__lineType = type_ | 1514 self.__lineType = type_ |
1434 | 1515 |
1435 def setComment(self, comment): | 1516 def setComment(self, comment): |
1436 if not isinstance(comment, str): | 1517 if not isinstance(comment, text_type): |
1437 raise ValueError( utils.mapping(_("Measure Comment must be a "\ | 1518 _tuni = ("Measure Comment must be a text string ($1)") |
1438 "string ($1)"), (str(comment),)) ) | 1519 _uni = utils.mapping(_tuni, (comment,)) |
1520 _str = _uni.encode("utf-8") | |
1521 raise ValueError(_str) | |
1439 self.__comment = comment | 1522 self.__comment = comment |
1440 | 1523 |
1441 def setUnits(self, units, decimals): | 1524 def setUnits(self, units, decimals): |
1442 if units != "": | 1525 if units != "": |
1443 if not isinstance(units, float): | 1526 if not isinstance(units, float): |
1444 raise ValueError( utils.mapping(_("Invalid Measure Units ($1)"), | 1527 _tuni = _("Invalid Measure Units ($1)") |
1445 (str(units),)) ) | 1528 _uni = utils.mapping(_tuni, (text(units),)) |
1529 _str = _uni.encode("utf-8") | |
1530 raise ValueError(_str) | |
1446 _DN = abs(decimals.DN) | 1531 _DN = abs(decimals.DN) |
1447 units = round(units, _DN) | 1532 units = round(units, _DN) |
1448 self.__units = units | 1533 self.__units = units |
1449 try: | 1534 try: |
1450 self.calculateParcial(decimals) | 1535 self.calculateParcial(decimals) |
1452 pass | 1537 pass |
1453 | 1538 |
1454 def setLength(self, length, decimals): | 1539 def setLength(self, length, decimals): |
1455 if length != "": | 1540 if length != "": |
1456 if not isinstance(length, float): | 1541 if not isinstance(length, float): |
1457 raise ValueError( utils.mapping(_("Invalid Measure length ($1)"), | 1542 _tuni = _("Invalid Measure length ($1)") |
1458 (str(units),)) ) | 1543 _uni = utils.mapping(_tuni, (text(length),)) |
1544 _str = _uni.encode("utf-8") | |
1545 raise ValueError(_str) | |
1459 _DD = abs(decimals.DD) | 1546 _DD = abs(decimals.DD) |
1460 length = round(length, _DD) | 1547 length = round(length, _DD) |
1461 self.__length = length | 1548 self.__length = length |
1462 try: | 1549 try: |
1463 self.calculateParcial(decimals) | 1550 self.calculateParcial(decimals) |
1465 pass | 1552 pass |
1466 | 1553 |
1467 def setWidth(self, width, decimals): | 1554 def setWidth(self, width, decimals): |
1468 if width != "": | 1555 if width != "": |
1469 if not isinstance(width, float): | 1556 if not isinstance(width, float): |
1470 raise ValueError( utils.mapping(_("Invalid Measure Width ($1)"), | 1557 _tuni = _("Invalid Measure Width ($1)") |
1471 (str(units),)) ) | 1558 _uni = utils.mapping(_tuni, (text(units),)) |
1559 _str = _uni.encode("utf-8") | |
1560 raise ValueError(_str) | |
1472 _DD = abs(decimals.DD) | 1561 _DD = abs(decimals.DD) |
1473 width = round(width, _DD) | 1562 width = round(width, _DD) |
1474 self.__width = width | 1563 self.__width = width |
1475 try: | 1564 try: |
1476 self.calculateParcial(decimals) | 1565 self.calculateParcial(decimals) |
1478 pass | 1567 pass |
1479 | 1568 |
1480 def setHeight(self, height, decimals): | 1569 def setHeight(self, height, decimals): |
1481 if height != "": | 1570 if height != "": |
1482 if not isinstance(height, float): | 1571 if not isinstance(height, float): |
1483 raise ValueError( utils.mapping(_("Invalid Measure Height ($1)"), | 1572 _tuni = _("Invalid Measure Height ($1)") |
1484 (str(height),)) ) | 1573 _uni = utils.mapping(_tuni, (text(height),)) |
1574 _str = _uni.encode("utf-8") | |
1575 raise ValueError(_str) | |
1485 _DD = abs(decimals.DD) | 1576 _DD = abs(decimals.DD) |
1486 height = round(height, _DD) | 1577 height = round(height, _DD) |
1487 self.__height = height | 1578 self.__height = height |
1488 try: | 1579 try: |
1489 self.calculateParcial(decimals) | 1580 self.calculateParcial(decimals) |
1490 except AttributeError: | 1581 except AttributeError: |
1491 pass | 1582 pass |
1492 | 1583 |
1493 def setFormula(self, formula, decimals): | 1584 def setFormula(self, formula, decimals): |
1494 if not isinstance(formula, str): | 1585 if not isinstance(formula, text_type): |
1495 raise ValueError( utils.mapping(_("Formula must be a "\ | 1586 _tuni = _("Formula must be a text string ($1)") |
1496 "string ($1)"), (str(formula),)) ) | 1587 _uni = utils.mapping(_tuni, (formula,)) |
1588 _str = _uni.encode("utf-8") | |
1589 raise ValueError(_str) | |
1497 if re.match(".*[^0123456789\.()\+\-\*/\^abcdp ].*", formula): | 1590 if re.match(".*[^0123456789\.()\+\-\*/\^abcdp ].*", formula): |
1498 raise ValueError( utils.mapping(_("There is invalid characters"\ | 1591 _tuni = _("There is invalid characters in formula ($1)") |
1499 "in formula ($1)"), (str(formula),)) ) | 1592 _uni = utils.mapping(_tuni, (formula,)) |
1593 _str = _uni.encode("utf-8") | |
1594 raise ValueError(_str) | |
1500 self.__formula = formula | 1595 self.__formula = formula |
1501 try: | 1596 try: |
1502 self.calculateParcial(decimals) | 1597 self.calculateParcial(decimals) |
1503 except AttributeError: | 1598 except AttributeError: |
1504 pass | 1599 pass |
1559 if c == "": c = 0.0 | 1654 if c == "": c = 0.0 |
1560 if d == "": d = 0.0 | 1655 if d == "": d = 0.0 |
1561 try: | 1656 try: |
1562 a = float(a) | 1657 a = float(a) |
1563 except: | 1658 except: |
1564 raise ValueError( _("'a' value must be a float number") ) | 1659 _tuni = _("'a' value must be a float number") |
1660 _str = _tuni.encode("utf-8") | |
1661 raise ValueError(_str) | |
1565 try: | 1662 try: |
1566 b = float(b) | 1663 b = float(b) |
1567 except: | 1664 except: |
1568 raise ValueError( _("'b' value must be a float number") ) | 1665 _tuni = _("'b' value must be a float number") |
1666 _str = _tuni.encode("utf-8") | |
1667 raise ValueError(_str) | |
1569 try: | 1668 try: |
1570 c = float(c) | 1669 c = float(c) |
1571 except: | 1670 except: |
1572 raise ValueError( _("'c' value must be a float number") ) | 1671 _tuni = _("'c' value must be a float number") |
1672 _str = _tuni.encode("utf-8") | |
1673 raise ValueError(_str) | |
1573 try: | 1674 try: |
1574 d = float(d) | 1675 d = float(d) |
1575 except: | 1676 except: |
1576 raise ValueError( _("'d' value must be a float number") ) | 1677 _tuni = _("'d' value must be a float number") |
1678 _str = _tuni.encode("utf-8") | |
1679 raise ValueError(_str) | |
1577 # spaces are erased | 1680 # spaces are erased |
1578 formula.replace(" ","") | 1681 formula.replace(" ","") |
1579 # operators and varibles are replaced | 1682 # operators and varibles are replaced |
1580 formula = formula.replace("+", " + ") | 1683 formula = formula.replace("+", " + ") |
1581 formula = formula.replace("-", " - ") | 1684 formula = formula.replace("-", " - ") |
1582 formula = formula.replace("*", " * ") | 1685 formula = formula.replace("*", " * ") |
1583 formula = formula.replace("/", " / ") | 1686 formula = formula.replace("/", " / ") |
1584 formula = formula.replace("^", " ** ") | 1687 formula = formula.replace("^", " ** ") |
1585 formula = formula.replace("(", " ( ") | 1688 formula = formula.replace("(", " ( ") |
1586 formula = formula.replace(")", " ) ") | 1689 formula = formula.replace(")", " ) ") |
1587 formula = formula.replace("a", str(a)) | 1690 formula = formula.replace("a", text(a)) |
1588 formula = formula.replace("b", str(b)) | 1691 formula = formula.replace("b", text(b)) |
1589 formula = formula.replace("c", str(c)) | 1692 formula = formula.replace("c", text(c)) |
1590 formula = formula.replace("d", str(d)) | 1693 formula = formula.replace("d", text(d)) |
1591 formula = formula.replace("p", "3.1415926") | 1694 formula = formula.replace("p", "3.1415926") |
1592 _list_formula = formula.split(" ") | 1695 _list_formula = formula.split(" ") |
1593 _formula2 = "" | 1696 _formula2 = "" |
1594 for oper in _list_formula: | 1697 for oper in _list_formula: |
1595 try: | 1698 try: |
1596 _float_oper= str(float(oper)) | 1699 _float_oper= text(float(oper)) |
1597 _formula2 = _formula2 + _float_oper | 1700 _formula2 = _formula2 + _float_oper |
1598 except ValueError: | 1701 except ValueError: |
1599 _formula2 = _formula2 + oper | 1702 _formula2 = _formula2 + oper |
1600 _g ={"__builtins__":{}} | 1703 _g ={"__builtins__":{}} |
1601 try: | 1704 try: |
1602 return eval(_formula2, _g) | 1705 return eval(_formula2, _g) |
1603 except: | 1706 except: |
1604 raise ValueError( _("Invalid formula") ) | 1707 _tuni = _("Invalid formula") |
1708 _str = _tuni.encode("utf-8") | |
1709 raise ValueError(_str) | |
1605 | 1710 |
1606 | 1711 |
1607 class Decimals(object): | 1712 class Decimals(object): |
1608 """base.Decimals: | 1713 """base.Decimals: |
1609 | 1714 |
1853 def getSheet_dict(self): | 1958 def getSheet_dict(self): |
1854 return self.__sheet_dict | 1959 return self.__sheet_dict |
1855 | 1960 |
1856 def setSheet_dict(self, sheet_dict): | 1961 def setSheet_dict(self, sheet_dict): |
1857 if not isinstance(sheet_dict, dict): | 1962 if not isinstance(sheet_dict, dict): |
1858 raise ValueError( _("sheet_dict must be a dictionay") ) | 1963 _tuni = _("sheet_dict must be a dictionay") |
1964 _str = _tuni.encode("utf-8") | |
1965 raise ValueError(_str) | |
1859 self.__sheet_dict = sheet_dict | 1966 self.__sheet_dict = sheet_dict |
1860 | 1967 |
1861 def getFields(self): | 1968 def getFields(self): |
1862 return self.sheet_dict.keys() | 1969 return self.sheet_dict.keys() |
1863 | 1970 |
1873 return self.__sheet_dict[field][section] | 1980 return self.__sheet_dict[field][section] |
1874 else: | 1981 else: |
1875 return None | 1982 return None |
1876 | 1983 |
1877 def addField(self, field, section_dict): | 1984 def addField(self, field, section_dict): |
1878 if not isinstance(field, str): | 1985 if not isinstance(field, text_type): |
1879 raise ValueError( _("sheet field must be a string") ) | 1986 _tuni = _("sheet field must be a text string") |
1987 _str = _tuni.encode("utf-8") | |
1988 raise ValueError(_str) | |
1880 if not isinstance(section_dict, dict): | 1989 if not isinstance(section_dict, dict): |
1881 raise ValueError( _("section_dict must be a dictionary") ) | 1990 _tuni = _("section_dict must be a dictionary") |
1991 _str = _tuni.encode("utf-8") | |
1992 raise ValueError(_str) | |
1882 self.__sheet_dict[field] = section_dict | 1993 self.__sheet_dict[field] = section_dict |
1883 | 1994 |
1884 def addSection(self, field, section, paragraph): | 1995 def addSection(self, field, section, paragraph): |
1885 if not isinstance(field, str): | 1996 if not isinstance(field, text_type): |
1886 raise ValueError( _("sheet field must be a string") ) | 1997 _tuni = _("sheet field must be a text string") |
1887 if not isinstance(section, str): | 1998 _str = _tuni.encode("utf-8") |
1888 raise ValueError( _("sheet section must be a string") ) | 1999 raise ValueError(_str) |
1889 if not isinstance(paragraph, str): | 2000 if not isinstance(section, text_type): |
1890 raise ValueError( _("sheet paragraph must be a string") ) | 2001 _tuni = _("sheet section must be a text string") |
2002 _str = _tuni.encode("utf-8") | |
2003 raise ValueError(_str) | |
2004 if not isinstance(paragraph, text_type): | |
2005 _tuni = _("sheet paragraph must be a text string") | |
2006 _str = _tuni.encode("utf-8") | |
2007 raise ValueError(_str) | |
1891 if not field in self.__sheet_dict: | 2008 if not field in self.__sheet_dict: |
1892 self.addField(field, { }) | 2009 self.addField(field, { }) |
1893 _field = self.__sheet_dict[field] | 2010 _field = self.__sheet_dict[field] |
1894 _field[section] = paragraph | 2011 _field[section] = paragraph |
1895 | 2012 |
2170 """setOwner(self, owner) | 2287 """setOwner(self, owner) |
2171 | 2288 |
2172 owner: data owner | 2289 owner: data owner |
2173 Set the data owner. | 2290 Set the data owner. |
2174 """ | 2291 """ |
2175 if isinstance(owner, basestring): | 2292 if isinstance(owner, text_type): |
2176 self.__file_owner = owner | 2293 self.__file_owner = owner |
2177 else: | 2294 else: |
2178 raise TypeError( _("Owner must be a string") ) | 2295 _tuni = _("Owner must be a text string") |
2296 _str = _tuni.encode("utf-8") | |
2297 raise TypeError(_str) | |
2179 | 2298 |
2180 def setDate(self, date): | 2299 def setDate(self, date): |
2181 """setOwner(self, date) | 2300 """setOwner(self, date) |
2182 | 2301 |
2183 date (_y, _m, _d) | 2302 date (_y, _m, _d) |
2189 date[2] in range(32): | 2308 date[2] in range(32): |
2190 if date[1] != 0 and date[2] != 0: | 2309 if date[1] != 0 and date[2] != 0: |
2191 datetime.date(*date) | 2310 datetime.date(*date) |
2192 self.__date = date | 2311 self.__date = date |
2193 else: | 2312 else: |
2194 raise TypeError(utils.mapping(_("Invalid Date: $1"),(str(date),))) | 2313 _tuni = _("Invalid Date: $1") |
2314 _uni = utils.mapping(_tuni,(text(date),)) | |
2315 _str = _uni.encode("utf-8") | |
2316 raise TypeError(_str) | |
2195 | 2317 |
2196 def setComment(self, comment): | 2318 def setComment(self, comment): |
2197 """setOwner(self, comment) | 2319 """setOwner(self, comment) |
2198 | 2320 |
2199 comment: text to comment the budged | 2321 comment: text to comment the budged |
2200 Set the comment. | 2322 Set the comment. |
2201 """ | 2323 """ |
2202 if isinstance(comment, basestring): | 2324 if isinstance(comment, text_type): |
2203 self.__comment = comment | 2325 self.__comment = comment |
2204 else: | 2326 else: |
2205 raise TypeError( _("Comment must be a string") ) | 2327 _tuni = _("Comment must be a text string") |
2328 _str = _tuni.encode("utf-8") | |
2329 raise TypeError(_str) | |
2206 | 2330 |
2207 def setBudgeType(self, budget_type): | 2331 def setBudgeType(self, budget_type): |
2208 """setOwner(self, budget_type) | 2332 """setOwner(self, budget_type) |
2209 | 2333 |
2210 budget_type: type of data in budget | 2334 budget_type: type of data in budget |
2216 Set the budget type. | 2340 Set the budget type. |
2217 """ | 2341 """ |
2218 if budget_type in [1, 2, 3, 4]: | 2342 if budget_type in [1, 2, 3, 4]: |
2219 self.__budgetType = budget_type | 2343 self.__budgetType = budget_type |
2220 else: | 2344 else: |
2221 raise ValueError( _("Budget type must be 1, 2, 3 or 4.") ) | 2345 _tuni = _("Budget type must be 1, 2, 3 or 4.") |
2346 _str = _tuni.encode("utf-8") | |
2347 raise ValueError(_str) | |
2222 | 2348 |
2223 def setCertificateOrder(self, certificate_order, certificate_date): | 2349 def setCertificateOrder(self, certificate_order, certificate_date): |
2224 """setOwner(self, budget_type) | 2350 """setOwner(self, budget_type) |
2225 | 2351 |
2226 certificate_order: certificate number | 2352 certificate_order: certificate number |
2228 Set the certificate order and date. | 2354 Set the certificate order and date. |
2229 """ | 2355 """ |
2230 if isinstance(certificate_order, int): | 2356 if isinstance(certificate_order, int): |
2231 self.__budgetCerficateOrder = certificate_order | 2357 self.__budgetCerficateOrder = certificate_order |
2232 else: | 2358 else: |
2233 raise ValueError( _("Certificate order must be a integer.") ) | 2359 _tuni = _("Certificate order must be a integer.") |
2360 _str = _tuni.encode("utf-8") | |
2361 raise ValueError(_str) | |
2234 | 2362 |
2235 def setCertificateDater(self, certificate_date): | 2363 def setCertificateDater(self, certificate_date): |
2236 """setCertidicateDate(self, certificate_date) | 2364 """setCertidicateDate(self, certificate_date) |
2237 | 2365 |
2238 Set the certificate date. | 2366 Set the certificate date. |
2243 isinstance(certificate_date[1], int) and \ | 2371 isinstance(certificate_date[1], int) and \ |
2244 isinstance(certificate_date[2], int): | 2372 isinstance(certificate_date[2], int): |
2245 datetime.date(*certificate_date) | 2373 datetime.date(*certificate_date) |
2246 self.__budgetCerficateDate = certificate_date | 2374 self.__budgetCerficateDate = certificate_date |
2247 else: | 2375 else: |
2248 _str = _("Budget certificate Date must be a valid Date.") | 2376 _tuni = _("Budget certificate Date must be a valid Date.") |
2377 _str = _tuni.encode("utf-8") | |
2249 raise ValueError(_str) | 2378 raise ValueError(_str) |
2250 | 2379 |
2251 def setTitleList(self, title_list): | 2380 def setTitleList(self, title_list): |
2252 """setTitleList(self, title_list) | 2381 """setTitleList(self, title_list) |
2253 | 2382 |
2254 title_list: [ "Header", ["Title1", "Title2", ... ] ] | 2383 title_list: [ "Header", ["Title1", "Title2", ... ] ] |
2255 Set the header and titles for the price groups and decimals. | 2384 Set the header and titles for the price groups and decimals. |
2256 """ | 2385 """ |
2257 title_list[0] = str(title_list[0]) | 2386 title_list[0] = text(title_list[0]) |
2258 if isinstance(title_list, list) and isinstance(title_list[1], list): | 2387 if isinstance(title_list, list) and isinstance(title_list[1], list): |
2259 for i in range(len(title_list[1])): | 2388 for i in range(len(title_list[1])): |
2260 title_list[1][i] = str(title_list[1][i]) | 2389 title_list[1][i] = text(title_list[1][i]) |
2261 self.__title_list = title_list | 2390 self.__title_list = title_list |
2262 else: | 2391 else: |
2263 raise TypeError( _("Invalid title list format") ) | 2392 _tuni = _("Invalid title list format") |
2393 _str = _tuni.encode("utf-8") | |
2394 raise TypeError(_str) | |
2264 | 2395 |
2265 def getTitleList(self): | 2396 def getTitleList(self): |
2266 """ getTitleList(self) | 2397 """ getTitleList(self) |
2267 | 2398 |
2268 Returns the header and titles for the price groups and decimals. | 2399 Returns the header and titles for the price groups and decimals. |
2287 _default_decimals = self.__decimals[0] | 2418 _default_decimals = self.__decimals[0] |
2288 self.__decimals.append(_default_decimals) | 2419 self.__decimals.append(_default_decimals) |
2289 elif N < len(self.__decimals): | 2420 elif N < len(self.__decimals): |
2290 _default_decimals = self.__decimals[N] | 2421 _default_decimals = self.__decimals[N] |
2291 else: | 2422 else: |
2292 raise IndexError( _("Invalid Index Title") ) | 2423 _tuni = _("Invalid Index Title") |
2424 _str = _tuni.encode("utf-8") | |
2425 raise IndexError(_str) | |
2293 for _decimal in dictionary: | 2426 for _decimal in dictionary: |
2294 if dictionary[_decimal] == "": | 2427 if dictionary[_decimal] == "": |
2295 dictionary[_decimal] = eval("_default_decimals." + _decimal) | 2428 dictionary[_decimal] = eval("_default_decimals." + _decimal) |
2296 decimals = Decimals(dictionary["DN"], dictionary["DD"], | 2429 decimals = Decimals(dictionary["DN"], dictionary["DD"], |
2297 dictionary["DSP"], dictionary["DS"], | 2430 dictionary["DSP"], dictionary["DS"], |
2362 elif key == "keys": | 2495 elif key == "keys": |
2363 return self.__percentages.keys | 2496 return self.__percentages.keys |
2364 elif key in self.__percentages: | 2497 elif key in self.__percentages: |
2365 return self.__percentages[key] | 2498 return self.__percentages[key] |
2366 else: | 2499 else: |
2367 raise KeyError( _("Invalid Percentage key") ) | 2500 _tuni = _("Invalid Percentage key") |
2501 _str = _tuni.encode("utf-8") | |
2502 raise KeyError(_str) | |
2368 | 2503 |
2369 def getAllParents(self,code): | 2504 def getAllParents(self,code): |
2370 """getAllParents(self,code) | 2505 """getAllParents(self,code) |
2371 | 2506 |
2372 code: a record code. | 2507 code: a record code. |
2433 _decomposition = self.getDecomposition(path) | 2568 _decomposition = self.getDecomposition(path) |
2434 _measure = _decomposition.budgetMeasures[0] | 2569 _measure = _decomposition.budgetMeasures[0] |
2435 return _measure | 2570 return _measure |
2436 | 2571 |
2437 def getStrYield(self, measure, recordType): | 2572 def getStrYield(self, measure, recordType): |
2438 #_DR = measure.getDR(self.getDecimals()) | |
2439 _DR = abs(self.getDecimals().getDR(recordType)) | 2573 _DR = abs(self.getDecimals().getDR(recordType)) |
2440 _yield = ("%." + str(_DR) + "f" ) % measure.yield_ | 2574 _yield = ("%." + text(_DR) + "f" ) % measure.yield_ |
2441 return _yield | 2575 return _yield |
2442 | 2576 |
2443 def getStrFactor(self, measure, recorType): | 2577 def getStrFactor(self, measure, recorType): |
2444 _DF = abs(self.getDecimals().getDF(recordType)) | 2578 _DF = abs(self.getDecimals().getDF(recordType)) |
2445 #_DF = measure.getDF(self.getDecimals()) | 2579 _factor = ("%." + text(_DF) + "f" ) % measure.factor |
2446 _factor = ("%." + str(_DF) + "f" ) % measure.factor | |
2447 return _factor | 2580 return _factor |
2448 | 2581 |
2449 def setTree(self, code, child_code, position, factor, yield_, total, | 2582 def setTree(self, code, child_code, position, factor, yield_, total, |
2450 list_lines, label, type_): | 2583 list_lines, label, type_): |
2451 """setTree(self, code, child_code, position, factor,yield_, total, | 2584 """setTree(self, code, child_code, position, factor,yield_, total, |
2479 Sets the decomposition of a record in a child record | 2612 Sets the decomposition of a record in a child record |
2480 """ | 2613 """ |
2481 if code is None: # No-estructured measures | 2614 if code is None: # No-estructured measures |
2482 code = self.getRoot() | 2615 code = self.getRoot() |
2483 if code == None: # No root | 2616 if code == None: # No root |
2484 print( "No-estructured measures. Adding root record " + | 2617 _record = self.setRecord("root", [], 0, "", "", [0.0,], |
2485 str(self.setRecord("root", [], 0, "", "", [0.0,], [(1,1,1970)], | 2618 [(1,1,1970)], 0, "") |
2486 0, "") ).encode("utf8")) | 2619 _tuni = _("No-estructured measures. Adding root record") |
2620 print(_tuni) | |
2487 code = self.getRoot() | 2621 code = self.getRoot() |
2488 | 2622 |
2489 if not utils.is_valid_code(code)[0]: | 2623 if not utils.is_valid_code(code)[0]: |
2490 raise ValueError( utils.mapping(_("Invalid parent code: $1"), | 2624 _tuni = _("Invalid parent code: $1") |
2491 (str(code),)) ) | 2625 _uni = utils.mapping(_tuni, (code,)) |
2626 _str = _uni.encode("utf-8") | |
2627 raise ValueError(_str) | |
2492 if not utils.is_valid_code(child_code)[0]: | 2628 if not utils.is_valid_code(child_code)[0]: |
2493 raise ValueError( utils.mapping(_("Invalid child code: $1 $2"), | 2629 _tuni = _("Invalid child code: $1 $2") |
2494 (str(code),str(child_code))) ) | 2630 _uni = utils.mapping(_tuni, (code,child_code)) |
2631 _str = _uni.encode("utf-8") | |
2632 raise ValueError(_str) | |
2495 if not isinstance(position, int): | 2633 if not isinstance(position, int): |
2496 raise ValueError( utils.mapping(_("Invalid position in measure "\ | 2634 _tuni = _("Invalid position in measure $1, in code $2 $3") |
2497 "$1, in code $2"), (str(parent_code), str(position))) ) | 2635 _uni = utils.mapping(_tuni, (text(position), code, child_code)) |
2636 _str = _uni.encode("utf-8") | |
2637 raise ValueError(_str) | |
2498 # Test circular references | 2638 # Test circular references |
2499 _all_parent_list = self.getAllParents(code) + [ code ] | 2639 _all_parent_list = self.getAllParents(code) + [ code ] |
2500 _all_child_list = self.getAllchildren(child_code) + [ child_code ] | 2640 _all_child_list = self.getAllchildren(child_code) + [ child_code ] |
2501 for _parent_code in _all_parent_list: | 2641 for _parent_code in _all_parent_list: |
2502 if _parent_code in _all_child_list: | 2642 if _parent_code in _all_child_list: |
2503 # TODO: change return to except | 2643 # TODO: change return to except |
2504 _str = _("Circular Decomposition, parent code: "\ | 2644 _tuni = _("Circular Decomposition, parent code: "\ |
2505 "$1, child code: $2, repeated code: $3") | 2645 "$1, child code: $2, repeated code: $3") |
2506 print(utils.mapping(_str, (str(code), str(child_code), | 2646 _uni = utils.mapping(_tuni, (code, child_code, _parent_code)) |
2507 str(_parent_code))).encode("utf8") ) | 2647 print(_uni) |
2508 return | 2648 return |
2509 | 2649 |
2510 # Creating reference to parent code in child record | 2650 # Creating reference to parent code in child record |
2511 if child_code in self.__records: | 2651 if child_code in self.__records: |
2512 _child_record = self.__records[child_code] | 2652 _child_record = self.__records[child_code] |
2526 # No-estructured measures or empty position (error in FIEBDC file) | 2666 # No-estructured measures or empty position (error in FIEBDC file) |
2527 if position == -2: | 2667 if position == -2: |
2528 positions = _record.getChildPositions(child_code) | 2668 positions = _record.getChildPositions(child_code) |
2529 if len(positions) == 1: | 2669 if len(positions) == 1: |
2530 position = positions[0] | 2670 position = positions[0] |
2531 _str = _("No-estructured measure or empty position. " \ | 2671 _tuni = _("No-estructured measure or empty position. " \ |
2532 "Parent Code: $1, Child code: $2, Position: $3") | 2672 "Parent Code: $1, Child code: $2, Position: $3") |
2533 print(utils.mapping(_str,(str(code), str(child_code), | 2673 _uni = utils.mapping(_tuni,(code, child_code, |
2534 str(position))).encode("utf8") ) | 2674 text(position))) |
2675 print(_uni) | |
2535 else: | 2676 else: |
2536 position = _child_number | 2677 position = _child_number |
2537 _str = _("No-estructured measure or empty position. "\ | 2678 _tuni = _("No-estructured measure or empty position. "\ |
2538 "Repeated child in unspecified position. "\ | 2679 "Repeated child in unspecified position. "\ |
2539 "It is impossible to determine the position. "\ | 2680 "It is impossible to determine the position. "\ |
2540 "New child is added in the decomposition. "\ | 2681 "New child is added in the decomposition. "\ |
2541 "Parent code: $1, Child code: $2, Position: $3") | 2682 "Parent code: $1, Child code: $2, Position: $3") |
2542 print(utils.mapping(_str,(str(code), str(child_code), | 2683 _uni = utils.mapping(_tuni,(code, child_code, |
2543 str(position))).encode("utf8") ) | 2684 text(position))) |
2685 print(_uni) | |
2544 if position == _child_number: | 2686 if position == _child_number: |
2545 # The record do not have the child | 2687 # The record do not have the child |
2546 if not isinstance(factor, float): factor = 1.0 | 2688 if not isinstance(factor, float): factor = 1.0 |
2547 if not isinstance(yield_, float): yield_ = 1.0 | 2689 if not isinstance(yield_, float): yield_ = 1.0 |
2548 if not isinstance(total, float): total = 0.0 | 2690 if not isinstance(total, float): total = 0.0 |
2570 yield_ = 0.0 | 2712 yield_ = 0.0 |
2571 _measure.setMeasure(total, self.getDecimals()) | 2713 _measure.setMeasure(total, self.getDecimals()) |
2572 if isinstance(list_lines, list) and len(list_lines) > 0: | 2714 if isinstance(list_lines, list) and len(list_lines) > 0: |
2573 _measure.buildMeasure(list_lines, type_, self.getDecimals(), | 2715 _measure.buildMeasure(list_lines, type_, self.getDecimals(), |
2574 _record.recordType) | 2716 _record.recordType) |
2575 if isinstance(label, str) and label != "" : | 2717 if isinstance(label, text_type) and label != "" : |
2576 _measure.label = label | 2718 _measure.label = label |
2577 else: | 2719 else: |
2578 # TODO: change return for except | 2720 # TODO: change return for except |
2579 _str = _("Error: Invalid child position in " | 2721 _tuni = _("Error: Invalid child position in " |
2580 "decomposition. Parent code: $1 Child code: $2 "\ | 2722 "decomposition. Parent code: $1 Child code: $2 "\ |
2581 "Position: $3") | 2723 "Position: $3") |
2582 print(utils.mapping(_str, (str(code), str(child_code), | 2724 _uni = utils.mapping(_tuni, (code, child_code, |
2583 str(position))).encode("utf8") ) | 2725 text(position))) |
2726 print(_uni) | |
2584 return | 2727 return |
2585 else: | 2728 else: |
2586 if child_code == "" : | 2729 if child_code == "" : |
2587 _str = _("Error: Empty child code. Parent code: "\ | 2730 _tuni = _("Error: Empty child code. Parent code: "\ |
2588 "$1 Position: $2") | 2731 "$1 Position: $2") |
2589 print(utils.mapping(_str, (str(code), | 2732 _uni = utils.mapping(_tuni, (code, text(position))) |
2590 str(position))).encode("utf8") ) | 2733 print(_uni) |
2591 return | 2734 return |
2592 if position == -1: | 2735 if position == -1: |
2593 position = 0 | 2736 position = 0 |
2594 elif position != 0: | 2737 elif position != 0: |
2595 _str = _("Error: Invalid child position in "\ | 2738 _tuni = _("Error: Invalid child position in "\ |
2596 "decomposition. Parent code: $1 Child code: $2 "\ | 2739 "decomposition. Parent code: $1 Child code: $2 "\ |
2597 "Position: $3") | 2740 "Position: $3") |
2598 print(utils.mapping(_str, (str(code), str(child_code), | 2741 _uni = utils.mapping(_tuni, (code, child_code, |
2599 str(position))).encode("utf8") ) | 2742 text(position))) |
2743 print(_uni) | |
2600 return | 2744 return |
2601 if not isinstance(factor, float): | 2745 if not isinstance(factor, float): |
2602 factor = 1.0 | 2746 factor = 1.0 |
2603 if not isinstance(yield_, float): | 2747 if not isinstance(yield_, float): |
2604 yield_ = 1.0 | 2748 yield_ = 1.0 |
2627 if c == "": c = 0.0 | 2771 if c == "": c = 0.0 |
2628 if d == "": d = 0.0 | 2772 if d == "": d = 0.0 |
2629 try: | 2773 try: |
2630 a = float(a) | 2774 a = float(a) |
2631 except: | 2775 except: |
2632 raise ValueError( _("'a' value must be a float number") ) | 2776 _tuni = _("'a' value must be a float number") |
2777 _str = _tuni.encode("utf-8") | |
2778 raise ValueError(_str) | |
2633 try: | 2779 try: |
2634 b = float(b) | 2780 b = float(b) |
2635 except: | 2781 except: |
2636 raise ValueError( _("'b' value must be a float number") ) | 2782 _tuni = _("'b' value must be a float number") |
2783 _str = _tuni.encode("utf-8") | |
2784 raise ValueError(_str) | |
2637 try: | 2785 try: |
2638 c = float(c) | 2786 c = float(c) |
2639 except: | 2787 except: |
2640 raise ValueError( _("'c' value must be a float number") ) | 2788 _tuni = _("'c' value must be a float number") |
2789 _str = _tuni.encode("utf-8") | |
2790 raise ValueError(_str) | |
2641 try: | 2791 try: |
2642 d = float(d) | 2792 d = float(d) |
2643 except: | 2793 except: |
2644 raise ValueError( _("'d' value must be a float number") ) | 2794 _tuni = _("'d' value must be a float number") |
2795 _str = _tuni.encode("utf-8") | |
2796 raise ValueError(_str) | |
2645 # spaces are erased | 2797 # spaces are erased |
2646 sre.sub("[ ]","",formula) | 2798 sre.sub("[ ]","",formula) |
2647 # operators and varibles are replaced | 2799 # operators and varibles are replaced |
2648 formula = formula.replace("+", " + ") | 2800 formula = formula.replace("+", " + ") |
2649 formula = formula.replace("-", " - ") | 2801 formula = formula.replace("-", " - ") |
2650 formula = formula.replace("*", " * ") | 2802 formula = formula.replace("*", " * ") |
2651 formula = formula.replace("/", " / ") | 2803 formula = formula.replace("/", " / ") |
2652 formula = formula.replace("^", " ** ") | 2804 formula = formula.replace("^", " ** ") |
2653 formula = formula.replace("(", " ( ") | 2805 formula = formula.replace("(", " ( ") |
2654 formula = formula.replace(")", " ) ") | 2806 formula = formula.replace(")", " ) ") |
2655 formula = formula.replace("a", str(a)) | 2807 formula = formula.replace("a", text(a)) |
2656 formula = formula.replace("b", str(b)) | 2808 formula = formula.replace("b", text(b)) |
2657 formula = formula.replace("c", str(c)) | 2809 formula = formula.replace("c", text(c)) |
2658 formula = formula.replace("d", str(d)) | 2810 formula = formula.replace("d", text(d)) |
2659 formula = formula.replace("p", "3.1415926") | 2811 formula = formula.replace("p", "3.1415926") |
2660 _list_formula = formula.split(" ") | 2812 _list_formula = formula.split(" ") |
2661 _formula2 = "" | 2813 _formula2 = "" |
2662 for oper in _list_formula: | 2814 for oper in _list_formula: |
2663 try: | 2815 try: |
2664 _float_oper= str(float(oper)) | 2816 _float_oper= text(float(oper)) |
2665 _formula2 = _formula2 + _float_oper | 2817 _formula2 = _formula2 + _float_oper |
2666 except ValueError: | 2818 except ValueError: |
2667 _formula2 = _formula2 + oper | 2819 _formula2 = _formula2 + oper |
2668 _g = {"__builtins__":{}} | 2820 _g = {"__builtins__":{}} |
2669 try: | 2821 try: |
2670 return eval(_formula2, _g) | 2822 return eval(_formula2, _g) |
2671 except: | 2823 except: |
2672 raise ValueError( _("Invalid formula") ) | 2824 _tuni = _("Invalid formula") |
2825 _str = _tuni.encode("utf-8") | |
2826 raise ValueError(_str) | |
2673 | 2827 |
2674 def getText(self,code): | 2828 def getText(self,code): |
2675 """getText(self,code) | 2829 """getText(self,code) |
2676 | 2830 |
2677 code: the record code | 2831 code: the record code |
2678 Returns the description text of a record | 2832 Returns the description text of a record |
2679 """ | 2833 """ |
2680 if code in self.__records: | 2834 if code in self.__records: |
2681 return self.__records[code].text | 2835 return self.__records[code].text |
2682 else: | 2836 else: |
2683 raise IndexError( _("Invalid code") ) | 2837 _tuni = _("Invalid code") |
2838 _str = _tuni.encode("utf-8") | |
2839 raise IndexError(_str) | |
2684 | 2840 |
2685 def setText(self,code,text): | 2841 def setText(self,code,text): |
2686 """setText(self,code,text) | 2842 """setText(self,code,text) |
2687 | 2843 |
2688 code: the parent record code | 2844 code: the parent record code |
2689 text: the descripion text | 2845 text: the descripion text |
2690 Sests the description text of a record | 2846 Sests the description text of a record |
2691 """ | 2847 """ |
2692 if not utils.is_valid_code(code)[0]: | 2848 if not utils.is_valid_code(code)[0]: |
2693 _str = _("Invalid record: $1") | 2849 _tuni = _("Invalid record: $1") |
2694 raise ValueError( utils.mapping(_str, (str(code),)) ) | 2850 _uni = utils.mapping(_tuni, (code,)) |
2851 _str = _uni.encode("utf-8") | |
2852 raise ValueError(_str) | |
2695 if not code in self.__records: | 2853 if not code in self.__records: |
2696 _record = self.setRecord(code, [], "", "", "", [], [], | 2854 _record = self.setRecord(code, [], "", "", "", [], [], |
2697 "", "") | 2855 "", "") |
2698 _record.text = text | 2856 _record.text = text |
2699 else: | 2857 else: |
2752 if hierarchy == 0 : | 2910 if hierarchy == 0 : |
2753 # is the root record | 2911 # is the root record |
2754 if self.__root is None: | 2912 if self.__root is None: |
2755 self.__root = code | 2913 self.__root = code |
2756 else: | 2914 else: |
2757 print(_("Only can be one root record").encode("utf8") ) | 2915 _tuni = _("Only can be one root record") |
2916 print(_tuni) | |
2758 return | 2917 return |
2759 # TODO: If the root is created in settree. | 2918 # TODO: If the root is created in settree. |
2760 # No-estructured measures | 2919 # No-estructured measures |
2761 # TODO Rewrite root values | 2920 # TODO Rewrite root values |
2762 # retake previous values. | 2921 # retake previous values. |
2843 _amount_sum = _amount_sum + _amount | 3002 _amount_sum = _amount_sum + _amount |
2844 _price = _amount_sum | 3003 _price = _amount_sum |
2845 else: | 3004 else: |
2846 _price = record.getPrice(index_price) | 3005 _price = record.getPrice(index_price) |
2847 _D = abs(self.getDecimals().getD(record.recordType)) | 3006 _D = abs(self.getDecimals().getD(record.recordType)) |
2848 _price = ("%." + str(_D) + "f" ) % _price | 3007 _price = ("%." + text(_D) + "f" ) % _price |
2849 return _price | 3008 return _price |
2850 | 3009 |
2851 def getCode(self, path): | 3010 def getCode(self, path): |
2852 """getCode(self, path) | 3011 """getCode(self, path) |
2853 | 3012 |
2862 _record = self.__records[_code] | 3021 _record = self.__records[_code] |
2863 _children_list = _record.children | 3022 _children_list = _record.children |
2864 try: | 3023 try: |
2865 _child = _children_list[i] | 3024 _child = _children_list[i] |
2866 except: | 3025 except: |
2867 raise ValueError( _("This record does not exits") ) | 3026 _tuni = _("This record does not exits") |
3027 _str = _tuni.encode("utf-8") | |
3028 raise ValueError(_str) | |
2868 _code = _child.code | 3029 _code = _child.code |
2869 else: | 3030 else: |
2870 raise ValueError( _("Path item must be a integer") ) | 3031 _tuni = _("Path item must be a integer") |
3032 _str = _tuni.encode("utf-8") | |
3033 raise ValueError(_str) | |
2871 return _code | 3034 return _code |
2872 else: | 3035 else: |
2873 raise ValueError( _("This record does not exits") ) | 3036 _tuni = _("This record does not exits") |
3037 _str = _tuni.encode("utf-8") | |
3038 raise ValueError(_str) | |
2874 else: | 3039 else: |
2875 raise ValueError( utils.mapping(_("Path must be a not empty "\ | 3040 _tuni = _("Path must be a not empty tuple: $1") |
2876 "tuple: $1"), (str(path),)) ) | 3041 _uni = utils.mapping(_tuni, (text(path),)) |
3042 _str = _uni.encode("utf-8") | |
3043 raise ValueError(_str) | |
2877 | 3044 |
2878 def getAmount(self, path): | 3045 def getAmount(self, path): |
2879 """def getAmount(self,path) | 3046 """def getAmount(self,path) |
2880 | 3047 |
2881 path: record path | 3048 path: record path |
2889 return _amount | 3056 return _amount |
2890 else: | 3057 else: |
2891 _parent_code = self.getCode(path[:-1]) | 3058 _parent_code = self.getCode(path[:-1]) |
2892 _parent_record = self.getRecord(_parent_code) | 3059 _parent_record = self.getRecord(_parent_code) |
2893 _child_number = path[-1] | 3060 _child_number = path[-1] |
2894 | |
2895 _decomposition = _parent_record.children[_child_number] | 3061 _decomposition = _parent_record.children[_child_number] |
2896 _factor = _decomposition.budgetMeasures[0].factor | 3062 _factor = _decomposition.budgetMeasures[0].factor |
2897 _yield = _decomposition.budgetMeasures[0].yield_ | 3063 _yield = _decomposition.budgetMeasures[0].yield_ |
2898 _child_code = _decomposition.code | 3064 _child_code = _decomposition.code |
2899 _child_record = self.getRecord(_child_code) | 3065 _child_record = self.getRecord(_child_code) |
2932 else: | 3098 else: |
2933 _parent_code = self.getCode(path[:-1]) | 3099 _parent_code = self.getCode(path[:-1]) |
2934 _parent_record = self.getRecord(_parent_code) | 3100 _parent_record = self.getRecord(_parent_code) |
2935 _amount = self.getAmount(path) | 3101 _amount = self.getAmount(path) |
2936 _DI = abs(self.getDecimals().getDI(_parent_record.recordType)) | 3102 _DI = abs(self.getDecimals().getDI(_parent_record.recordType)) |
2937 _amount = ("%." + str(_DI) + "f") % _amount | 3103 _amount = ("%." + text(_DI) + "f") % _amount |
2938 return _amount | 3104 return _amount |
2939 | 3105 |
2940 def setSheetSection(self,sheet_code,sheet_title): | 3106 def setSheetSection(self,sheet_code,sheet_title): |
2941 if not isinstance(sheet_code, str): | 3107 if not isinstance(sheet_code, text_type): |
2942 raise ValueError( _("The sheet code must be a string") ) | 3108 _tuni = _("The sheet code must be a text string") |
2943 if not isinstance(sheet_title, str): | 3109 _str = _tuni.encode("utf-8") |
2944 raise ValueError( _("The sheet title must be a string") ) | 3110 raise ValueError(_str) |
3111 if not isinstance(sheet_title, text_type): | |
3112 _tuni = _("The sheet title must be a text string") | |
3113 _str = _tuni.encode("utf-8") | |
3114 raise ValueError(_str) | |
2945 self.__sheet_sections[sheet_code] = sheet_title | 3115 self.__sheet_sections[sheet_code] = sheet_title |
2946 | 3116 |
2947 def hasSheetSection(self, section): | 3117 def hasSheetSection(self, section): |
2948 return section in self.__sheet_sections | 3118 return section in self.__sheet_sections |
2949 | 3119 |
2950 def getSheetSection(self, section): | 3120 def getSheetSection(self, section): |
2951 return self.__sheet_sections[section] | 3121 return self.__sheet_sections[section] |
2952 | 3122 |
2953 def setSheetSections(self,dictionary): | 3123 def setSheetSections(self,dictionary): |
2954 if not isinstance(dictionary, dict): | 3124 if not isinstance(dictionary, dict): |
2955 raise ValueError( _("The sheet sections must be a dictionary") ) | 3125 _tuni = _("The sheet sections must be a dictionary") |
3126 _str = _tuni.encode("utf-8") | |
3127 raise ValueError(_str) | |
2956 for sheet_code in dictionary.keys(): | 3128 for sheet_code in dictionary.keys(): |
2957 self.setSheetSection(sheet_code, dictionary[sheet_code]) | 3129 self.setSheetSection(sheet_code, dictionary[sheet_code]) |
2958 | 3130 |
2959 def setSheetField(self, field_code, field_title): | 3131 def setSheetField(self, field_code, field_title): |
2960 if not isinstance(field_code, str): | 3132 if not isinstance(field_code, text_type): |
2961 raise ValueError( _("The field code must be a string") ) | 3133 _tuni = _("The field code must be a text string") |
2962 if not isinstance(field_title, str): | 3134 _str = _tuni.encode("utf-8") |
2963 raise ValueError( _("The field title must be a string") ) | 3135 raise ValueError(_str) |
3136 if not isinstance(field_title, text_type): | |
3137 _tuni = _("The field title must be a text string") | |
3138 _str = _tuni.encode("utf-8") | |
3139 raise ValueError(_str) | |
2964 self.__sheet_fields[field_code] = field_title | 3140 self.__sheet_fields[field_code] = field_title |
2965 | 3141 |
2966 def hasSheetField(self, field): | 3142 def hasSheetField(self, field): |
2967 return field in self.__sheet_fields | 3143 return field in self.__sheet_fields |
2968 | 3144 |
2969 def getSheetField(self, field): | 3145 def getSheetField(self, field): |
2970 return self.__sheet_fields[field] | 3146 return self.__sheet_fields[field] |
2971 | 3147 |
2972 def setSheetFields(self, field_dict): | 3148 def setSheetFields(self, field_dict): |
2973 if not isinstance(field_dict, dict): | 3149 if not isinstance(field_dict, dict): |
2974 raise ValueError( _("The sheet field must be a dictionary") ) | 3150 _tuni = _("The sheet field must be a dictionary") |
3151 _str = _tuni.encode("utf-8") | |
3152 raise ValueError(_str) | |
2975 for field_code in field_dict.keys(): | 3153 for field_code in field_dict.keys(): |
2976 self.setSheetField( field_code, field_dict[field_code]) | 3154 self.setSheetField( field_code, field_dict[field_code]) |
2977 | 3155 |
2978 def setSheetParagraph(self, paragraph_code, paragraph_text): | 3156 def setSheetParagraph(self, paragraph_code, paragraph_text): |
2979 if not isinstance(paragraph_code, str): | 3157 if not isinstance(paragraph_code, text_type): |
2980 raise ValueError( _("The paragraph code must be a string") ) | 3158 _tuni = _("The paragraph code must be a text string") |
2981 if not isinstance(paragraph_text, str): | 3159 _str = _tuni.encode("utf-8") |
2982 raise ValueError( _("The paragraph text must be a string") ) | 3160 raise ValueError(_str) |
3161 if not isinstance(paragraph_text, text_type): | |
3162 _tuni = _("The paragraph text must be a text string") | |
3163 _str = _tuni.encode("utf-8") | |
3164 raise ValueError(_str) | |
2983 self.__sheet_paragraphs[paragraph_code] = paragraph_text | 3165 self.__sheet_paragraphs[paragraph_code] = paragraph_text |
2984 | 3166 |
2985 def hasSheetParagraph(self, paragraph): | 3167 def hasSheetParagraph(self, paragraph): |
2986 return paragraph in self.__sheet_paragraphs | 3168 return paragraph in self.__sheet_paragraphs |
2987 | 3169 |
2988 def getSheetParagraph(self, paragraph): | 3170 def getSheetParagraph(self, paragraph): |
2989 return self.__sheet_paragraphs[paragraph] | 3171 return self.__sheet_paragraphs[paragraph] |
2990 | 3172 |
2991 def setSheetParagraphs(self, paragraph_dict): | 3173 def setSheetParagraphs(self, paragraph_dict): |
2992 if not isinstance(paragraph_dict, dict): | 3174 if not isinstance(paragraph_dict, dict): |
2993 raise ValueError( _("The paragraph dict must be a dictionary") ) | 3175 _tuni = _("The paragraph dict must be a dictionary") |
3176 _str = _tuni.encode("utf-8") | |
3177 raise ValueError(_str) | |
2994 for paragraph_code in paragraph_dict.keys(): | 3178 for paragraph_code in paragraph_dict.keys(): |
2995 self.setSheetParagraph(paragraph_code, | 3179 self.setSheetParagraph(paragraph_code, |
2996 paragraph_dict[paragraph_code]) | 3180 paragraph_dict[paragraph_code]) |
2997 | 3181 |
2998 def setSheetRecord(self, record_code, field, section_dict): | 3182 def setSheetRecord(self, record_code, field, section_dict): |
2999 if not isinstance(record_code, str): | 3183 if not isinstance(record_code, text_type): |
3000 raise ValueError( _("The record_code code must be a string") ) | 3184 _tuni = _("The record_code code must be a text string") |
3001 if not isinstance(field, str): | 3185 _str = _tuni.encode("utf-8") |
3002 raise ValueError( _("The field must be a string") ) | 3186 raise ValueError(_str) |
3187 if not isinstance(field, text_type): | |
3188 _tuni = _("The field must be a text string") | |
3189 _str = _tuni.encode("utf-8") | |
3190 raise ValueError(_str) | |
3003 if not isinstance(section_dict, dict): | 3191 if not isinstance(section_dict, dict): |
3004 raise ValueError( _("The section dict must be a dictionary") ) | 3192 _tuni = _("The section dict must be a dictionary") |
3193 _str = _tuni.encode("utf-8") | |
3194 raise ValueError(_str) | |
3005 #-# | 3195 #-# |
3006 # TODO: Add a empty record? | 3196 # TODO: Add a empty record? |
3007 if not self.hasRecord(record_code): | 3197 if not self.hasRecord(record_code): |
3008 _str = _("Error: The budget do not have this record "\ | 3198 _tuni = _("Error: The budget do not have this record "\ |
3009 "code and can not be added the sheet text in the field $1. "\ | 3199 "code and can not be added the sheet text in the field $1. "\ |
3010 "Record Code: $2") | 3200 "Record Code: $2") |
3011 print(utils.mapping(_str, ( str(field), | 3201 _uni = utils.mapping(_tuni, ( text(field), record_code)) |
3012 str(record_code))).encode("utf8") ) | 3202 print(_uni) |
3013 return | 3203 return |
3014 #-# | 3204 #-# |
3015 if not self.hasSheetField(field): | 3205 if not self.hasSheetField(field): |
3016 self.setSheetField(field, "") | 3206 self.setSheetField(field, "") |
3017 for section, paragraph in section_dict.iteritems(): | 3207 for (section, paragraph) in section_dict.items(): |
3018 if not self.hasSheetParagraph(paragraph): | 3208 if not self.hasSheetParagraph(paragraph): |
3019 self.setSheetParagraph(paragraph,"") | 3209 self.setSheetParagraph(paragraph,"") |
3020 if not self.hasSheetSection(section): | 3210 if not self.hasSheetSection(section): |
3021 self.setSheetSection(section, "") | 3211 self.setSheetSection(section, "") |
3022 _sheet = self.getRecord(record_code).getSheet() | 3212 _sheet = self.getRecord(record_code).getSheet() |
3023 _sheet.addSection(field, section, paragraph) | 3213 _sheet.addSection(field, section, paragraph) |
3024 | 3214 |
3025 def addFile(self, record_code, filepath, type_, description): | 3215 def addFile(self, record_code, filepath, type_, description): |
3026 if not isinstance(record_code, str): | 3216 if not isinstance(record_code, text_type): |
3027 raise ValueError( _("The record_code code must be a string") ) | 3217 _tuni = _("The record_code code must be a text string") |
3028 #-# str and unicode | 3218 _str = _uni.encode("utf-8") |
3029 if not isinstance(filepath, str) and not isinstance(filepath, unicode): | 3219 raise ValueError(_str) |
3030 raise ValueError( _("The filename must be a string") ) | 3220 if not isinstance(filepath, text_type): |
3031 #-# | 3221 _tuni = _("The filename must be a text string") |
3222 _str = _uni.encode("utf-8") | |
3223 raise ValueError(_str) | |
3032 # TODO: Add a empty record? | 3224 # TODO: Add a empty record? |
3033 if not self.hasRecord(record_code): | 3225 if not self.hasRecord(record_code): |
3034 print(utils.mapping(_("Error: The budget do not have the record "\ | 3226 _tuni = _("Error: The budget do not have the record "\ |
3035 "code $1 and can not be added the file: $2"), | 3227 "code $1 and can not be added the file: $2") |
3036 (str(record_code), str(filepath))).encode("utf8") ) | 3228 _uni = utils.mapping(_tuni, (record_code, filepath)) |
3229 print(_uni) | |
3037 return | 3230 return |
3038 #-# | |
3039 _record = self.getRecord(record_code) | 3231 _record = self.getRecord(record_code) |
3040 _record.addFile(filepath, type_, description) | 3232 _record.addFile(filepath, type_, description) |
3041 | 3233 |
3042 def setCompany(self, company_code, sumamary, name, offices, | 3234 def setCompany(self, company_code, sumamary, name, offices, |
3043 cif, web, email): | 3235 cif, web, email): |
3044 if not isinstance(company_code, str): | 3236 if not isinstance(company_code, text_type): |
3045 raise ValueError( _("The company code must be a string") ) | 3237 _tuni = _("The company code must be a text string") |
3046 if not isinstance(sumamary, str): | 3238 _str = _tuni.encode("utf-8") |
3047 raise ValueError( _("The summary must be a string") ) | 3239 raise ValueError(_str) |
3048 if not isinstance(name, str): | 3240 if not isinstance(sumamary, text_type): |
3049 raise ValueError( _("The name must be a string") ) | 3241 _tuni = ("The summary must be a text string") |
3242 _str = _tuni.encode("utf-8") | |
3243 raise ValueError(_str) | |
3244 if not isinstance(name, text_type): | |
3245 _tuni = _("The name must be a text string") | |
3246 _str = _tuni.encode("utf-8") | |
3247 raise ValueError(_str) | |
3050 if not isinstance(offices, list): | 3248 if not isinstance(offices, list): |
3051 raise ValueError( _("The name must be a list") ) | 3249 _tuni = _("The name must be a list") |
3250 _str = _tuni.encode("utf-8") | |
3251 raise ValueError(_str) | |
3052 _offices = [] | 3252 _offices = [] |
3053 for _office in offices: | 3253 for _office in offices: |
3054 if not isinstance(_office, list): | 3254 if not isinstance(_office, list): |
3055 raise ValueError( _("The office must be a list") ) | 3255 _tuni = _("The office must be a list") |
3256 _str = _tuni.encode("utf-8") | |
3257 raise ValueError(_str) | |
3056 if not len(_office) == 10: | 3258 if not len(_office) == 10: |
3057 raise ValueError( _("The office must be a 10 items list") ) | 3259 _tuni = _("The office must be a 10 items list") |
3260 _str = _tuni.encode("utf-8") | |
3261 raise ValueError(_str) | |
3058 for _item in _office[:7] + _office[9:10]: | 3262 for _item in _office[:7] + _office[9:10]: |
3059 if not isinstance(_item, str): | 3263 if not isinstance(_item, text_type): |
3060 raise ValueError( _("This office item must be a "\ | 3264 _tuni = _("This office item must be a text string") |
3061 "string") ) | 3265 _str = _tuni.encode("utf-8") |
3266 raise ValueError(_str) | |
3062 for _item in _office[7:8]: | 3267 for _item in _office[7:8]: |
3063 if not isinstance(_item, list): | 3268 if not isinstance(_item, list): |
3064 raise ValueError( _("This office item must be a "\ | 3269 _tuni = _("This office item must be a list") |
3065 "list") ) | 3270 _str = _tuni.encode("utf-8") |
3271 raise ValueError(_str) | |
3066 _offices.append(Office(_office[0], | 3272 _offices.append(Office(_office[0], |
3067 _office[1], | 3273 _office[1], |
3068 _office[2], | 3274 _office[2], |
3069 _office[3], | 3275 _office[3], |
3070 _office[4], | 3276 _office[4], |
3071 _office[5], | 3277 _office[5], |
3072 _office[6], | 3278 _office[6], |
3073 _office[7], | 3279 _office[7], |
3074 _office[8], | 3280 _office[8], |
3075 _office[9])) | 3281 _office[9])) |
3076 if not isinstance(cif, str): | 3282 if not isinstance(cif, text_type): |
3077 raise ValueError( _("The name must be a string") ) | 3283 _tuni = _("The name must be a text string") |
3078 if not isinstance(web, str): | 3284 _str = _tuni.encode("utf-8") |
3079 raise ValueError( _("The web must be a string") ) | 3285 raise ValueError(_str) |
3080 if not isinstance(email, str): | 3286 if not isinstance(web, text_type): |
3081 raise ValueError( _("The email must be a string") ) | 3287 _tuni = _("The web must be a text string") |
3288 _str = _tuni.encode("utf-8") | |
3289 raise ValueError(_str) | |
3290 if not isinstance(email, text_type): | |
3291 _tuni = _("The email must be a text string") | |
3292 _str = _tuni.encode("utf-8") | |
3293 raise ValueError(_str) | |
3082 | 3294 |
3083 self.__companys[company_code] = Company(company_code, sumamary, name, | 3295 self.__companys[company_code] = Company(company_code, sumamary, name, |
3084 _offices, cif, web, email) | 3296 _offices, cif, web, email) |
3085 def getCompany(self, company_code): | 3297 def getCompany(self, company_code): |
3086 return self.__companys[company_code] | 3298 return self.__companys[company_code] |
3087 | 3299 |
3088 def getCompanyKeys(self): | 3300 def getCompanyKeys(self): |
3089 return self.__companys.keys() | 3301 return self.__companys.keys() |
3090 | 3302 |
3091 def addTecInfo(self, ti_code, text, unit): | 3303 def addTecInfo(self, ti_code, text, unit): |
3092 if not isinstance(ti_code, str): | 3304 if not isinstance(ti_code, text_type): |
3093 raise ValueError( _("The tecnical info code must be a string") ) | 3305 _tuni = _("The tecnical info code must be a text string") |
3094 if not isinstance(text, str): | 3306 _str = _tuni.encode("utf-8") |
3095 raise ValueError( _("The tecnical info description must be a "\ | 3307 raise ValueError(_str) |
3096 "string") ) | 3308 if not isinstance(text, text_type): |
3097 if not isinstance(unit, str): | 3309 _tuni = _("The tecnical info description must be a text string") |
3098 raise ValueError( _("The tecnical info unit must be a string") ) | 3310 _str = _tuni.encode("utf-8") |
3311 raise ValueError(_str) | |
3312 if not isinstance(unit, text_type): | |
3313 _tuni = _("The tecnical info unit must be a text string") | |
3314 _str = _tuni.encode("utf-8") | |
3315 raise ValueError(_str) | |
3099 self.__tec_info[ti_code] = [text, unit] | 3316 self.__tec_info[ti_code] = [text, unit] |
3100 | 3317 |
3101 def hasTecInfo(self, ti_code): | 3318 def hasTecInfo(self, ti_code): |
3102 return ti_code in self.__tec_info | 3319 return ti_code in self.__tec_info |
3103 | 3320 |
3143 def addLabel(self, record_code, label): | 3360 def addLabel(self, record_code, label): |
3144 """addLabel(self, record_code, label) | 3361 """addLabel(self, record_code, label) |
3145 | 3362 |
3146 Add a label to a record | 3363 Add a label to a record |
3147 """ | 3364 """ |
3148 if not isinstance(label,str): | 3365 if not isinstance(label, text_type): |
3149 raise ValueError( _("The label must be a string") ) | 3366 _tuni = _("The label must be a text string") |
3367 _str = _tuni.encode("utf-8") | |
3368 raise ValueError(_str) | |
3150 if self.hasRecord(record_code): | 3369 if self.hasRecord(record_code): |
3151 _record = self.__records[record_code] | 3370 _record = self.__records[record_code] |
3152 _record.addLabel(label) | 3371 _record.addLabel(label) |
3153 if not label in self.__labels: | 3372 if not label in self.__labels: |
3154 self.__labels[label] = [record_code] | 3373 self.__labels[label] = [record_code] |
3160 def setParametricSelectComment(self, record_code, comment): | 3379 def setParametricSelectComment(self, record_code, comment): |
3161 """setParametricSelectComment(self, record_code, comment) | 3380 """setParametricSelectComment(self, record_code, comment) |
3162 | 3381 |
3163 Sets Paramtric Record Select Comment | 3382 Sets Paramtric Record Select Comment |
3164 """ | 3383 """ |
3165 if not isinstance(record_code, str): | 3384 if not isinstance(record_code, text_type): |
3166 raise ValueError( _("The record_code code must be a string") ) | 3385 _tuni = _("The record_code code must be a text string") |
3167 if not isinstance(comment, str): | 3386 _str = _tuni.encode("utf-8") |
3168 raise ValueError( _("The parametric select comment must be a "\ | 3387 raise ValueError(_str) |
3169 "string") ) | 3388 if not isinstance(comment, text_type): |
3389 _tuni = _("The parametric select comment must be a text string") | |
3390 _str = _tuni.encode("utf-8") | |
3391 raise ValueError(_str) | |
3170 if not self.hasRecord(record_code): | 3392 if not self.hasRecord(record_code): |
3171 print(utils.mapping(_("Error: The budget do not have the record "\ | 3393 _tuni = _("Error: The budget do not have the record "\ |
3172 "code $1 and can not be added the Parametric select comment: "\ | 3394 "code $1 and can not be added the Parametric "\ |
3173 "$2"), | 3395 "select comment: $2") |
3174 (str(record_code), str(comment))).encode("utf8") ) | 3396 _uni = utils.mapping(_tuni, (record_code, comment)) |
3397 print(_uni) | |
3175 return | 3398 return |
3176 _record = self.getRecord(record_code) | 3399 _record = self.getRecord(record_code) |
3177 if not isinstance(_record, ParametricRecord): | 3400 if not isinstance(_record, ParametricRecord): |
3178 print(utils.mapping(_("Error: The Record $1 is not a "\ | 3401 _tuni = _("Error: The Record $1 is not a "\ |
3179 "Parametric Record and can not have Parametric comment"), | 3402 "Parametric Record and can not have Parametric comment") |
3180 (str(record_code),)).encode("utf8") ) | 3403 _uni = utils.mapping(_tuni, (record_code,)) |
3404 print(_uni) | |
3181 else: | 3405 else: |
3182 _record.select_comment = comment | 3406 _record.select_comment = comment |
3183 | 3407 |
3184 def setParametricSummary(self, record_code, summary): | 3408 def setParametricSummary(self, record_code, summary): |
3185 """setParametricSummary(self, record_code, summary) | 3409 """setParametricSummary(self, record_code, summary) |
3186 | 3410 |
3187 Sets parametric record summary | 3411 Sets parametric record summary |
3188 """ | 3412 """ |
3189 if not isinstance(record_code, str): | 3413 if not isinstance(record_code, text_type): |
3190 raise ValueError( _("The record_code code must be a string") ) | 3414 _tuni = _("The record_code code must be a text string") |
3191 if not isinstance(summary, str): | 3415 _str = _uni.encode("utf-8") |
3192 raise ValueError( _("The summary record must be a string") ) | 3416 raise ValueError(_str) |
3417 if not isinstance(summary, text_type): | |
3418 _tuni = _("The summary record must be a text string") | |
3419 _str = _uni.encode("utf-8") | |
3420 raise ValueError(_str) | |
3193 if not self.hasRecord(record_code): | 3421 if not self.hasRecord(record_code): |
3194 print(utils.mapping(_("Error: The budget do not have the record "\ | 3422 _tuni = _("Error: The budget do not have the record "\ |
3195 "code $1 and can not be seted the summary: $2"), | 3423 "code $1 and can not be seted the summary: $2") |
3196 (str(record_code), str(summary))).encode("utf8") ) | 3424 _uni = utils.mapping(_tuni, (record_code, summary)) |
3425 print(_uni) | |
3197 return | 3426 return |
3198 _record = self.getRecord(record_code) | 3427 _record = self.getRecord(record_code) |
3199 if not isinstance(_record, ParametricRecord): | 3428 if not isinstance(_record, ParametricRecord): |
3200 print(utils.mapping(_("Error: The Record $1 is not a "\ | 3429 _tuni = _("Error: The Record $1 is not a "\ |
3201 "Parametric Record and can not have Parametric summary"), | 3430 "Parametric Record and can not have Parametric summary") |
3202 (str(record_code),)).encode("utf8") ) | 3431 _uni = utils.mapping(_tuni, (record_code,)) |
3432 print(_uni) | |
3203 else: | 3433 else: |
3204 self.getRecord(record_code).parametric_summary = summary | 3434 self.getRecord(record_code).parametric_summary = summary |
3205 | 3435 |
3206 def setParametricText(self, record_code, text): | 3436 def setParametricText(self, record_code, text): |
3207 """setParametricText(self, record_code, text) | 3437 """setParametricText(self, record_code, text) |
3208 | 3438 |
3209 Sets parametric record text | 3439 Sets parametric record text |
3210 """ | 3440 """ |
3211 if not isinstance(record_code, str): | 3441 if not isinstance(record_code, text_type): |
3212 raise ValueError( _("The record_code code must be a string") ) | 3442 _tuni = _("The record_code code must be a text string") |
3213 if not isinstance(text, str): | 3443 _str = _uni.encode("utf-8") |
3214 raise ValueError( _("The text record must be a string") ) | 3444 raise ValueError(_str) |
3445 if not isinstance(text, text_type): | |
3446 _tuni = _("The text record must be a text string") | |
3447 _str = _uni.encode("utf-8") | |
3448 raise ValueError(_str) | |
3215 if not self.hasRecord(record_code): | 3449 if not self.hasRecord(record_code): |
3216 print(utils.mapping(_("Error: The budget do not have the record "\ | 3450 _tuni = _("Error: The budget do not have the record "\ |
3217 "code $1 and can not be seted the text: $2"), | 3451 "code $1 and can not be seted the text: $2") |
3218 (str(record_code), str(text))).encode("utf8") ) | 3452 _uni = utils.mapping(_tuni, (record_code, text)) |
3453 print(_uni) | |
3219 return | 3454 return |
3220 _record = self.getRecord(record_code) | 3455 _record = self.getRecord(record_code) |
3221 if not isinstance(_record, ParametricRecord): | 3456 if not isinstance(_record, ParametricRecord): |
3222 print(utils.mapping(_("Error: The Record $1 is not a "\ | 3457 _tuni = _("Error: The Record $1 is not a "\ |
3223 "Parametric Record and can not have Parametric text"), | 3458 "Parametric Record and can not have Parametric text") |
3224 (str(record_code),)).encode("utf8") ) | 3459 _uni = utils.mapping(_tuni, (record_code,)) |
3460 print(_uni) | |
3225 else: | 3461 else: |
3226 self.getRecord(record_code).parametric_text = text | 3462 self.getRecord(record_code).parametric_text = text |
3227 | 3463 |
3228 | 3464 |
3229 class Office(object): | 3465 class Office(object): |
3740 def getHierarchy(self): | 3976 def getHierarchy(self): |
3741 return self.__hierarchy | 3977 return self.__hierarchy |
3742 | 3978 |
3743 def setHierarchy(self, hierarchy): | 3979 def setHierarchy(self, hierarchy): |
3744 if not hierarchy in [-1, 0 , 1 ,2, ""]: | 3980 if not hierarchy in [-1, 0 , 1 ,2, ""]: |
3745 raise ValueError( utils.mapping(_("Invalid Hierarchy ($1) "\ | 3981 _tuni = _("Invalid Hierarchy ($1) "\ |
3746 "The hierarchy must be -1, 0, 1, 2"), (str(hierarchy),)) ) | 3982 "The hierarchy must be -1, 0, 1, 2") |
3983 _uni = utils.mapping(_tuni, (text(hierarchy),)) | |
3984 _str = _uni.encode("utf-8") | |
3985 raise ValueError(_str) | |
3747 elif hierarchy == "": | 3986 elif hierarchy == "": |
3748 print("Hierarchy temporarily set to an empty string".encode("utf8")) | 3987 _tuni = _("Hierarchy temporarily set to an empty string") |
3988 print(_tuni) | |
3749 #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget | 3989 #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget |
3750 self.__hierarchy = hierarchy | 3990 self.__hierarchy = hierarchy |
3751 | 3991 |
3752 def getType(self): | 3992 def getType(self): |
3753 return self.__type | 3993 return self.__type |
3754 | 3994 |
3755 def setType(self, type_): | 3995 def setType(self, type_): |
3756 if not type_ in ["", 0, 1, 2, 3] : | 3996 if not type_ in ["", 0, 1, 2, 3]: |
3757 raise ValueError( utils.mapping(_("Invalid type ($1),"\ | 3997 _tuni = _("Invalid type ($1),"\ |
3758 "the type must be (empty string,0,1,2,3)"),(str(type_)),) ) | 3998 "the type must be (empty string,0,1,2,3)") |
3999 _uni = utils.mapping(_tuni ,(text(type_),)) | |
4000 _str = _uni.encode("utf-8") | |
4001 raise ValueError(_str) | |
3759 self.__type = type_ | 4002 self.__type = type_ |
3760 | 4003 |
3761 def getSubtype(self): | 4004 def getSubtype(self): |
3762 return self.__subtype | 4005 return self.__subtype |
3763 | 4006 |
3764 def setSubtype(self, subtype): | 4007 def setSubtype(self, subtype): |
3765 if not subtype in ["", "OB", "PU", "EA", "EU", "EC", "EF", "PA", "H", | 4008 if not subtype in ["", "OB", "PU", "EA", "EU", "EC", "EF", "PA", "H", |
3766 "Q", "%", "MC", "MCr", "MM", "MS", "ME", "MCu", | 4009 "Q", "%", "MC", "MCr", "MM", "MS", "ME", "MCu", |
3767 "Mal","ML","M"]: | 4010 "Mal","ML","M"]: |
3768 raise ValueError( utils.mapping(_("Invalid subtype ($1), The "\ | 4011 _tuni = _("Invalid subtype ($1), The "\ |
3769 "subtype must one in (empty string, EA, "\ | 4012 "subtype must one in (empty string, EA, "\ |
3770 "EU, EC, EF, OB, PA, PU, H, Q, %, MC, MCr, "\ | 4013 "EU, EC, EF, OB, PA, PU, H, Q, %, MC, MCr, "\ |
3771 "MM, MS, ME, MCu, MAl, ML, M)"), (str(subtype),)) ) | 4014 "MM, MS, ME, MCu, MAl, ML, M)") |
4015 _uni = utils.mapping(_tuni, (text(subtype),)) | |
4016 _str = _uni.encode("utf-8") | |
4017 raise ValueError(_str) | |
3772 self.__subtype = subtype | 4018 self.__subtype = subtype |
3773 | 4019 |
3774 hierarchy = property(getHierarchy, setHierarchy, None, | 4020 hierarchy = property(getHierarchy, setHierarchy, None, |
3775 """Record Hierarchy | 4021 """Record Hierarchy |
3776 -1 -> temporarily unfixed | 4022 -1 -> temporarily unfixed |