Need help converting from gnucash

583 views
Skip to first unread message

melb...@gmail.com

unread,
Aug 30, 2017, 12:26:08 PM8/30/17
to Beancount
I'd love to try beancount but I seem to be stuck trying to convert my data from gnucash. I am using https://github.com/debanjum/gnucash-to-beancount to convert 4 years of gnucash data. When I run bean-check on the result file, I get a ton of errors that look like

/home/user1/beancount/foo.beancount:4505:    Invalid token: 'taxed'
/home/user1/beancount/foo.beancount:4517:    syntax error, unexpected COLON, expecting EOL or COMMENT or ATAT or AT
/home/user1/beancount/foo.beancount:4517:    Invalid token: 'k'
/home/user1/beancount/foo.beancount:4522:    Invalid token: 'taxed'
/home/user1/beancount/foo.beancount:4532:    syntax error, unexpected COLON, expecting EOL or COMMENT or ATAT or AT
/home/user1/beancount/foo.beancount:4532:    Invalid token: 'k'
/home/user1/beancount/foo.beancount:4537:    Invalid token: 'taxed'
/home/user1/beancount/foo.beancount:4547:    syntax error, unexpected COLON, expecting EOL or COMMENT or ATAT or AT
/home/user1/beancount/foo.beancount:4547:    Invalid token: 'k'
/home/user1/beancount/foo.beancount:4552:    Invalid token: 'taxed'
/home/user1/beancount/foo.beancount:4566:    syntax error, unexpected COLON, expecting EOL or COMMENT or ATAT or AT
/home/user1/beancount/foo.beancount:4566:    Invalid token: 'k'
/home/user1/beancount/foo.beancount:4571:    Invalid token: 'taxed'
/home/user1/beancount/foo.beancount:4581:    syntax error, unexpected COLON, expecting EOL or COMMENT or ATAT or AT
/home/user1/beancount/foo.beancount:4581:    Invalid token: 'k'
/home/user1/beancount/foo.beancount:4586:    Invalid token: 'taxed'

followed by a ton of results like this

/home/user1/beancount/foo.beancount:1168:    Invalid reference to inactive account 'Expenses:House:Appliances-and-Furniture'

   2014-011-06 * "AMAZON.COM          AMZN.COM/BI - Vornado fan"
     notes: "OFX ext. info: |Trans type:Generic debit|Memo:FOOBAR MERCHANDISE"
     num: "12345023456233"
     Liabilities:American-Express             -107.760 USD
       memo: "FOOBAR MERCHANDISE"
     Expenses:House:Appliances-and-Furniture   107.760 USD

melb...@gmail.com

unread,
Aug 30, 2017, 12:31:16 PM8/30/17
to Beancount, melb...@gmail.com
For what it's worth I have also tried gnucash2ledger and then ledger2beancount, but I get similar errors.

melb...@gmail.com

unread,
Aug 30, 2017, 2:05:17 PM8/30/17
to Beancount, melb...@gmail.com
Okay, I was finally able to run bean-check without any errors. I will write down things I did in hopes that it will help someone else. I wouldn't have been able to do with without folks on the IRC channel, they were really helpful.

The gnucash-to-beancount script opens all the accounts at the beginning of the file but on some accounts the dates are later then some of the transactions in the file, which produces the inactive account error. I changed the dates for the opening statements to when the earliest transaction was for that account. Then basically iterate this for the rest of the accounts with the same error.

Another big problem was that fact that I had a lot of account names that are valid in gnucash which aren't valid in beancount.
  * Accounts starting with lowercase
  * Accounts starting with numbers
  * Accounts with & in their name (e.g., Expenses:Gas-&-Electric)
  * Accounts with apostrophes

Martin Blais

unread,
Aug 31, 2017, 3:03:11 AM8/31/17
to Beancount
On Wed, Aug 30, 2017 at 2:05 PM, <melb...@gmail.com> wrote:
Okay, I was finally able to run bean-check without any errors. I will write down things I did in hopes that it will help someone else. I wouldn't have been able to do with without folks on the IRC channel, they were really helpful.

That's great!

 
The gnucash-to-beancount script opens all the accounts at the beginning of the file but on some accounts the dates are later then some of the transactions in the file, which produces the inactive account error. I changed the dates for the opening statements to when the earliest transaction was for that account. Then basically iterate this for the rest of the accounts with the same error.

This would cause the second error you reported indeed. Beancount ignores the location of the directives in the file (on purpose).


