Customizing Your Importer

Basic, institution-specific importer code should be written to be shared within the plain text accounting community. However, one frequently needs to build customizations. beancount-reds-importers is written to be shared, but easily customized, simply by overriding the importer methods. Let us look at an example.

beancount-reds-importers is makes straightforward decisions where it can, and calls overridable methods to outsource more complex or custom decisions. An example is get_target_acct_custom(). You can write your own code, as simple or complex as it may be, to make a decision about the target posting for a transaction.

I make personal overrides like so in my my.import file that gets passed to bean-extract. The code below:

  • catches capital gains distributions based on the transaction memo (from the institution’s ofx file), and books them to the correct account
  • makes an exception for municipal bond income, booking them to a :Tax-Free: account, even if the asset is in a :Taxable: account
from beancount_reds_importers import vanguard
def get_target_acct_custom(self, transaction, ticker=None):
    if 'LT CAP GAIN' in transaction.memo:
        return self.config['capgainsd_lt']
    elif 'ST CAP GAIN' in transaction.memo:
        return self.config['capgainsd_st']
    else:
        target = self.target_account_map.get(transaction.type, None)
        if ticker and ticker == 'FMBIX' and target.startswith('Income:'):
            target = target.replace('Taxable', 'Tax-Free')
            return target
    return None
    
vanguard.Importer.get_target_acct_custom = get_target_acct_custom

Notes mentioning this note