diff --git a/ofxparse/ofxparse.py b/ofxparse/ofxparse.py index 8af6c60..5703f15 100644 --- a/ofxparse/ofxparse.py +++ b/ofxparse/ofxparse.py @@ -259,6 +259,9 @@ def __init__(self, keys): else: self.success = False + self.dtserver = OfxParser.parseOfxDateTime( + self.dtserver.strip()) + def __str__(self): ret = "\t\r\n" + "\t\t\r\n" + \ "\t\t\t\r\n" diff --git a/ofxparse/ofxprinter.py b/ofxparse/ofxprinter.py index e39b895..aa6351b 100644 --- a/ofxparse/ofxprinter.py +++ b/ofxparse/ofxprinter.py @@ -7,16 +7,19 @@ class OfxPrinter(): out_handle = None term = "\r\n" - def __init__(self, ofx, filename, term="\r\n"): + def __init__(self, ofx, filename, term="\r\n", tabs=True): self.ofx = ofx self.out_filename = filename self.term = term + self.tabs_enabled = tabs def writeLine(self, data, tabs=0, term=None): if term is None: term = self.term - tabbing = (tabs * "\t") if (tabs > 0) else '' + tabbing = '' + if self.tabs_enabled: + tabbing = (tabs * "\t") if (tabs > 0) else '' return self.out_handle.write( "{0}{1}{2}".format( @@ -35,9 +38,34 @@ def writeHeaders(self): self.writeLine("") def writeSignOn(self, tabs=0): - # signon already has newlines and tabs in it - # TODO: reimplement signon printing with tabs - self.writeLine(self.ofx.signon.__str__(), term="") + if self.ofx.signon: + self.writeLine("", tabs=tabs) + tabs += 1 + self.writeLine("", tabs=tabs) + tabs += 1 + if self.ofx.signon.code or self.ofx.signon.severity: + self.writeLine("", tabs=tabs) + if self.ofx.signon.code is not None: + self.writeLine("{0}".format( + self.ofx.signon.code + ), tabs=tabs + 1) + if self.ofx.signon.severity: + self.writeLine("{0}".format( + self.ofx.signon.severity + ), tabs=tabs + 1) + self.writeLine("", tabs=tabs) + if self.ofx.signon.dtserver: + self.writeLine("{0}".format( + self.printDate(self.ofx.signon.dtserver) + ), tabs=tabs) + if self.ofx.signon.language: + self.writeLine("{0}".format( + self.ofx.signon.language + ), tabs=tabs) + tabs -= 1 + self.writeLine("", tabs=tabs) + tabs -= 1 + self.writeLine("", tabs=tabs) def printDate(self, dt, msec_digs=3): strdt = dt.strftime('%Y%m%d%H%M%S') @@ -65,7 +93,8 @@ def writeTrn(self, trn, tabs=5): trn.checknum ), tabs=tabs) - self.writeLine("{}".format(trn.payee), tabs=tabs) + if len(trn.payee) > 0: + self.writeLine("{}".format(trn.payee), tabs=tabs) if len(trn.memo.strip()) > 0: self.writeLine("{}".format(trn.memo), tabs=tabs) @@ -146,6 +175,44 @@ def writeStmTrs(self, tabs=3): self.writeLine("", tabs=tabs) + def writeCCStmTrs(self, tabs=3): + for acct in self.ofx.accounts: + self.writeLine("", tabs=tabs) + tabs += 1 + + if acct.curdef: + self.writeLine("{0}".format( + acct.curdef + ), tabs=tabs) + + if acct.account_id: + self.writeLine("", tabs=tabs) + self.writeLine("{0}".format( + acct.account_id + ), tabs=tabs+1) + self.writeLine("", tabs=tabs) + + self.writeLine("", tabs=tabs) + tabs += 1 + self.writeLine("{0}".format( + self.printDate(acct.statement.start_date) + ), tabs=tabs) + self.writeLine("{0}".format( + self.printDate(acct.statement.end_date) + ), tabs=tabs) + + for trn in acct.statement.transactions: + self.writeTrn(trn, tabs=tabs) + + tabs -= 1 + + self.writeLine("", tabs=tabs) + self.writeLedgerBal(acct.statement, tabs=tabs) + + tabs -= 1 + + self.writeLine("", tabs=tabs) + def writeBankMsgsRsv1(self, tabs=1): self.writeLine("", tabs=tabs) tabs += 1 @@ -170,11 +237,38 @@ def writeBankMsgsRsv1(self, tabs=1): tabs -= 1 self.writeLine("", tabs=tabs) + def writeCreditCardMsgsRsv1(self, tabs=1): + self.writeLine("", tabs=tabs) + tabs += 1 + self.writeLine("", tabs=tabs) + tabs += 1 + if self.ofx.trnuid is not None: + self.writeLine("{0}".format( + self.ofx.trnuid + ), tabs=tabs) + if self.ofx.status: + self.writeLine("", tabs=tabs) + self.writeLine("{0}".format( + self.ofx.status['code'] + ), tabs=tabs+1) + self.writeLine("{0}".format( + self.ofx.status['severity'] + ), tabs=tabs+1) + self.writeLine("", tabs=tabs) + self.writeCCStmTrs(tabs=tabs) + tabs -= 1 + self.writeLine("", tabs=tabs) + tabs -= 1 + self.writeLine("", tabs=tabs) + def writeOfx(self, tabs=0): self.writeLine("", tabs=tabs) tabs += 1 self.writeSignOn(tabs=tabs) - self.writeBankMsgsRsv1(tabs=tabs) + if self.ofx.account.type == 2: + self.writeCreditCardMsgsRsv1(tabs=tabs) + else: + self.writeBankMsgsRsv1(tabs=tabs) tabs -= 1 # No newline at end of file self.writeLine("", tabs=tabs, term="")