Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues importing Yodlee into MS Money #6

Open
brucet opened this issue Apr 11, 2011 · 1 comment
Open

Issues importing Yodlee into MS Money #6

brucet opened this issue Apr 11, 2011 · 1 comment

Comments

@brucet
Copy link

brucet commented Apr 11, 2011

Thanks so much for this, this is exactly what I have been after!

However, in getting this working I had to work around a few issues.

  • My Yodlee csv file did not not have a Transaction Id column, and I got this error
    Using Default Mappings
    Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\csv2ofx__init__.py", line 219, in OnExport
    csv2ofx_export(path,mapping,grid)
    File "C:\Python27\lib\site-packages\csv2ofx\ofx.py", line 29, in export
    tran=dict([(k,mappingk) for k in ['DTPOSTED','TRNAMT','FITID','PAYEE','MEMO','CHECKNUM']])
    File "C:\Python27\lib\site-packages\csv2ofx\mappings.py", line 109, in
    'FITID':lambda row,grid: fromCSVCol(row,grid,'Transaction Id'),
    File "C:\Python27\lib\site-packages\csv2ofx\csvutils.py", line 62, in fromCSVCol
    return xmlize(grid.GetValue(row,grid.GetColPos(col_name)))
    File "C:\Python27\lib\site-packages\csv2ofx\csvutils.py", line 46, in GetColPos
    return self.col_map[col_name]
    KeyError: 'Transaction Id'

I got around this by simply adding a Transaction Id header column.

  • csv2ofx does not add OFX header
    I got errors importing the OFX file because MS Money seems to expect the following at the head of the document:

OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE

Once I added this, it went through.

  • I'm getting failures importing OFX files which contain multiple accounts.
    csv2ofx creates many elements within a single . When I changed this to define different accounts in different STMTTRNRS elements, I got around this problem.
@brucet
Copy link
Author

brucet commented Apr 11, 2011

Here is my modified ofx.py file (I don't know Python, so I may have messed something up, but so far it's worked for me!) Apologies for the weird markup, I don't understand this GitHub markup, and I couldn't see any way to attach a file.

from datetime import datetime
import time

def export ( path, mapping, grid):
"""
path: path to save the file
mapping: mapping selected from mappings.py
data: grid with csv data from csvutils.py
"""

accounts={}
today = datetime.now().strftime('%Y%m%d')
for row in range(grid.GetNumberRows()):
    # which account            
    if mapping['skip'](row,grid): continue

    uacct="%s-%s" % (mapping['BANKID'](row,grid), mapping['ACCTID'](row,grid))
    acct = accounts.setdefault(uacct,{})

    acct['BANKID'] = mapping['BANKID'](row,grid)
    acct['ACCTID'] = mapping['ACCTID'](row,grid)
    acct['TODAY'] = today
    acct['TRNUID'] = int(time.mktime(time.localtime()))
    currency = acct.setdefault('CURDEF',mapping['CURDEF'](row,grid))
    if currency != mapping['CURDEF'](row,grid):
        print "Currency not the same."
    trans=acct.setdefault('trans',[])
    tran=dict([(k,mapping[k](row,grid)) for k in ['DTPOSTED','TRNAMT','FITID','PAYEE','MEMO','CHECKNUM']])
    tran['TRNTYPE'] = tran['TRNAMT'] >0 and 'CREDIT' or 'DEBIT'
    trans.append(tran)


# output

out=open(path,'w')

out.write (
    """

OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE

    <OFX>
        <SIGNONMSGSRSV1>
           <SONRS>
            <STATUS>
                <CODE>0</CODE>
                    <SEVERITY>INFO</SEVERITY>
                </STATUS>
                <DTSERVER>%(DTSERVER)s</DTSERVER>
            <LANGUAGE>ENG</LANGUAGE>
        </SONRS>
        </SIGNONMSGSRSV1>
        <BANKMSGSRSV1>

    """ % {'DTSERVER':today}
)

for acct in accounts.values():
    out.write(
        """
        <STMTTRNRS>
            <TRNUID>%(TRNUID)d</TRNUID>
            <STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS>
        <STMTRS>
            <CURDEF>%(CURDEF)s</CURDEF>
            <BANKACCTFROM>
                <BANKID>%(BANKID)s</BANKID>
                <ACCTID>%(ACCTID)s</ACCTID>
                <ACCTTYPE>CHECKING</ACCTTYPE>
            </BANKACCTFROM>
            <BANKTRANLIST>
                <DTSTART>%(TODAY)s</DTSTART>
                <DTEND>%(TODAY)s</DTEND>

        """ % acct
    )

    for tran in acct['trans']:
        out.write (
            """
                    <STMTTRN>
                        <TRNTYPE>%(TRNTYPE)s</TRNTYPE>
                        <DTPOSTED>%(DTPOSTED)s</DTPOSTED>
                        <TRNAMT>%(TRNAMT)s</TRNAMT>
                        <FITID>%(FITID)s</FITID>

            """ % tran
        )
        if tran['CHECKNUM'] is not None and len(tran['CHECKNUM'])>0:
            out.write(
            """
                        <CHECKNUM>%(CHECKNUM)s</CHECKNUM>
            """ % tran
            )
        out.write(
            """
                        <NAME>%(PAYEE)s</NAME>
                        <MEMO>%(MEMO)s</MEMO>
            """ % tran
        )
        out.write(
            """
                    </STMTTRN>
            """
        )

    out.write (
        """
            </BANKTRANLIST>
            <LEDGERBAL>
                <BALAMT>0</BALAMT>
                <DTASOF>%s</DTASOF>
            </LEDGERBAL>
        </STMTRS>
        </STMTTRNRS>
        """ % today
    )

out.write ( "</BANKMSGSRSV1></OFX>" )
out.close()
print "Exported %s" % path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant