beancount / ledger2beancount

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

Use ledger's transaction description as beancount's payee #237

Closed delexi closed 3 years ago

delexi commented 3 years ago

I have this ledger transaction:

2020/03/06 * Deutsche Bahn
    ; thing: 7B6E33
    Expenses:Transport:Zug                    €3.85
    Assets:Giro

And I want ledger2beancount to convert it into this beancount transaction:

2020-03-06 * "Deutsche Bahn" "7B6E33"
  Expenses:Transport:Zug                    3.85 €
  Assets:Giro

Note that ledger's transaction description shall used as beancount's payee field. The narration shall be taken from a metadata tag called "thing".

For now, I only managed to turn the metadata tag "thing" into the payee with payee_tag. How do I tell ledger2beancount to turn "thing" into the narration and ledger's description into beancount's payee?

tbm commented 3 years ago

How do I tell ledger2beancount to turn "thing" into the narration and ledger's description into beancount's payee?

I don't think this is possible at the moment.

Where does "thing" come from in the first place? Who creates that metadata?

delexi commented 3 years ago

The "thing" metadata was created by me manually while entering transactions. It serves as extra context information to the transaction. Very much like the narration feature of beancount. In the example above, thing contains the ticket number of the ticket I bougt at the german railway provider "Deutsche Bahn".

Am 14. November 2020 01:01:24 MEZ schrieb Martin Michlmayr notifications@github.com:

How do I tell ledger2beancount to turn "thing" into the narration and ledger's description into beancount's payee?

I don't think this is possible at the moment.

Where does "thing" come from in the first place? Who creates that metadata?

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/beancount/ledger2beancount/issues/237#issuecomment-727092212

tbm commented 3 years ago

I guess adding a narration_tag config option similar to payee_tag is the way to go.

I don't really like the idea of adding yet another option for something so specific (I recently wondered if payee_tag was a good idea); I was thinking of a more generic solution but looking at the code it's not easy to implement.

delexi commented 3 years ago

As I have come to this tool only yesterday my understanding of any implementation trade-offs is very limited. From a user perspective, narration_tag was something I was actively looking for in the documentation before I posted this issue.

Taking a step back, a general solution might be to have yet another map that allows the user to map ledger metadata tags to beancount concepts. But as I said, I have no idea whether this is a reasonable suggestion.

tbm commented 3 years ago

I wrote a patch for narration_tag, but I'm still not sure if I want to add that or whether I should try to implement the more elegant solution I had in mind (or do both). For the latter I have to refactor the code but I have other things I should do today. (I'll try to take another look tomorrow)

In the meantime, you can try the "narration" branch here: https://github.com/tbm/ledger2beancount/tree/narration which has narration_tag.

tbm commented 3 years ago

@delexi @zacchiro maybe you can give me feedback on my other idea. The basic idea is to load metadata and other information about the transaction (e.g. payee) into a hash (dict); also allow users to regex match and load stuff into that dict.

And then have payee and narration that describes a format string where you can use the variables from the dict.

So in this example it would be:

payee: "%(payee)s"
narration: "%(thing)s"

This might be a more elegant solution to the current payee_split too.

(This is basically inspired by how to do things in Python)

delexi commented 3 years ago

From where I am standing, this looks like a cleaner solution compared to several "adhoc"-feeling specialized settings like payee_tag or payee_split. I like it.

delexi commented 3 years ago

I wrote a patch for narration_tag, but I'm still not sure if I want to add that or whether I should try to implement the more elegant solution I had in mind (or do both). For the latter I have to refactor the code but I have other things I should do today. (I'll try to take another look tomorrow)

In the meantime, you can try the "narration" branch here: https://github.com/tbm/ledger2beancount/tree/narration which has narration_tag.

I tested your branch. Here is what it produces for the example above:

option "operating_currency" "EUR"
2010-03-01 open Assets:Giro
2010-03-01 open Expenses:Transport:Zug

2010-03-01 commodity EUR

2020-11-13 * "7B6E33"
  Expenses:Transport:Zug                    3.85 EUR
  Assets:Giro

Now, the narration is taken from the thing tag, which is what I want. But this version has no way of setting beancount's payee to ledger's description. payee_tag can only target metadata tags, right?

EDIT: If I set payee_split to - (?<payee>.*) and narration_tag to thing, I get the following (desired) output:

option "operating_currency" "EUR"
2010-03-01 open Assets:Giro
2010-03-01 open Expenses:Transport:Zug

2010-03-01 commodity EUR

2020-11-13 * "Deutsche Bahn" "7B6E33"
  Expenses:Transport:Zug                    3.85 EUR
  Assets:Giro
tbm commented 3 years ago

If I set payee_split to - (?.*) and narration_tag to thing, I get the following (desired) output:

Sorry, I should have mentioned that!

tbm commented 3 years ago

Sorry, I was a bit too optimistic when I wrote "Monday". At least I've completed the refactoring work now, so I can look into implementing this feature soon.

In the meantime, I'd be curious about your usage of ledger2beancount. Are you using it to use ledger and beancount in parallel, to migrate to beancount, etc...? And if you have other bugs or suggestions, please feel free to open other issues.

delexi commented 3 years ago

Sorry, I was a bit too optimistic when I wrote "Monday". At least I've completed the refactoring work now, so I can look into implementing this feature soon.

I don't think you mentioned anything about Monday. And even if you did, there is no expectation from my side that you or anyone should immediately jump on an issue I am having. Nevertheless I very much appreciate your quick and helpful responses and fixes! :)

As to my usage, I use ledger2beancount to migrate from ledger to beancount. I also use Cone on Android to track my cash expenses on the go. That tool outputs ledger files for the forseeable future, thus my current plan is to use l2b to convert those to beancount format.

tbm commented 3 years ago

I never heard of Cone. Thanks for mentioning that.

tbm commented 3 years ago

So I implemented it locally, but... looking at the whole picture again, I think I will just go with narration_tag instead.

While the other idea I proposed is more elegant, it doesn't really fit so well into all the other config variables we have for payee/narration already. If I'd start from scratch, I think I'd implement it this way. But given where we are, adding a narration_tag seems like the more natural approach.