Update ness.py
This commit is contained in:
parent
a3a23e165f
commit
03b670bc8d
17
ness.py
17
ness.py
@ -8,8 +8,8 @@ YMD = "%Y-%m-%d"
|
|||||||
|
|
||||||
|
|
||||||
class Transactions:
|
class Transactions:
|
||||||
def __init__(self, transactions, interest=12.34):
|
def __init__(self, transactions, interest):
|
||||||
self.interest = interest / 100
|
self.interest = interest / 100 # to percent
|
||||||
self.transactions = transactions
|
self.transactions = transactions
|
||||||
self.start_date = datetime.datetime.strptime("2023-01-01", YMD)
|
self.start_date = datetime.datetime.strptime("2023-01-01", YMD)
|
||||||
self.last_date = self._find_last_date()
|
self.last_date = self._find_last_date()
|
||||||
@ -89,9 +89,14 @@ class Transactions:
|
|||||||
total = self.balance(statement["transactions"])
|
total = self.balance(statement["transactions"])
|
||||||
running_balance += total
|
running_balance += total
|
||||||
statement["total"] = total
|
statement["total"] = total
|
||||||
statement["interest"] = 0
|
|
||||||
if total > 0:
|
if total > 0:
|
||||||
statement["interest"] = self.interest * total
|
statement["transactions"].append({
|
||||||
|
"transaction_id": "tx_InterestCalc",
|
||||||
|
"transaction_date": "2023-99-99",
|
||||||
|
"transaction_type": "Interest",
|
||||||
|
"amount": int(self.interest * total),
|
||||||
|
"description": "Interest Charge"
|
||||||
|
})
|
||||||
|
|
||||||
def statements_print_formatted(self):
|
def statements_print_formatted(self):
|
||||||
total = 0
|
total = 0
|
||||||
@ -105,12 +110,12 @@ class Transactions:
|
|||||||
f"* {txn['transaction_date']}"
|
f"* {txn['transaction_date']}"
|
||||||
f": {txn['transaction_id']}"
|
f": {txn['transaction_id']}"
|
||||||
f": {txn['transaction_type']: <9}"
|
f": {txn['transaction_type']: <9}"
|
||||||
f"\t{txn['amount']}"
|
f"\t{txn['amount']:.0f}"
|
||||||
f"\t{total}"
|
f"\t{total}"
|
||||||
f"\t{txn['description']}"
|
f"\t{txn['description']}"
|
||||||
)
|
)
|
||||||
out += "\n"
|
out += "\n"
|
||||||
out += f"------------- TOTAL:{statement['total']}, {statement['interest']:.2f}\n"
|
out += f"------------- TOTAL:{total}\n"
|
||||||
|
|
||||||
print(out)
|
print(out)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user