jbms / beancount-import

Web UI for semi-automatically importing external data into beancount
GNU General Public License v2.0
391 stars 100 forks source link

GenericImporterSource - which data/field is used for the source_desc field? #204

Open kosli opened 1 year ago

kosli commented 1 year ago

I have written a GenericImporter for my bank statements and I am automatically setting the payee and narration based on my "raw" data / statements.

Sometimes I leave the narration empty, which seems to be a problem with beancount-importer. It seems that the narration field is used/copied to the source_desc field which is used for the recognition of already confirmed transactions.

As my bank statements have their "raw" data which I would like for the source_desc matching, I tried to add them straight as metadata, but they are getting overwritten by beancount-importer.

How can i define what beancount-importer uses for the source_desc field?

kosli commented 1 year ago

I see the description in the GenericImporter and how the source_desc is being set -> https://github.com/jbms/beancount-import/blob/master/beancount_import/source/generic_importer_source.py As this is hardcoded, it means I would need to create my own GenericImporter in case I wanna use my "raw" data for the source_desc, or if I wanna be able to use empty narration fields, which is valid beancount syntax: https://beancount.github.io/docs/beancount_language_syntax.html#payee-narration So maybe the generic importer should be changed to rely on a combination of payee AND narration? (Or have the source_desc set / overriden by the custom importer)

kosli commented 7 months ago

Any update/feedback on this? Thanks.

dumbPy commented 7 months ago

@kosli You may raise a PR to allow importers to set source_descby changing this

            if isinstance(posting.meta, dict):
                posting.meta["source_desc"] = entry.narration
                posting.meta["date"] = entry.date

to

            if isinstance(posting.meta, dict):
                posting.meta.setdefault("source_desc", entry.narration)
                posting.meta.setdefault("date", entry.date)

So it sets narration to source_desc only if source_desc isn't already set by the importer, and similarly for date