CSV Importer: how to use read rows properly in categorizer

43 views
Skip to first unread message

vlam...@gmail.com

unread,
Dec 17, 2020, 12:15:48 PM12/17/20
to Beancount
Hi all,

I am wiriting an importer using the shipped CSV one. I wonder what's the proper way to read the row in the categorizer. Here is my current method:

def categorizer(txn, row) -> Transaction:
            # Fees column must be included to get correct balance
            if self.parse_amount(row[17]):  # Fee
                create_simple_posting(
                    entry=txn,
                    account='Expenses:Financial:Fees',
                    number=-(self.parse_amount(row[17])),
                    currency=currency
                )
                create_simple_posting(
                    entry=txn,
                    account=account,
                    number=self.parse_amount(row[17]),
                    currency=currency
                )
            # Balancing entry TODO: categorize
            create_simple_posting(
                entry=txn,
                account='Equity:Opening-Balances',
                number=None,
                currency=None
            )
            return txn

You need column index. Currently I can only hardcode it, which is not great. I could get it mapped in `iconfig`, simply pass something like `{ExtCol.Fee: fee_column_name}` in `config`, but I cannot get to `iconfig` in my class.

Is there currently any alternative?

Thanks,
Vlad


Reply all
Reply to author
Forward
0 new messages