Thank you very much for the codes. It worked. I tested on two sample csv files from two banks with different patches. No interference between them.
Just one last nag. The pytest won't pass when I let it tests all importers. It is obvious one patch is affecting the other. Pytest can pass if I specify the importer subfolder like this and both will pass: pytest -v importers/bank1 pytest -v importers/bank2 But it will fail if test them all pytest -v importers Any pointer for this? Thanks! On Tuesday, May 19, 2020 at 7:17:23 PM UTC-4, [email protected] wrote: > > I would create an importer module for your institution, in say > importers/institution/csv.py. Make sure you indicate these directories as > Python packages with appropriate __init__ files. > > In that module import the built-in csv import module: > from beancount.ingest.importers import csv > > Subclass the Importer defined in that module: > class Importer(csv.Importer): > Define your column mapping config, decorators and other jazz. Monkey patch > functions in the csv module. In my case I chain a couple of decorators: > csv.get_amounts = normalise(ignore_pending(csv.get_amounts)) > Import and set config for your new importer class in your importer config > module. > > This won't trample the get_amounts function "seen" by other importers. > > On Wednesday, May 20, 2020 at 3:19:17 AM UTC+10, [email protected] wrote: >> >> >> >> Thanks for the code. I was doing essentially the same thing as yours. But >> as you mentioned, I did get tripped by the patching. >> >> I have two different bank statements needing two different patches. And >> one importer indeed changes the behavior of the other. Any suggestion how >> to do it properly? Thanks! >> >> W.E. >> >> On Saturday, May 16, 2020 at 10:00:44 PM UTC-4, [email protected] >> wrote >> >> If you haven't got a good handle on how Python namespaces work, you may >>> get tripped up by monkey patching. Spend a bit of time getting familiar >>> with it. You'll change the behaviour of your other importers depending on >>> the CSV module if you're not careful. >>> >>> >>> -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/6ec9eb81-f865-4132-bc8e-71b55659ea19%40googlegroups.com.
