beancount / ledger2beancount

Ledger to Beancount text-based converter
GNU General Public License v3.0
82 stars 15 forks source link

Comments in account declarations #179

Closed xuhcc closed 5 years ago

xuhcc commented 5 years ago

Currently ledger2beancount parses them incorrectly:

account Assets:Test     ; test

Results in:

;----------------------------------------------------------------------
; ledger2beancount conversion notes:
;
;   - Account Assets:Test     ; test renamed to Assets:Test-------test
;----------------------------------------------------------------------

1970-01-01 open Assets:Test-------test

I'm using comments to set account types for hledger:

https://hledger.org/journal.html#account-types-declared-with-tags

tbm commented 5 years ago

So in regular ledger this is actually invalid. It will parse everything about account as the account name:

account Assets:Test ; test
    check payee =~ /Test/

2019-01-01 * Tex
    Assets:Test               10.00 EUR
    Assets:Cash
ledger -f a bal --strict --explicit 
Warning: "/home/tbm/src/tbm/ledger2beancount/a", line 6: Unknown account 'Assets:Test'
Warning: "/home/tbm/src/tbm/ledger2beancount/a", line 7: Unknown account 'Assets:Cash'
                   0  Assets
          -10.00 EUR    Cash
           10.00 EUR    Test
--------------------
                   0

And with --debug:

   22ms  [DEBUG] Considering account: Assets:Test ; test

So it's unfortunate ledger and hledger don't have the same behaviour here. Although you could argue that ledger's behaviour is broken.

@simonmichael

I can fix ledger2beancount but I'm not sure if I should make it conditional on whether hledger parsing more is on. Arguably treating this a a comment is the right behaviour.

tbm commented 5 years ago

Hmm, the problem is that this is actually valid:

account Assets:Test ; test
    check payee =~ /Test/

2019-01-01 * Tex
    Assets:Test ; test          10.00 EUR
    Assets:Cash
ledger -f a   bal --strict --explicit  
Warning: "/home/tbm/src/tbm/ledger2beancount/a", line 7: Unknown account 'Assets:Cash'
Warning: "/home/tbm/src/tbm/ledger2beancount/a", line 7: Transaction check failed: (payee =~ /Test/)
                   0  Assets
          -10.00 EUR    Cash
           10.00 EUR    Test ; test
--------------------
                   0
simonmichael commented 5 years ago

Yes I think Ledger's behaviour should be changed here.

simonmichael commented 5 years ago

(I put my account comments on the next line to avoid this incompatibility. But I'd rather declare accounts with one line each.)