@@ -55,7 +55,7 @@ def find_ledger_file(ledgerrcpath=None):
55
55
return None
56
56
57
57
58
- def print_results (converter , ofx , ledger , txns , args ):
58
+ def print_results (converter , ofx , account_idx , ledger , txns , args ):
59
59
"""
60
60
This function is the final common pathway of program:
61
61
@@ -69,18 +69,18 @@ def print_results(converter, ofx, ledger, txns, args):
69
69
if (not (ledger .check_transaction_by_id
70
70
("ofxid" , converter .mk_ofxid (AUTOSYNC_INITIAL ))) and
71
71
not (ledger .check_transaction_by_id ("ofxid" , ALL_AUTOSYNC_INITIAL ))):
72
- print (converter .format_initial_balance (ofx .account .statement ))
72
+ print (converter .format_initial_balance (ofx .accounts [ account_idx ] .statement ))
73
73
for txn in txns :
74
74
print (converter .convert (txn ).format (args .indent ))
75
75
if args .assertions :
76
- print (converter .format_balance (ofx .account .statement ))
76
+ print (converter .format_balance (ofx .accounts [ account_idx ] .statement ))
77
77
78
78
# if OFX has positions use these to obtain commodity prices
79
79
# and print "P" records to provide dated/timed valuations
80
80
# Note that this outputs only the commodity price,
81
81
# not your position (e.g. # shares), even though this is in the OFX record
82
- if hasattr (ofx .account .statement , 'positions' ):
83
- for pos in ofx .account .statement .positions :
82
+ if hasattr (ofx .accounts [ account_idx ] .statement , 'positions' ):
83
+ for pos in ofx .accounts [ account_idx ] .statement .positions :
84
84
print (converter .format_position (pos ))
85
85
86
86
@@ -112,31 +112,44 @@ def import_ofx(ledger, args):
112
112
sync = OfxSynchronizer (ledger , hardcodeaccount = args .hardcodeaccount ,
113
113
shortenaccount = args .shortenaccount )
114
114
ofx = OfxSynchronizer .parse_file (args .PATH )
115
- txns = sync .filter (
116
- ofx .account .statement .transactions ,
117
- ofx .account .account_id )
118
- accountname = args .account
119
- if accountname is None :
120
- if ofx .account .institution is not None :
121
- accountname = "%s:%s" % (ofx .account .institution .organization ,
122
- ofx .account .account_id )
123
- else :
124
- accountname = UNKNOWN_BANK_ACCOUNT
125
115
126
- # build SecurityList (including indexing by CUSIP and ticker symbol)
127
- security_list = SecurityList (ofx )
116
+ account_idx = 0
117
+ for account in ofx .accounts :
118
+ txns = sync .filter (
119
+ account .statement .transactions ,
120
+ account .account_id )
121
+ try :
122
+ accountname = args .account [account_idx ]
123
+ except IndexError :
124
+ accountname = None
125
+ if accountname is None :
126
+ if account .institution is not None :
127
+ accountname = "%s:%s" % (account .institution .organization ,
128
+ account .account_id )
129
+ elif args .account_format is not None :
130
+ accountname = args .account_format .format (
131
+ account_id = account .account_id ,
132
+ account_type = account .account_type ,
133
+ routing_number = account .routing_number ,
134
+ branch_id = account .branch_id )
135
+ else :
136
+ accountname = "%s:%s" % (UNKNOWN_BANK_ACCOUNT , account_idx )
137
+
138
+ # build SecurityList (including indexing by CUSIP and ticker symbol)
139
+ security_list = SecurityList (ofx )
128
140
129
- converter = OfxConverter (account = ofx .account ,
130
- name = accountname ,
131
- ledger = ledger ,
132
- indent = args .indent ,
133
- fid = args .fid ,
134
- unknownaccount = args .unknownaccount ,
135
- payee_format = args .payee_format ,
136
- hardcodeaccount = args .hardcodeaccount ,
137
- shortenaccount = args .shortenaccount ,
138
- security_list = security_list )
139
- print_results (converter , ofx , ledger , txns , args )
141
+ converter = OfxConverter (account = account ,
142
+ name = accountname ,
143
+ ledger = ledger ,
144
+ indent = args .indent ,
145
+ fid = args .fid ,
146
+ unknownaccount = args .unknownaccount ,
147
+ payee_format = args .payee_format ,
148
+ hardcodeaccount = args .hardcodeaccount , #TODO
149
+ shortenaccount = args .shortenaccount , #TODO
150
+ security_list = security_list )
151
+ print_results (converter , ofx , account_idx , ledger , txns , args )
152
+ account_idx += 1
140
153
141
154
142
155
def import_csv (ledger , args ):
@@ -233,6 +246,14 @@ def run(args=None, config=None):
233
246
{tferaction} for OFX. If the input file is a CSV file,
234
247
substitutions are written using the CSV file column names
235
248
between {}.""" )
249
+ parser .add_argument (
250
+ '--account-format' ,
251
+ type = str ,
252
+ default = None ,
253
+ dest = 'account_format' ,
254
+ help = """Format string to use for generating the account line.
255
+ Substitutions can be written using {account_id}, {routing_number},
256
+ {branch_id}, {account_type} for OFX.""" )
236
257
parser .add_argument ('--python' , action = 'store_true' , default = False ,
237
258
help = 'use the ledger python interface' )
238
259
parser .add_argument ('--slow' , action = 'store_true' , default = False ,
0 commit comments