Skip to content

Commit

Permalink
feat: add 'show_configured' in paycheck transaction builder
Browse files Browse the repository at this point in the history
This lists all entries in the paycheck which are being ignored by the
current configuration. This is useful when new items appear on the
paycheck and the configuration needs to be appended with it.
  • Loading branch information
redstreet committed Mar 15, 2024
1 parent 92b5184 commit 80afa1b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions beancount_reds_importers/libtransactionbuilder/paycheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from beancount.core import data
from beancount.core.number import D
from beancount_reds_importers.libtransactionbuilder import banking

from collections import defaultdict

# paychecks are typically transaction with many (10-40) postings including several each of income, taxes,
# pre-tax and post-tax deductions, transfers, reimbursements, etc. This importer enables importing a single
Expand Down Expand Up @@ -66,15 +66,19 @@ def build_postings(self, entry):
template = self.config['paycheck_template']
currency = self.config['currency']
total = 0
template_missing = defaultdict(set)

for section, table in self.alltables.items():
if section not in template:
template_missing[section] = set()
continue
for row in table.namedtuples():
# TODO: 'bank' is workday specific; move it there
row_description = getattr(row, 'description', getattr(row, 'bank', None))
row_pattern = next(filter(lambda ts: row_description.startswith(ts), template[section]), None)
if row_pattern:
if not row_pattern:
template_missing[section].add(row_description)
else:
accounts = template[section][row_pattern]
accounts = [accounts] if not isinstance(accounts, list) else accounts
for account in accounts:
Expand All @@ -89,6 +93,14 @@ def build_postings(self, entry):
total += amount
if amount:
data.create_simple_posting(entry, account, amount, currency)

if self.config.get('show_unconfigured', False):
for section in template_missing:
print(section)
if template_missing[section]:
print(' ' + '\n '.join(i for i in template_missing[section]))
print()

if total != 0:
data.create_simple_posting(entry, "TOTAL:NONZERO", total, currency)

Expand Down

0 comments on commit 80afa1b

Please sign in to comment.