Record posting states

This commit is contained in:
RunasSudo 2020-04-15 11:11:46 +10:00
parent c87e1c3a70
commit 327493be3e
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 11 additions and 4 deletions

View File

@ -90,10 +90,10 @@ def raw_transactions_at_date(date):
ledger = Ledger(date) ledger = Ledger(date)
ledger.prices = get_pricedb() 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') 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: 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) transaction = Transaction(ledger, trn_id, datetime.strptime(date_str, '%Y-%m-%d'), payee, code=code)
ledger.transactions.append(transaction) ledger.transactions.append(transaction)
@ -105,7 +105,7 @@ def raw_transactions_at_date(date):
comment = comment[comment.index(';')+1:].strip() comment = comment[comment.index(';')+1:].strip()
amount = parse_amount(amount_str) 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) transaction.postings.append(posting)
if amount.commodity.name not in ledger.commodities: if amount.commodity.name not in ledger.commodities:

View File

@ -17,6 +17,7 @@
from .config import config from .config import config
from decimal import Decimal from decimal import Decimal
from enum import Enum
import functools import functools
class Ledger: class Ledger:
@ -83,11 +84,17 @@ class Transaction:
return '\n'.join(result) return '\n'.join(result)
class Posting: 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.transaction = transaction
self.account = account self.account = account
self.amount = Amount(amount) self.amount = Amount(amount)
self.comment = comment self.comment = comment
self.state = state
def __repr__(self): def __repr__(self):
return '<Posting "{}" {}>'.format(self.account.name, self.amount.tostr(False)) return '<Posting "{}" {}>'.format(self.account.name, self.amount.tostr(False))