def import_ofx(ledger, args): sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) ofx = OfxSynchronizer.parse_file(args.PATH) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) accountname = args.account if accountname is None: if ofx.account.institution is not None: accountname = "%s:%s" % (ofx.account.institution.organization, ofx.account.account_id) else: accountname = UNKNOWN_BANK_ACCOUNT # build SecurityList (including indexing by CUSIP and ticker symbol) security_list = SecurityList(ofx) converter = make_ofx_converter(account=ofx.account, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount, security_list=security_list) print_results(converter, ofx, ledger, txns, args)
def import_ofx(ledger, args): sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) ofx = OfxSynchronizer.parse_file(args.PATH) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) accountname = args.account if accountname is None: if ofx.account.institution is not None: accountname = "%s:%s" % (ofx.account.institution.organization, ofx.account.account_id) else: accountname = UNKNOWN_BANK_ACCOUNT # build SecurityList (including indexing by CUSIP and ticker symbol) security_list = SecurityList(ofx) converter = make_ofx_converter(account=ofx.account, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount, security_list=security_list, date_format=args.date_format, infer_account=args.infer_account) print_results(converter, ofx, ledger, txns, args)
def test_fresh_sync(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse(file(os.path.join('fixtures', 'checking.ofx'))) txns1 = ofx.account.statement.transactions txns2 = sync.filter(ofx) self.assertEqual(txns1, txns2)
def test_fresh_sync(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse(open(os.path.join('fixtures', 'checking.ofx'))) txns1 = ofx.account.statement.transactions txns2 = sync.filter(txns1, ofx.account.account_id) self.assertEqual(txns1, txns2)
def test_apostrophe(self): ofxpath = os.path.join('fixtures', 'apostrophe.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEquals(len(txns), 1)
def test_one_settleDate(self): ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEquals(len(txns), 17)
def test_no_institution(self): ofxpath = os.path.join('fixtures', 'no-institution.ofx') sync = OfxSynchronizer(self.lgr) ofx = OfxSynchronizer.parse_file(ofxpath) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEquals(len(txns), 3)
def test_apostrophe(self): ofxpath = os.path.join('fixtures', 'apostrophe.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_no_institution(self): ofxpath = os.path.join('fixtures', 'no-institution.ofx') sync = OfxSynchronizer(self.lgr) ofx = OfxSynchronizer.parse_file(ofxpath) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 3)
def test_sync_order(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse( file(os.path.join('fixtures', 'checking_order.ofx'))) txns = sync.filter(ofx) self.assertTrue(txns[0].date < txns[1].date and txns[1].date < txns[2].date)
def test_comment_txns(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxSynchronizer.parse_file( os.path.join('fixtures', 'comments.ofx')) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_partial_sync(self): ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxSynchronizer.parse_file( os.path.join('fixtures', 'checking.ofx')) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_one_settleDate(self): ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 17)
def test_partial_sync(self): ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxSynchronizer.parse_file( os.path.join('fixtures', 'checking.ofx')) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_comment_txns(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxSynchronizer.parse_file( os.path.join('fixtures', 'comments.ofx')) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_sync_order(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse( open(os.path.join('fixtures', 'checking_order.ofx'))) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertTrue(txns[0].date < txns[1].date and txns[1].date < txns[2].date)
def test_accented_characters_latin1(self): ofxpath = os.path.join('fixtures', 'accented_characters_latin1.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) converter = OfxConverter(account=ofx.account, name="Foo") self.assertEqual(converter.format_payee(txns[0]), "Virement Interac à: Jean") self.assertEqual(len(txns), 1)
def test_sync_order(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse( open( os.path.join( 'fixtures', 'checking_order.ofx'))) txns = sync.filter( ofx.account.statement.transactions, ofx.account.account_id) self.assertTrue(txns[0].date < txns[1].date and txns[1].date < txns[2].date)
def import_ofx(ledger, args): sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) ofx = OfxSynchronizer.parse_file(args.PATH) if args.account != None and len(args.account) != len(ofx.accounts): sys.stderr.write( "number of account name (--account) does not match the number of accounts in the OFX file\n" ) exit(1) account_idx = 0 for account in ofx.accounts: txns = sync.filter(account.statement.transactions, account.account_id) try: accountname = args.account[account_idx] except (IndexError, TypeError): accountname = None if accountname is None: if account.institution is not None: accountname = "%s:%s" % (account.institution.organization, account.account_id) elif args.account_format is not None: accountname = args.account_format.format( account_id=account.account_id, account_type=account.account_type, routing_number=account.routing_number, branch_id=account.branch_id) else: accountname = "%s:%s" % (UNKNOWN_BANK_ACCOUNT, account_idx) # build SecurityList (including indexing by CUSIP and ticker symbol) security_list = SecurityList(ofx) converter = make_ofx_converter( account=account, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=args.hardcodeaccount, #TODO shortenaccount=args.shortenaccount, #TODO security_list=security_list) print_results(converter, ofx, ledger, txns, args, account_idx) account_idx += 1