beancount / smart_importer

Augment Beancount importers with machine learning functionality.
MIT License
248 stars 29 forks source link

I can't manage to have smart_importer working #88

Closed grostim closed 5 years ago

grostim commented 5 years ago

Hi!

I have probablbly missed something obvious, so please apologize if my question is stupid, but i have not been able to get smart_importer working.

Situation: I have a basic importer (QIF parser) that works well on its own. The QIF is properly parsed and all the transactions are added to my beancount file with a default posting account "Expense:ToBeClassified". After that i modify manually each posting to the relevant account.

Now i want to use smart_importer as i understand that it should automagically modify some of the postings with the proper account. Therefore, i have modified my import file as follows:

Famille.import:

#!/usr/bin/env python3
"""Example import configuration."""

# Insert our custom importers path here.
# (In practice you might just change your PYTHONPATH environment.)
import sys
from os import path
sys.path.insert(0, path.join(path.dirname(__file__)))

from importers.ImporterQIF import ImporterQIF
from beancount.ingest import extract
from smart_importer import apply_hooks, PredictPayees, PredictPostings
from beancount.ingest.importers import ofx

import logging
logging.getLogger('smart_importer').setLevel(logging.DEBUG)

# Setting this variable provides a list of importer instances.

ACCOUNTLIST = {
        '00040754305'       : 'Actif:Boursorama:CCJoint',
        '00040132901'       : 'Actif:Boursorama:CCTim',
        '00040239557'       : 'Actif:Boursorama:CCAnna',
    }

CONFIG = [
     apply_hooks(ImporterQIF(ACCOUNTLIST), [PredictPostings()]),
]

# Override the header on extracted text (if desired).
extract.HEADER = ';; -*- mode: org; mode: beancount; coding: utf-8; -*-\n'

When i import (with bean-extract Famille.import *.qif -f Famille.beancount ; or through fava), i don't have any error and the import is working propoerly... except that all my transactions remains with the default posting "Expense:ToBeClassified". Most of the transaction are redundant (i have for example transactions with the same amount and named with the same payee name that occur every month)

Am i missing something ? Please give me some pointers to understand what may happen.

Kind regards, Tim

tarioch commented 5 years ago

Just to be sure, is your importer using the extended interface which passes the existing entries?

def extract(self, file, existing_entries):

I think if it's not using this interface this might not get passed through the interceptor

grostim commented 5 years ago

Nope !

I think i have missed this. Where is it documented ?

grostim commented 5 years ago

ERRATUM: I just checked, and without knowing it, i was using it: def extract(self, file, existing_entries=None):

tarioch commented 5 years ago

Do you see any log output from smart importer? Maybe @johannesjh has any idea?

johannesjh commented 5 years ago

Hi Tim,

It seems to me that you are using smart_importer in a slightly different way... maybe this is the cause of frustration:

The QIF is properly parsed and all the transactions are added to my beancount file with a default posting account "Expense:ToBeClassified". After that i modify manually each posting to the relevant account.

Now i want to use smart_importer as i understand that it should automagically modify some of the postings with the proper account.

My approach in using smart_importer is to have it add missing postings, not to modify existing ones. In order to take the same approach, your ImporterQIF's extract method should return entries without default postings such as "Expense:ToBeClassified". Does this resolve your issue?

grostim commented 5 years ago

indeed ! I did not understood that the importer was supposed to post transactions with only one leg! Thank you for your help. It is working now!