beancount / ledger2beancount

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

Ignoring virtual postings does not discard posting metadata #189

Closed MarinBernard closed 4 years ago

MarinBernard commented 4 years ago

Hi,

When ledger2beancount is set to ignore virtual postings (default behaviour), metadata tags defined in the context of the ignored postings are still rendered as beancount tags. Shouldn't these tags be discarded as their parent posting ?

It's an annoying issue for me because I often define the same tag under several postings in a single transaction, which results in myriads of Duplicate posting metadata field errors in beancount.

Thank you!

tbm commented 4 years ago

Test case:

2020-05-29 * Metadata on virtual posting should be ignored
    Assets:Cash          -10.00 EUR
    Expenses:Food         10.00 EUR
      ; foo: bar
   (Expenses:Virtual)      2.00 EUR
      ; foo: baz
tbm commented 4 years ago

@MarinBernard thanks for pointing out this issue. It's not a scenario I considered because I don't use virtual postings. I'll see how I can best fix it.

MarinBernard commented 4 years ago

Thank you!

tbm commented 4 years ago

I don't want to simply discard all meta-data on virtual postings since there might be valuable information (and there might be comments) worth preserving.

So I will keep the meta-data but as a comment.

So in the example above you'd get:

2020-05-29 * "Metadata on virtual posting should be ignored"
  Assets:Cash          -10.00 EUR
  Expenses:Food         10.00 EUR
    foo: "bar"
    ; foo: baz

I hope that works.

MarinBernard commented 4 years ago

Yes, I think it would be fine, since beancount is expected to ignore such comments. Maybe you could also add a flag to the config file to control whether one wants to keep those metadata as comments ? I personally don't care since I only use beancount to feed fava, but I suppose other people would find it valuable.

tbm commented 4 years ago

I don't really want to add too many config options. But I made one change: I'll add a conversion note if there's a comment or meta-data on a virtual posting which is preserved as a comment.

If users are not happy, we can make more changes in the future.

Does ledger2beancount make it easy for you to use Fava? Are there any other improvements that would make it easier (if yes, best to open another issue).

tbm commented 4 years ago

Let me know if this works.

MarinBernard commented 4 years ago

Yes, it does work: all warnings vanished!

Yes, ledger2beancount is a huge time-saver for me. Fava is a great tool for data reporting, but from my point of view, beancount is still lacking too many features to replace ledger entirely (I make a heavy use of posting metadata, account aliases, virtual accounts, budgets and automatic transactions — none of them being supported at the moment). Since I didn't want to chose between both tools, I used to manually keep a distinct journal for each one, writing every transaction twice. Since I was bored to spend my whole life writing transactions, I began to write a very basic conversion script (full of regex spaghetti) to automate the conversion process, but the rendered file was still requiring manual edits. Then I found ledger2beancount, and my nightmare ended.

tbm commented 4 years ago

Thanks for the feedback @MarinBernard. It's always nice to hear how people use the tool.

Virtual postings will never happen but someone has written an envelope budgeting extension for Fava recently (in case that's what you use them for). Martin Blais is planning to rewrite the beancount parser in C++ soon and hopefully that will fix the meta-data for postings. Automation transactions are best solved with some plugins. I wonder if account aliases could be handled in your editor somehow.