From 327493be3ec5e5487a979e12e656b70a21ffb5fe Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 15 Apr 2020 11:11:46 +1000 Subject: [PATCH] Record posting states --- ledger_pyreport/ledger.py | 6 +++--- ledger_pyreport/model.py | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ledger_pyreport/ledger.py b/ledger_pyreport/ledger.py index d5a9938..b452ce4 100644 --- a/ledger_pyreport/ledger.py +++ b/ledger_pyreport/ledger.py @@ -90,10 +90,10 @@ def raw_transactions_at_date(date): ledger = Ledger(date) ledger.prices = get_pricedb() - output = run_ledger_date(date, 'csv', '--csv-format', '%(quoted(parent.id)),%(quoted(format_date(date))),%(quoted(parent.code)),%(quoted(payee)),%(quoted(account)),%(quoted(display_amount)),%(quoted(comment))\n') + output = run_ledger_date(date, 'csv', '--csv-format', '%(quoted(parent.id)),%(quoted(format_date(date))),%(quoted(parent.code)),%(quoted(payee)),%(quoted(account)),%(quoted(display_amount)),%(quoted(comment)),%(quoted(state))\n') reader = csv.reader(output.splitlines(), dialect='ledger') - for trn_id, date_str, code, payee, account_str, amount_str, comment in reader: + for trn_id, date_str, code, payee, account_str, amount_str, comment, state_str in reader: if not ledger.transactions or trn_id != ledger.transactions[-1].id: transaction = Transaction(ledger, trn_id, datetime.strptime(date_str, '%Y-%m-%d'), payee, code=code) ledger.transactions.append(transaction) @@ -105,7 +105,7 @@ def raw_transactions_at_date(date): comment = comment[comment.index(';')+1:].strip() amount = parse_amount(amount_str) - posting = Posting(transaction, ledger.get_account(account_str), amount, comment=comment) + posting = Posting(transaction, ledger.get_account(account_str), amount, comment=comment, state=Posting.State(int(state_str))) transaction.postings.append(posting) if amount.commodity.name not in ledger.commodities: diff --git a/ledger_pyreport/model.py b/ledger_pyreport/model.py index e936ffc..c59c71e 100644 --- a/ledger_pyreport/model.py +++ b/ledger_pyreport/model.py @@ -17,6 +17,7 @@ from .config import config from decimal import Decimal +from enum import Enum import functools class Ledger: @@ -83,11 +84,17 @@ class Transaction: return '\n'.join(result) class Posting: - def __init__(self, transaction, account, amount, comment=None): + class State(Enum): + UNCLEARED = 0 + CLEARED = 1 + PENDING = 2 + + def __init__(self, transaction, account, amount, comment=None, state=State.UNCLEARED): self.transaction = transaction self.account = account self.amount = Amount(amount) self.comment = comment + self.state = state def __repr__(self): return ''.format(self.account.name, self.amount.tostr(False))