def test_checking(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'checking.ofx'))) converter = OfxConverter(account=ofx.account, name="Foo") self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.1452687~7.0000486 Expenses:Misc -$0.01 """) self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[1]).format(), """2011/04/05 AUTOMATIC WITHDRAWAL, ELECTRIC BILL WEB(S ) Foo -$34.51 ; ofxid: 1101.1452687~7.0000487 Expenses:Misc $34.51 """) self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[2]).format(), """2011/04/07 RETURNED CHECK FEE, CHECK # 319 FOR $45.33 ON 04/07/11 Foo -$25.00 ; ofxid: 1101.1452687~7.0000488 Expenses:Misc $25.00 """)
def test_transfer_txn(self): ofx = OfxParser.parse( open( os.path.join( 'fixtures', 'investment_401k.ofx'))) converter = OfxConverter(account=ofx.account, name="Foo", unknownaccount='Expenses:Unknown') if len(ofx.account.statement.transactions) > 2: # older versions of ofxparse would skip these transactions if hasattr(ofx.account.statement.transactions[2], 'tferaction'): # unmerged pull request self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[2]).format(), """2014/06/30 Foo: transfer: out Foo -9.060702 BAZ @ $21.928764 ; ofxid: 1234.12345678.123456-01.3 Transfer $198.69 """) else: self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[2]).format(), """2014/06/30 Foo: transfer Foo -9.060702 BAZ @ $21.928764 ; ofxid: 1234.12345678.123456-01.3 Transfer $198.69 """)
def test_checking(self): with open(os.path.join('fixtures', 'checking.ofx'), 'rb') as ofx_file: ofx = OfxParser.parse(ofx_file) converter = OfxConverter(account=ofx.account, name="Foo") self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.1452687~7.0000486 Expenses:Misc -$0.01 """) self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[1]).format(), """2011/04/05 AUTOMATIC WITHDRAWAL, ELECTRIC BILL WEB(S ) Foo -$34.51 ; ofxid: 1101.1452687~7.0000487 Expenses:Misc $34.51 """) self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[2]).format(), """2011/04/07 RETURNED CHECK FEE, CHECK # 319 FOR $45.33 ON 04/07/11 Foo -$25.00 ; ofxid: 1101.1452687~7.0000488 Expenses:Misc $25.00 """)
def test_fee(self): """Test that fees are parsed correctly. In this case we have a 7-cent fee. We need to make sure that the net sale price which shows up is the gross price of 3239.44 minus 7 cents which equals 3239.37 and that the 7 cent fee shows up as an extra posting. """ with open(os.path.join('fixtures', 'fidelity_fee.ofx'), 'rb') as ofx_file: ofx = OfxParser.parse(ofx_file) converter = OfxConverter(account=ofx.account, name="Foo", security_list=SecurityList(ofx)) # test fee self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[1]).format(), """2012/08/01 SELL Foo -100.0 "929042109" @ $32.3944 ; ofxid: 7776.01234567890.0123456789021401420120801 Assets:Unknown $3239.37 Expenses:Fees $0.07 """) # test fee and comission self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[0]).format(), """2020/05/22=2020/05/26 SELL Foo -1.0 "Z9977810Z" @ $8.27 ; ofxid: 7776.01234567890.987654321 Assets:Unknown $8.25 Expenses:Fees $0.02 Expenses:Commission $1.00 """)
def test_transfer_txn(self): with open(os.path.join('fixtures', 'investment_401k.ofx'), 'rb') as ofx_file: ofx = OfxParser.parse(ofx_file) converter = OfxConverter(account=ofx.account, name="Foo", unknownaccount='Expenses:Unknown') if len(ofx.account.statement.transactions) > 2: # older versions of ofxparse would skip these transactions if hasattr(ofx.account.statement.transactions[2], 'tferaction'): # unmerged pull request self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[2]).format(), """2014/06/30 Foo: transfer: out Foo -9.060702 BAZ @ $21.928764 ; ofxid: 1234.12345678.123456-01.3 Transfer $198.69 """) else: self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[2]).format(), """2014/06/30 Foo: transfer Foo -9.060702 BAZ @ $21.928764 ; ofxid: 1234.12345678.123456-01.3 Transfer $198.69 """)
def test_investments(self): ofx = OfxParser.parse(file(os.path.join('fixtures', 'fidelity.ofx'))) converter = OfxConverter(ofx=ofx, name="Foo") self.assertEqualLedgerPosting(converter.convert(ofx.account.statement.transactions[0]).format(), """2012/07/20 YOU BOUGHT Foo 100.00000 INTC @ $25.635000000 ; ofxid: 7776.01234567890.0123456789020201120120720 Assets:Unknown -$2563.50 """) # test no payee/memo self.assertEqualLedgerPosting(converter.convert(ofx.account.statement.transactions[1]).format(), """2012/07/27 Foo: buystock Foo 128.00000 SDRL @ $39.390900000 ; ofxid: 7776.01234567890.0123456789020901120120727 Assets:Unknown -$5042.04 """)
def test_quote_commodity(self): ofx = OfxParser.parse(file(os.path.join('fixtures', 'fidelity.ofx'))) converter = OfxConverter(ofx=ofx, name="Foo") self.assertEqualLedgerPosting(converter.convert(ofx.account.statement.transactions[0]).format(), """2012/07/20 YOU BOUGHT Foo 100.00000 INTC @ $25.635000000 ; ofxid: 7776.01234567890.0123456789020201120120720 Assets:Unknown -$2563.50 """)
def test_indent(ofx): converter = OfxConverter(account=ofx.account, name="Foo", indent=4) # testing indent, so do not use the string collapsing version of assert assert ( converter.convert(ofx.account.statement.transactions[0]).format() == """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.1452687~7.0000486 Expenses:Misc -$0.01 """)
def test_unknownaccount(self): ofx = OfxParser.parse(file(os.path.join('fixtures', 'checking.ofx'))) converter = OfxConverter(ofx=ofx, name="Foo", unknownaccount='Expenses:Unknown') self.assertEqualLedgerPosting(converter.convert(ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.1452687~7.0000486 Expenses:Unknown -$0.01 """)
def test_hardcodeaccount(self): ofx = OfxParser.parse(file(os.path.join('fixtures', 'checking.ofx'))) converter = OfxConverter(ofx=ofx, name="Foo", indent=4, hardcodeaccount="9999") # testing indent, so do not use the string collapsing version of assert self.assertEqual(converter.convert(ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.9999.0000486 Expenses:Misc -$0.01 """)
def test_dividend(self): ofx = OfxParser.parse(file(os.path.join('fixtures', 'income.ofx'))) converter = OfxConverter(ofx=ofx, name="Foo") self.assertEqualLedgerPosting(converter.convert(ofx.account.statement.transactions[0]).format(), """2016/10/12 DIVIDEND RECEIVED ; dividend_from: cusip_redacted Foo $1234.56 ; ofxid: 1234.12345678.123456-01.redacted Income:Dividends -$1234.56 """)
def test_dynamic_account(self): ofx = OfxParser.parse(file(os.path.join('fixtures', 'checking.ofx'))) ledger = Ledger(os.path.join('fixtures', 'checking-dynamic-account.lgr')) converter = OfxConverter(ofx=ofx, name="Assets:Foo", ledger=ledger) self.assertEqualLedgerPosting(converter.convert(ofx.account.statement.transactions[1]).format(), """2011/04/05 AUTOMATIC WITHDRAWAL, ELECTRIC BILL WEB(S ) Assets:Foo -$34.51 ; ofxid: 1101.1452687~7.0000487 Expenses:Bar $34.51 """)
def test_unknownaccount(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'checking.ofx'))) converter = OfxConverter(account=ofx.account, name="Foo", unknownaccount='Expenses:Unknown') self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.1452687~7.0000486 Expenses:Unknown -$0.01 """)
def test_dividend(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'income.ofx'))) converter = OfxConverter(account=ofx.account, name="Foo") self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[0]).format(), """2016/10/12 DIVIDEND RECEIVED ; dividend_from: cusip_redacted Foo $1234.56 ; ofxid: 1234.12345678.123456-01.redacted Income:Dividends -$1234.56 """)
def test_indent(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'checking.ofx'))) converter = OfxConverter(account=ofx.account, name="Foo", indent=4) # testing indent, so do not use the string collapsing version of assert self.assertEqual( converter.convert( ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.1452687~7.0000486 Expenses:Misc -$0.01 """)
def test_payee_match(self): ofx = OfxParser.parse( open(os.path.join('fixtures', 'checking-payee-match.ofx'))) ledger = Ledger(os.path.join('fixtures', 'checking.lgr')) converter = OfxConverter(account=ofx.account, name="Foo", ledger=ledger) self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[0]).format(), """2011/03/31 Match Payee Foo -$0.01 ; ofxid: 1101.1452687~7.0000489 Expenses:Bar $0.01 """)
def test_quote_commodity(self): with open(os.path.join('fixtures', 'fidelity.ofx'), 'rb') as ofx_file: ofx = OfxParser.parse(ofx_file) converter = OfxConverter(account=ofx.account, name="Foo", security_list=SecurityList(ofx)) self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[0]).format(), """2012/07/20 YOU BOUGHT Foo 100.00000 INTC @ $25.635000000 ; ofxid: 7776.01234567890.0123456789020201120120720 Assets:Unknown -$2563.50 Expenses:Commission $7.95 """)
def test_investments(self): with open(os.path.join('fixtures', 'fidelity.ofx'), 'rb') as ofx_file: ofx = OfxParser.parse(ofx_file) converter = OfxConverter(account=ofx.account, name="Foo", security_list=SecurityList(ofx)) self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[0]).format(), """2012/07/20 YOU BOUGHT Foo 100.00000 INTC @ $25.635000000 ; ofxid: 7776.01234567890.0123456789020201120120720 Assets:Unknown -$2563.50 Expenses:Commission $7.95 """) # test no payee/memo self.assertEqualLedgerPosting( converter.convert(ofx.account.statement.transactions[1]).format(), """2012/07/27 Foo: buystock Foo 128.00000 SDRL @ $39.390900000 ; ofxid: 7776.01234567890.0123456789020901120120727 Assets:Unknown -$5042.04 Expenses:Commission $7.95 """)
def test_quote_commodity(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'fidelity.ofx'))) converter = OfxConverter( account=ofx.account, name="Foo", security_list=SecurityList(ofx)) self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[0]).format(), """2012/07/20 YOU BOUGHT Foo 100.00000 INTC @ $25.635000000 ; ofxid: 7776.01234567890.0123456789020201120120720 Assets:Unknown -$2563.50 """)
def test_investments(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'fidelity.ofx'))) converter = OfxConverter( account=ofx.account, name="Foo", security_list=SecurityList(ofx)) self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[0]).format(), """2012/07/20 YOU BOUGHT Foo 100.00000 INTC @ $25.635000000 ; ofxid: 7776.01234567890.0123456789020201120120720 Assets:Unknown -$2563.50 """) # test no payee/memo self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[1]).format(), """2012/07/27 Foo: buystock Foo 128.00000 SDRL @ $39.390900000 ; ofxid: 7776.01234567890.0123456789020901120120727 Assets:Unknown -$5042.04 """)
def test_shortenaccount(self): with open(os.path.join('fixtures', 'checking.ofx'), 'rb') as ofx_file: ofx = OfxParser.parse(ofx_file) converter = OfxConverter(account=ofx.account, name="Foo", indent=4, shortenaccount=True) # testing indent, so do not use the string collapsing version of assert self.assertEqual( converter.convert(ofx.account.statement.transactions[0]).format(), """2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05% Foo $0.01 ; ofxid: 1101.87~7.0000486 Expenses:Misc -$0.01 """)
def test_dynamic_account(self): ofx = OfxParser.parse(open(os.path.join('fixtures', 'checking.ofx'))) ledger = Ledger( os.path.join( 'fixtures', 'checking-dynamic-account.lgr')) converter = OfxConverter( account=ofx.account, name="Assets:Foo", ledger=ledger) self.assertEqualLedgerPosting( converter.convert( ofx.account.statement.transactions[1]).format(), """2011/04/05 AUTOMATIC WITHDRAWAL, ELECTRIC BILL WEB(S ) Assets:Foo -$34.51 ; ofxid: 1101.1452687~7.0000487 Expenses:Bar $34.51 """)