1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
|
'''
.. note::
license: GNU Lesser General Public License v3.0 (see LICENSE)
Partial implementation of a OFX file writer.
This package is not intended to fully implement the OFX Spec. Its final purpose
is the conversion from CSB43 (norma 43 del Consejo Superior Bancario). That is,
only transaction response is (partially) implemented.
.. seealso::
References:
- (http://www.ofx.net/)
'''
from typing import (
Optional,
List,
Sequence,
Union,
)
from datetime import datetime
from decimal import Decimal
from xml.sax.saxutils import escape
DATEFORMAT = "%Y%m%d" # short date OFX format
def XMLElement(name: str, content) -> str:
'''
Build a *name* XML element with *content* as body.
Args:
name -- tag name
content -- content of the node
Return:
(str) <NAME>content</NAME>
>>> XMLElement("hello", 12)
'<HELLO>12</HELLO>'
'''
if content is not None:
return "<{0}>{1}</{0}>".format(name.upper(), content)
else:
return ""
def XMLAggregate(*args, **kwargs) -> str:
'''
Build a *name* XML aggregate with *content* as body.
Args:
name -- tag name
content -- content of the node
Return:
(str) <NAME>content</NAME>
>>> XMLAggregate("hello", 12)
'<HELLO>12</HELLO>'
'''
return XMLElement(*args, **kwargs)
def SGMLElement(name: str, content) -> str:
'''
Build a *name* SGML element with *content* as body.
Args:
name -- tag name
content -- content of the node
Return:
(str) <NAME>content
>>> SGMLElement("hello", 12)
'<HELLO>12'
'''
if content is not None:
return "<{0}>{1}".format(name.upper(), content)
else:
return ""
def SGMLAggregate(name: str, content) -> str:
'''
Build a *name* SGML aggregate with *content* as body.
Args:
name -- tag name
content -- content of the node
Return:
(str) <NAME>content</NAME>
>>> SGMLAggregate("hello", 12)
'<HELLO>12</HELLO>'
'''
if content is not None:
return "<{0}>{1}</{0}>".format(name.upper(), content)
else:
return ""
def strDate(field: Optional[datetime]) -> Optional[str]:
'''
Format a date as specified by OFX
Args:
field (datetime)
Return:
(str)
'''
if field:
return field.strftime(DATEFORMAT)
else:
return None
def strBool(field: Optional[bool]) -> Optional[str]:
'''
Format a boolean as specified by OFX
Args:
field (bool)
Return:
(str)
'''
if field is not None:
if field:
return "Y"
else:
return "N"
else:
return None
def strCurrency(field):
'''
Format a ISO-4217 currency entity as specified by OFX
Args:
field (pycountry.Currency)
Return:
(str)
'''
if field is not None:
# ISO-4217
return field.alpha_3
else:
return None
def strText(field: Optional[str]) -> Optional[str]:
'''
Format a string as specified by OFX, that is, characters '&', '>' and '<'
are XML escaped.
'''
if field is not None:
return escape("{0}".format(field))
else:
return None
class OfxObject(object):
def __init__(self, tagName: str, sgml=False):
'''
:param tagName: name for the XML tag
:type tagName: :class:`str`
'''
self._tagName = tagName
self._sgml = sgml
if sgml:
self._ELEM = SGMLElement
self._AGGR = SGMLAggregate
else:
self._ELEM = XMLElement
self._AGGR = XMLAggregate
def _get_content(self) -> str:
'''
:rtype: the xml representation of this object
'''
return ""
def is_sgml(self) -> bool:
return self._sgml
def get_tag_name(self) -> str:
'''
:rtype: the XML tag name
'''
return self._tagName
def set_tag_name(self, name: str):
'''
Set a XML tag name for this object
:param name: name for the XML tag
:type name: :class:`str`
'''
self._tagName = name
def __str__(self) -> str:
'''
:rtype: XML representation of the object
'''
# return XMLElement(self._tagName, self._get_content())
return self._get_content()
class File(OfxObject):
'''
An OFX file
'''
def __init__(self, tagName="ofx", **kwargs):
'''
:param tagName: tag's name to be used for this object
:type tagName: :class:`str`
'''
super(File, self).__init__(tagName, **kwargs)
# self.__requests = []
self.__responses: List['Response'] = []
# def get_requests(self):
# '''
# Return:
# list of requests
# '''
# return self.__requests
def get_responses(self) -> Sequence['Response']:
'''
:rtype: :class:`list` of :class:`Response`
'''
return self.__responses
# def add_request(self, value):
# '''
# Args:
# value (Request)
# '''
# self.__requests.append(value)
def add_response(self, value: 'Response'):
'''
Add a response to the file
:param value: a response object to include in this object
:type value: :class:`Response`
'''
self.__responses.append(value)
def _get_content(self) -> str:
ELEM = self._ELEM
AGGR = self._AGGR
if self.is_sgml():
header = (
"OFXHEADER:100\n"
"DATA:OFXSGML\n"
"VERSION:103\n"
"ENCODING:UNICODE\n\n"
)
else:
header = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<?OFX OFXHEADER="200" VERSION="211" SECURITY="NONE"'
' OLDFILEUID="NONE" NEWFILEUID="NONE"?>'
)
content = ""
for r in self.__responses:
aux = ELEM("trnuid", 0)
aux += AGGR("status",
ELEM("code", 0) + ELEM("severity", "INFO"))
aux += AGGR(r.get_tag_name(), r)
content += AGGR("stmttrnrs", aux)
content = (
AGGR("signonmsgsrsv1", SignOnResponse(sgml=self.is_sgml()))
+ AGGR("bankmsgsrsv1", content)
)
return header + AGGR(self.get_tag_name(), content)
class SignOnResponse(OfxObject):
def __init__(self, tagName="sonrs", **kwargs):
'''
:param tagName: name for the XML tag
:type tagName: :class:`str`
'''
super(SignOnResponse, self).__init__(tagName, **kwargs)
def _get_content(self) -> str:
ELEM = self._ELEM
AGGR = self._AGGR
code = ELEM("code", 0)
severity = ELEM("severity", "INFO")
status = AGGR("status", code + severity)
dtserver = ELEM("dtserver", strDate(datetime.utcnow()))
language = ELEM("language", "SPA")
return AGGR(self.get_tag_name(), status + dtserver + language)
class Response(OfxObject):
def __init__(self, tagName="stmtrs", **kwargs):
'''
:param tagName: name for the XML tag
:type tagName: :class:`str`
'''
super(Response, self).__init__(tagName, **kwargs)
self.__currency = None
self.__accountFrom = None
self.__transactionList = None
self.__ledgerBalance = None
self.__availableBalance = None
self.__balances = []
self.__mktginfo = None
def get_currency(self):
'''
:rtype: :class:`pycountry.dbCurrency` -- \
Default currency for the statement
'''
return self.__currency
def get_bank_account_from(self) -> Optional['BankAccount']:
'''
:rtype: :class:`BankAccount` -- Account-from aggregate
'''
return self.__accountFrom
def get_transaction_list(self) -> Optional['TransactionList']:
'''
:rtype: :class:`TransactionList` -- \
Statement-transaction-data aggregate
'''
return self.__transactionList
def get_ledger_balance(self) -> Optional['Balance']:
'''
:rtype: :class:`Balance` -- the ledger balance aggregate
'''
return self.__ledgerBalance
def get_available_balance(self) -> Optional['Balance']:
'''
:rtype: `Balance` -- the available balance aggregate
'''
return self.__availableBalance
def get_balances(self) -> Optional[Sequence['Balance']]:
'''
:rtype: :class:`list` of miscellaneous other :class:`Balance` s
'''
return self.__balances
def get_mktginfo(self):
'''
:rtype: marketing info
'''
return self.__mktginfo
def set_currency(self, value):
'''
:param value: currency
:type value: :class:`pycountry.db.Currency`
'''
self.__currency = value
def set_bank_account_from(self, value: 'BankAccount'):
'''
:param value: value
:type value: :class:`BankAccount`
'''
self.__accountFrom = value
def set_transaction_list(self, value: 'TransactionList'):
'''
:param value: transactions list
:type value: :class:`TransactionList`
'''
self.__transactionList = value
def set_ledger_balance(self, value: 'Balance'):
'''
:param value: ledger balance
:type value: :class:`Balance`
'''
self.__ledgerBalance = value
def set_available_balance(self, value: 'Balance'):
'''
:param value: available balance
:type value: :class:`Balance`
'''
self.__availableBalance = value
def add_balance(self, value: 'Balance'):
'''
Add a complementary balance
:param value: a complementary balance
:type value: :class:`Balance`
'''
self.__balances.append(value)
def set_mktginfo(self, value):
'''
:param value: marketing info
'''
self.__mktginfo = value
def _get_content(self) -> str:
ELEM = self._ELEM
AGGR = self._AGGR
strC = ELEM("curdef", strCurrency(self.__currency))
strC += AGGR("bankacctfrom", self.__accountFrom)
strC += AGGR("banktranlist", self.__transactionList)
strC += AGGR("ledgerbal", self.__ledgerBalance)
strC += AGGR("availbal", self.__availableBalance)
if len(self.__balances) > 0:
strC += AGGR(
"ballist",
"".join(AGGR(x.get_tag_name(), x) for x in self.__balances)
)
strC += ELEM("mktginfo", strText(self.__mktginfo))
return strC
class TransactionList(OfxObject):
'''
Transaction list aggregate
'''
def __init__(self, tagName="banktranslist", **kwargs):
'''
Args:
tagName (str) -- see *OfxObject*
'''
super(TransactionList, self).__init__(tagName, **kwargs)
self.__dateStart = None
self.__dateEnd = None
self.__list = []
def get_date_start(self) -> Optional[datetime]:
'''
:rtype: :class:`datetime.datetime` -- date of the first transaction
'''
return self.__dateStart
def get_date_end(self) -> Optional[datetime]:
'''
:rtype: :class:`datetime.datetime` -- date of the first transaction
'''
return self.__dateEnd
def get_list(self) -> Sequence['Transaction']:
'''
:rtype: :class:`list` of :class:`Transaction`
'''
return self.__list
def set_date_start(self, value):
'''
:param value: date of start
:type value: :class:`datetime.datetime`
'''
self.__dateStart = value
def set_date_end(self, value: datetime):
'''
:param value: date of end
:type value: :class:`datetime.datetime`
'''
self.__dateEnd = value
def add_transaction(self, value: 'Transaction'):
'''
Add a new transaction to the list
:param value: a transaction
:type value: :class:`Transaction`
'''
self.__list.append(value)
def _get_content(self) -> str:
ELEM = self._ELEM
strC = ELEM("dtstart", strDate(self.__dateStart))
strC += ELEM("dtend", strDate(self.__dateEnd))
for t in self.__list:
strC += self._AGGR(t.get_tag_name(), t)
return strC
class Transaction(OfxObject):
'''
A OFX transaction
'''
#: type of transaction
TYPE = [
"CREDIT", # 0
"DEBIT", # 1
"INT", # 2
"DIV", # 3
"FEE", # 4
"SRVCHG", # 5
"DEP", # 6
"ATM", # 7
"POS", # 8
"XFER", # 9
"CHECK", # 10
"PAYMENT", # 11
"CASH", # 12
"DIRECTDEP", # 13
"DIRECTDEBIT", # 14
"REPEATPMT", # 15
"OTHER" # 16
]
def __init__(self, tagName="stmttrn", **kwargs):
'''
:param tagName: see :class:`OfxObject`
:type tagName: :class:`str`
'''
super(Transaction, self).__init__(tagName, **kwargs)
self.__type = None
self.__datePosted = None
self.__dateInitiated = None
self.__dateAvailable = None
self.__amount = None
self.__transactionId = None
self.__correctFitId = None
self.__correctAction = None
self.__serverTid = None
self.__checkNum = None
self.__refNum = None
self.__standardIndustrialCode = None
self.__payee = None
self.__bankAccountTo = None
self.__ccAccountTo = None
self.__memo = None
self.__imageData = None
self.__currency = None
self.__originCurrency = None
self.__originAmount = None
self.__inv401ksource = None
self.__payeeid = None
self.__name = None
self.__extendedName = None
def get_name(self) -> Optional[str]:
'''
:rtype: :class:`str` -- name of payee or description of transaction
'''
return self.__name
def get_extended_name(self) -> Optional[str]:
'''
:rtype: :class:`str` -- extended name of payee or description of \
transaction
'''
return self.__extendedName
def set_name(self, value: str):
'''
:param value: name of payee or description of transaction
'''
self.__name = value
def set_extended_name(self, value: str):
'''
:param value: extended name of payee or description of transaction
'''
self.__extendedName = value
def get_ref_num(self) -> Optional[str]:
'''
:rtype: :class:`str` -- reference number that uniquely indentifies \
the transaction.
'''
return self.__refNum
def set_ref_num(self, value: str):
'''
:param value: reference number that uniquely indentifies the \
transaction.
'''
self.__refNum = value
def get_type(self) -> str:
'''
:rtype: :class:`str` -- transaction type. See :class:`TYPE`. Default \
('OTHER')
'''
if self.__type is None:
return Transaction.TYPE[-1]
else:
return self.__type
def get_date_posted(self) -> Optional[datetime]:
'''
:rtype: :class:`datetime.datetime` -- date transaction was posted to \
account
'''
return self.__datePosted
def get_date_initiated(self) -> Optional[datetime]:
'''
:rtype: :class:`datetime.datetime` -- date user initiated transaction
'''
return self.__dateInitiated
def get_date_available(self) -> Optional[datetime]:
'''
:rtype: :class:`datetime.datetime` -- date funds are available
'''
return self.__dateAvailable
def get_amount(self) -> Optional[Union[int, float, Decimal]]:
'''
:rtype: number -- amount of transaction
'''
return self.__amount
def get_transaction_id(self) -> str:
'''
:rtype: :class:`str` -- transaction ID issued by financial institution
'''
return self.__transactionId
def get_correct_fit_id(self) -> str:
'''
correct fit id
'''
return self.__correctFitId
def get_correct_action(self) -> str:
'''
correct action
'''
return self.__correctAction
def get_server_tid(self) -> str:
'''
server transaction id
'''
return self.__serverTid
def get_check_num(self) -> str:
'''
:rtype: :class:`str` -- check (or other reference) number
'''
return self.__checkNum
def get_standard_industrial_code(self) -> Optional[str]:
'''
standard industrial code
'''
return self.__standardIndustrialCode
def get_payee(self) -> Optional['Payee']:
'''
:rtype: :class:`Payee`
'''
return self.__payee
def get_payeeid(self) -> Optional[str]:
'''
:rtype: :class:`str` -- payee identifier
'''
return self.__payeeid
def get_bank_account_to(self) -> Optional['BankAccount']:
'''
:rtype: :class:`BankAccount` -- account the transaction is \
transferring to
'''
return self.__bankAccountTo
def get_cc_account_to(self) -> Optional['BankAccount']:
'''
cc account to
'''
return self.__ccAccountTo
def get_memo(self) -> Optional[str]:
'''
:rtype: :class:`str` -- extra information
'''
return self.__memo
def get_image_data(self):
'''
image data
'''
return self.__imageData
def get_currency(self):
'''
:rtype: :class:`pycountry.db.Currency` -- currency of the \
transaction, if different from the one in :class:`BankAccount`
'''
return self.__currency
def get_origin_currency(self):
'''
:rtype: :class:`pycountry.db.Currency` -- currency of the \
transaction, if different from the one in :class:`BankAccount`
'''
return self.__originCurrency
def get_origin_amount(self):
return self.__originAmount
def get_inv_401ksource(self):
return self.__inv401ksource
def set_type(self, value):
self.__type = value
def set_date_posted(self, value: datetime):
self.__datePosted = value
def set_date_initialised(self, value: datetime):
self.__dateInitiated = value
def set_date_available(self, value: datetime):
self.__dateAvailable = value
def set_amount(self, value: Union[int, float, Decimal]):
self.__amount = value
def set_transaction_id(self, value: str):
self.__transactionId = value
def set_correct_fit_id(self, value: str):
self.__correctFitId = value
def set_correct_action(self, value: str):
self.__correctAction = value
def set_server_tid(self, value: str):
self.__serverTid = value
def set_check_num(self, value: str):
self.__checkNum = value
def set_standard_industrial_code(self, value: str):
self.__standardIndustrialCode = value
def set_payee(self, value: 'Payee'):
self.__payee = value
def set_payeeid(self, value: str):
self.__payeeid = value
def set_bank_account_to(self, value: 'BankAccount'):
self.__bankAccountTo = value
def set_cc_account_to(self, value: 'BankAccount'):
self.__ccAccountTo = value
def set_memo(self, value: str):
self.__memo = value
def set_image_data(self, value):
self.__imageData = value
def set_currency(self, value):
self.__currency = value
def set_origin_currency(self, value):
self.__originCurrency = value
def set_origin_amount(self, value):
self.__originAmount = value
def set_inv_401ksource(self, value):
self.__inv401ksource = value
def _get_content(self) -> str:
ELEM = self._ELEM
AGGR = self._AGGR
strC = ELEM("trntype", self.get_type())
strC += ELEM("dtposted", strDate(self.__datePosted))
strC += ELEM("dtuser", strDate(self.__dateInitiated))
strC += ELEM("dtavail", strDate(self.__dateAvailable))
strC += ELEM("trnamt", self.__amount)
strC += ELEM("fitid", strText(self.__transactionId))
strC += ELEM("correctfitid", strText(self.__correctFitId))
strC += ELEM("correctaction", self.__correctAction)
strC += ELEM("srvrtid", strText(self.__serverTid))
strC += ELEM("checknum", strText(self.__checkNum))
strC += ELEM("refnum", strText(self.__refNum))
strC += ELEM("sic", strText(self.__standardIndustrialCode))
strC += ELEM("payeeid", strText(self.__payeeid))
strC += ELEM("name", strText(self.__name))
strC += ELEM("extdname", strText(self.__extendedName))
strC += AGGR("payee", self.__payee)
strC += AGGR("bankacctto", self.__bankAccountTo)
strC += AGGR("ccacctto", self.__ccAccountTo)
strC += ELEM("memo", strText(self.__memo))
strC += AGGR("imagedata", self.__imageData)
strC += ELEM("currency", strCurrency(self.__currency))
strCurr = None
if self.__originCurrency:
ratio = round(self.__amount / self.__originAmount, 20)
strCurr = ELEM("currate", ratio)
strCurr += ELEM("cursym", strCurrency(self.__originCurrency))
strC += AGGR("origcurrency", strCurr)
strC += ELEM("inv401ksource", self.__inv401ksource)
return strC
class BankAccount(OfxObject):
'''
A bank account
'''
#: account type
TYPE = ["CHECKING", "SAVINGS", "MONEYMRKT", "CREDITLINE"]
def __init__(self, tagName="bankaccfrom", **kwargs):
super(BankAccount, self).__init__(tagName, **kwargs)
self.__bankId = None
self.__branchId = None
self.__id = None
self.__type = None
self.__key = None
def get_type(self) -> str:
'''
:rtype: :class:`str` -- type of account. See :class:`TYPE` (default \
*'SAVINGS'*)
'''
if self.__type is None:
return BankAccount.TYPE[1]
else:
return self.__type
def get_key(self) -> Optional[str]:
'''
:rtype: :class:`str` -- checksum (Spain: digitos de control)
'''
return self.__key
def set_type(self, value: str):
'''
:param value: type of account
:type value: :class:`str`
'''
self.__type = value
def set_key(self, value: str):
'''
:param value: checksum
'''
self.__key = value
def get_bank(self) -> str:
'''
:rtype: :class:`str` -- bank identifier (Spain: banco, entidad)
'''
return self.__bankId
def get_branch(self) -> str:
'''
:rtype: :class:`str` -- branch identifier (Spain: sucursal, oficina)
'''
return self.__branchId
def get_id(self) -> str:
'''
:rtype: :class:`str` -- account identifier
'''
return self.__id
def set_bank(self, value: str):
'''
:param value: bank identifier
'''
self.__bankId = value
def set_branch(self, value: str):
'''
:param branch: branch identifier
'''
self.__branchId = value
def set_id(self, value: str):
'''
:param value: account id
'''
self.__id = value
def _get_content(self) -> str:
ELEM = self._ELEM
strContent = ELEM("bankid", strText(self.__bankId))
strContent += ELEM("branchid", strText(self.__branchId))
strContent += ELEM("acctid", strText(self.__id))
strContent += ELEM("accttype", self.get_type())
strContent += ELEM("acctkey", strText(self.__key))
return strContent
class Payee(OfxObject):
def __init__(self, tagName="payeeid", **kwargs):
super(Payee, self).__init__(tagName, **kwargs)
self.__name = None
self.__payee = None
self.__extendedName = None
def get_name(self) -> Optional[str]:
return self.__name
def get_payee(self) -> Optional[str]:
return self.__payee
def get_extended_name(self) -> Optional[str]:
return self.__extendedName
def set_name(self, value: str):
self.__name = value
def set_payee(self, value: str):
self.__payee = value
def set_extended_name(self, value: str):
self.__extendedName = value
def _get_content(self) -> str:
ELEM = self._ELEM
strContent = ""
if self.__name:
strContent += ELEM("name", strText(self.__name))
else:
strContent += self._AGGR("payee", self.__payee)
strContent += ELEM("extdname", strText(self.__extendedName))
return strContent
class Balance(OfxObject):
'''
A balance
'''
def __init__(self, tagName="bal", **kwargs):
super(Balance, self).__init__(tagName, **kwargs)
self.__amount = None
self.__date = None
def get_amount(self) -> Optional[Union[int, float, Decimal]]:
'''
:rtype: the amount of the balance
'''
return self.__amount
def get_date(self) -> Optional[datetime]:
'''
:rtype: :class:`datetime` -- date of the balance
'''
return self.__date
def set_amount(self, value: Union[int, float, Decimal]):
'''
:param value: amount
'''
self.__amount = value
def set_date(self, value: datetime):
'''
:param value: a date object
:type value: :class:`datetime.datetime`
'''
self.__date = value
def _get_content(self) -> str:
ELEM = self._ELEM
return "{amount}{date}".format(
amount=ELEM("balamt", self.__amount),
date=ELEM("dtasof", strDate(self.__date))
)
|