sdementen / piecash

Pythonic interface to GnuCash SQL documents
Other
289 stars 74 forks source link

ledger-cli errors from piecash_ledger.py comment placement #5

Closed chrisberkhout closed 9 years ago

chrisberkhout commented 9 years ago

piecash_ledger.py (from piecash==0.8.2) is generating transactions such as this...

2014/01/01 * WITHDRAWAL AT HANDYBANK MELB CTL 5 O/S 25420178 01/01/14
;OFX ext. info: |Trans type:Cash withdrawal
    Assets:Current:Westpac SAV                  -180.00 AUD ;   WITHDRAWAL AT HANDYBANK MELB CTL 5 O/S 25420178 01/01/14
    Expenses:Unspecified:AUD                     180.00 AUD

Note that the second line is a comment with extra information from the OFX import of the transaction.

Ledger 3.1.0-20141005 rejects that with errors such as:

While parsing file "", line 5367:
Error: Unexpected whitespace at beginning of line

where the line number refers to the line following the comment (the line beginning Assets in the example above).

My work-around is to strip those comment lines with grep:

piecash_ledger.py Accounts.gnucash | grep -v ^\; | ledger -f -

It might be better to put such comments on the same line as the transaction description.

chrisberkhout commented 9 years ago

PS. piecash seems really great! I'm just starting to build some other scripting on top of it. Thanks for building and publishing it! The docs are outstanding too!

sdementen commented 9 years ago

Glad you find piecash useful.

Regarding the piecash_ledger script, I wrote it without any real experience with ledger, just reading the ledger docs and getting the inspiration from the script https://github.com/MatzeB/pygnucash/blob/master/gnucash2ledger.py. From the ledger docs, I read about the comment syntax here: http://www.ledger-cli.org/3.0/doc/ledger3.html#Commenting-on-your-Journal .

So I wonder if the bug is not that the comment is not idented properly (it starts without any spaces). Could you see if the following would be accepted by ledger ?

2014/01/01 * WITHDRAWAL AT HANDYBANK MELB CTL 5 O/S 25420178 01/01/14
    ;OFX ext. info: |Trans type:Cash withdrawal
    Assets:Current:Westpac SAV                  -180.00 AUD ;   WITHDRAWAL AT HANDYBANK MELB CTL 5 O/S 25420178 01/01/14
    Expenses:Unspecified:AUD                     180.00 AUD
chrisberkhout commented 9 years ago

Yes, you're right. I just tried prepending tabs to those lines and ledger is happy with that :)

sdementen commented 9 years ago

Great ! I saw your pull request on github. As I never handled such request, I will try tomorrow to "integrate" it properly ;-) And thank you for contributing !

On Saturday, June 20, 2015, Chris Berkhout notifications@github.com wrote:

Yes, you're right. I just tried prepending tabs to those lines and ledger is happy with that :)

— Reply to this email directly or view it on GitHub.< https://ci5.googleusercontent.com/proxy/xvHK8ps1fBl-wA5LSWAHwd8XSfcCTFdbd7DpMaCqSYWT4_YzUvpMlPwxzzjAUji79ScQVOUV19doauZCSBJkdhEWkeZh-i2nvNQruFMzh2hIWnp_X2fZ9MtvpQHf6FHf7I8-CzaprXHkSOJjt6dM667WjEvzWg=s0-d-e1-ft#https://github.com/notifications/beacon/ABPpdnrSCKJxFnmdXXZY83C-os6iZihwks5oVVB5gaJpZM4FH1uG.gif

chrisberkhout commented 9 years ago

Thanks!