Another big problem was that fact that I had a lot of account names that are valid in gnucash which aren't valid in beancount.
  * Accounts starting with lowercase
  * Accounts starting with numbers
  * Accounts with & in their name (e.g., Expenses:Gas-&-Electric)
  * Accounts with apostrophes

That's correct.
I think the converter script could be modified to make reasonable account name conversions.


 

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/fa929358-330c-4085-a3cf-9719be0e816b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

andrew...@gmail.com

unread,
Dec 4, 2017, 12:25:31 AM12/4/17
to Beancount
I encountered similar issues using Herique Bastos's gnucash-tobeancount (https://github.com/henriquebastos/gnucash-to-beancount) and have seen debanjum's changes (https://github.com/debanjum/gnucash-to-beancount).

Personally, I am using Gnucash with 17 years of data as my "master" data and doing frequent exports to beancount. I was very reluctant to change the Gnucash data. For this I modified my own copy of gnucash-to-beancount. Seeing this thread inspired me to clean up my work and push it out to github.
This version handles:
  • Many types of special characters in account and commodity names (spaces, commas, slash, underscore, period, percent, @, &, +, ?, ', (, ), ¢).
    •  Joe's -> Joes
    • 401(k) -> 401k
    • CD @ 2% -> CD-at-2-pct
  • Account names that start with '-' or a digit (401k -> X-401k)
  • Account names that start with lower case (iBond -> IBond)
  • Commodity names that have lower case or dashes or are longer than 24 characters.
  • Notes with double quotes (")
  • Accounts are open on the date of the first transaction
  • Gnucash's hidden accounts are considered closed. I added close directives for these.
  • Accounts are closed on the day after the last transaction
  • Skipping of Gnucash's placeholder accounts
  • Commodity precision is retrieved from Gnucash
If anyone is interested, please give it a whirl. The code is at https://github.com/AndrewStein/gnucash-to-beancount 
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

melb...@gmail.com

unread,
Dec 4, 2017, 12:28:20 PM12/4/17
to Beancount
Thanks for this

Andrew Stein

unread,
Dec 4, 2017, 9:17:41 PM12/4/17
to bean...@googlegroups.com
enjoy!

Andrew Stein

3555 Orchard Lane
Minnetonka, MN 55305
(952) 546 7684
Andrew...@GMail.com

--
You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beancount/MaaASKR1SSI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Martin Blais

unread,
Dec 9, 2017, 8:16:22 PM12/9/17
to Beancount
I added this to the contributions index.
Thanks!


To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Jason Chu

unread,
Dec 9, 2017, 8:19:29 PM12/9/17
to bean...@googlegroups.com

I can report that this was able to convert my 2014 and 2015 files no problem. Now I just have to backport all the transactions...

So thanks for that. ;)


enjoy!
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.

andrew...@gmail.com

unread,
Dec 18, 2017, 9:24:09 PM12/18/17
to Beancount
I have created a pull request for my changes: https://github.com/henriquebastos/gnucash-to-beancount/pull/8
Let's see if Henrique bites.


On Saturday, December 9, 2017 at 7:19:29 PM UTC-6, Jason Chu wrote:

I can report that this was able to convert my 2014 and 2015 files no problem. Now I just have to backport all the transactions...

So thanks for that. ;)


On Sat, Dec 9, 2017, 5:16 PM Martin Blais <bl...@furius.ca> wrote:
I added this to the contributions index.
Thanks!

On Mon, Dec 4, 2017 at 9:17 PM, Andrew Stein <andrew...@gmail.com> wrote:
enjoy!

Andrew Stein




Henrique Bastos

unread,
Dec 19, 2017, 5:45:51 AM12/19/17
to Beancount
Wow, that's pretty awesome. I'll definitely review and merge this asap (hopefully during my Holliday spare time). Thank you very much for your contribution.

falsi...@gmail.com

unread,
May 25, 2020, 5:28:42 PM5/25/20
to Beancount
I just ran gnucash-to-beancount but had to do some fiddling for it to work. Posting these notes in case it helps someone in the future. (Sorry to revive this ancient thread, but it comes up in search results and seems like an appropriate place for the information.)

My changes (on top of Andrew's commits) are at https://github.com/falsifian/gnucash-to-beancount but you probably don't want all of them. Also I had to do one hack which is not included as a git commit.
  • I edited setup.py to force piecash to be at exactly version 0.15.0. (Otherwise test.sh fails because newer piecash versions can't read data/sample.gnucash. It would probably be better to update that, but I was having some other issues; read on...)
  • piecash (even newer versions) complained about my GnuCash file, saying "AssertionError: Unsupported table versions". To fix this, I made the following changes on a copy of my GnuCash file. (File created with GnuCash 3.8; the values before the changes were 3000010 and 5 respectively.)
    • *** DON'T DO THIS TO YOUR MAIN GNUCASH FILE ***
    • sqlite3 (gnucash copy)
    • sqlite> update versions set table_version = 3000010 where table_name = 'Gnucash';
    • sqlite> update versions set table_version = 4 where table_name = 'splits';
  • My own quirks / conveniences; you may want to skip these:
    • If you're using nixpkgs, you might find the shell.nix I added convenient. (Just run 'nix-shell' and you'll get a shell where you can run the gnucash-to-beancount command.)
    • I changed directives.py so that all the account names now contain "GnuCash". This is the part you are least likely to want. I did it because I want to go through all my accounts and rename them if I end up switching to beancash, and this will be a way of keeping track of which accounts still have their old names.
    • I added "gnucash_guid" metadata fields to transactions, commodities, prices and accounts (in the "open" directive). I'm not sure whether I'll use these, but they're there just in case. This will tell me which things I imported from GnuCash, and could conceivably be useful if I end up making changes to my original GnuCash file and want to see what should be updated in my beancount file.

Chary Chary

unread,
May 27, 2020, 3:20:43 AM5/27/20
to Beancount
James,

thanks for input:


  • piecash (even newer versions) complained about my GnuCash file, saying "AssertionError: Unsupported table versions". 


Apparently there is a version, where it is fixed: https://github.com/jreynolds01/piecash

Anand Gupta

unread,
Aug 1, 2020, 1:41:13 AM8/1/20
to Beancount
I just converted three and half years worth of gnucash file into beancount. Really happy! I am using Gnucash 3.8 and struggled for few hours with gnucash-to-beancount and piecash installed by pip.

I had to build and install locally from https://github.com/jreynolds01/piecash and https://github.com/AndrewStein/gnucash-to-beancount . It will be nice if these changes are incorporated in the official pip packages.

I just came to know about beancount from the news.ycombinator.com couple of days back.  Loved the explanation of double entry accounting at https://beancount.github.io/docs/the_double_entry_counting_method.html

I have another gnucash file but that one is in xml format. So will be working on figuring out how to convert that to beancount.


Thanks,
Anand

James Cook

unread,
Aug 1, 2020, 3:09:43 AM8/1/20
to bean...@googlegroups.com

I have another gnucash file but that one is in xml format. So will be working on figuring out how to convert that to beancount.

I converted from XML by first using gnucash to save in the other format.


James

Anand Gupta

unread,
Aug 1, 2020, 10:32:27 AM8/1/20
to Beancount
Thanks! I could use  File->'Save As' to save the gnucash xml file into sqlite format.
Also I just had a top level income category in gnucash. Bean-check did not like it. So I created an Income:Revenue account at top,
and changed all the income entries to Income:Revenue.

The notes url  link below did not work for me though.

Best regards,
Anand


On Saturday, August 1, 2020 at 2:09:43 AM UTC-5, James Cook wrote:

I have another gnucash file but that one is in xml format. So will be working on figuring out how to convert that to beancount.

I converted from XML by first using gnucash to save in the other format.

Henrique Bastos

unread,
Aug 4, 2020, 8:33:57 AM8/4/20
to bean...@googlegroups.com
I'm no longer working on gnucash-to-beancount. I can either point to Andrew's repo or somehow give Andrew access to edit and maintain the release on pypi.

On Sat, Aug 1, 2020 at 11:32 AM Anand Gupta <anand.p...@gmail.com> wrote:
Thanks! I could use  File->'Save As' to save the gnucash xml file into sqlite format.
Also I just had a top level income category in gnucash. Bean-check did not like it. So I created an Income:Revenue account at top,
and changed all the income entries to Income:Revenue.

The notes url  link below did not work for me though.

Best regards,
Anand

On Saturday, August 1, 2020 at 2:09:43 AM UTC-5, James Cook wrote:

I have another gnucash file but that one is in xml format. So will be working on figuring out how to convert that to beancount.

I converted from XML by first using gnucash to save in the other format.

You received this message because you are subscribed to a topic in the Google Groups "Beancount" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beancount/MaaASKR1SSI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beancount+...@googlegroups.com.

James Cook

unread,
Aug 4, 2020, 12:23:42 PM8/4/20
to bean...@googlegroups.com
> The notes url link below did not work for me though.

It's just a link to this same thread. I didn't realize it was the same
thread when I posted the link. My May 25 post has some notes.

James
Reply all
Reply to author
Forward
0 new messages