Each children is essentually a type of transaction. We currently have: - bank transactions - money transactions - split transactions The table inheritance is implemented as a single table, with a polymorphic type and Null columns. Adds a IsSplit interface, which will later be used for the category views, so as to not repeat transactions.
30 lines
844 B
Python
30 lines
844 B
Python
from datetime import date
|
|
from functools import singledispatch
|
|
|
|
from pfbudget.common.types import TransactionError
|
|
from pfbudget.db.model import Bank, BankTransaction
|
|
from .utils import parse_decimal
|
|
|
|
|
|
@singledispatch
|
|
def convert(t):
|
|
print("No converter as been found")
|
|
pass
|
|
|
|
|
|
@convert.register
|
|
def _(json: dict, bank: Bank) -> BankTransaction:
|
|
i = -1 if bank.nordigen.invert else 1
|
|
try:
|
|
transaction = BankTransaction(
|
|
date=date.fromisoformat(json["bookingDate"]),
|
|
description=json["remittanceInformationUnstructured"],
|
|
bank=bank.name,
|
|
amount=i * parse_decimal(json["transactionAmount"]["amount"]),
|
|
)
|
|
# transaction.date += timedelta(days=bank.offset)
|
|
return transaction
|
|
|
|
except TransactionError:
|
|
print(f"{json} is in the wrong format")
|