[Interactive] Finish split command
This commit is contained in:
parent
e0fc310ef6
commit
abff76ad4e
@ -1,3 +1,6 @@
|
|||||||
|
from decimal import Decimal
|
||||||
|
from typing import Sequence
|
||||||
|
|
||||||
from pfbudget.cli.runnable import argparser
|
from pfbudget.cli.runnable import argparser
|
||||||
from pfbudget.common.types import Operation
|
from pfbudget.common.types import Operation
|
||||||
from pfbudget.core.manager import Manager
|
from pfbudget.core.manager import Manager
|
||||||
@ -26,6 +29,10 @@ def interactive(manager: Manager):
|
|||||||
next = False
|
next = False
|
||||||
quit = True
|
quit = True
|
||||||
|
|
||||||
|
case "split":
|
||||||
|
manager.action(Operation.Split, split(transaction, categories))
|
||||||
|
next = False
|
||||||
|
|
||||||
case "tag":
|
case "tag":
|
||||||
tag = input("tag: ")
|
tag = input("tag: ")
|
||||||
if tag not in [t.name for t in tags]:
|
if tag not in [t.name for t in tags]:
|
||||||
@ -48,10 +55,46 @@ def interactive(manager: Manager):
|
|||||||
)
|
)
|
||||||
next = False
|
next = False
|
||||||
|
|
||||||
|
session.commit()
|
||||||
if quit:
|
if quit:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
def split(
|
||||||
|
original: type.Transaction, categories: Sequence[type.Category]
|
||||||
|
) -> list[type.Transaction]:
|
||||||
|
|
||||||
|
total = original.amount
|
||||||
|
splitted: list[type.Transaction] = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if abs(sum(t.amount for t in splitted)) > abs(total):
|
||||||
|
print(
|
||||||
|
"The total amount from the splitted transactions exceeds the original transaction amount, please try again..."
|
||||||
|
)
|
||||||
|
splitted.clear()
|
||||||
|
|
||||||
|
if sum(t.amount for t in splitted) == total:
|
||||||
|
break
|
||||||
|
|
||||||
|
while (category := input("New transaction category: ")) not in [
|
||||||
|
c.name for c in categories
|
||||||
|
]:
|
||||||
|
print(f"{category} is not a valid category")
|
||||||
|
|
||||||
|
amount = input("amount: ")
|
||||||
|
|
||||||
|
split = type.Transaction(original.date, original.description, Decimal(amount))
|
||||||
|
split.category = type.TransactionCategory(
|
||||||
|
category, type.CategorySelector(type.Selector_T.manual)
|
||||||
|
)
|
||||||
|
|
||||||
|
splitted.append(split)
|
||||||
|
|
||||||
|
splitted.insert(0, original)
|
||||||
|
return splitted
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
argparser = argparser()
|
argparser = argparser()
|
||||||
args = vars(argparser.parse_args())
|
args = vars(argparser.parse_args())
|
||||||
|
|||||||
@ -35,6 +35,7 @@ class Categorizer:
|
|||||||
|
|
||||||
@Timer(name="nullify")
|
@Timer(name="nullify")
|
||||||
def _nullify(self, transactions: Sequence[t.BankTransaction]):
|
def _nullify(self, transactions: Sequence[t.BankTransaction]):
|
||||||
|
print(f"Nullifying {len(transactions)} transactions")
|
||||||
count = 0
|
count = 0
|
||||||
matching = []
|
matching = []
|
||||||
for transaction in transactions:
|
for transaction in transactions:
|
||||||
@ -72,6 +73,7 @@ class Categorizer:
|
|||||||
transactions: Sequence[t.BankTransaction],
|
transactions: Sequence[t.BankTransaction],
|
||||||
categories: Sequence[t.Category],
|
categories: Sequence[t.Category],
|
||||||
):
|
):
|
||||||
|
print(f"Categorizing {len(transactions)} transactions")
|
||||||
d = {}
|
d = {}
|
||||||
for category in [c for c in categories if c.rules]:
|
for category in [c for c in categories if c.rules]:
|
||||||
for rule in category.rules:
|
for rule in category.rules:
|
||||||
@ -112,6 +114,7 @@ class Categorizer:
|
|||||||
def _rule_based_tags(
|
def _rule_based_tags(
|
||||||
self, transactions: Sequence[t.BankTransaction], tags: Sequence[t.Tag]
|
self, transactions: Sequence[t.BankTransaction], tags: Sequence[t.Tag]
|
||||||
):
|
):
|
||||||
|
print(f"Tagging {len(transactions)} transactions")
|
||||||
d = {}
|
d = {}
|
||||||
for tag in [t for t in tags if len(t.rules) > 0]:
|
for tag in [t for t in tags if len(t.rules) > 0]:
|
||||||
for rule in tag.rules:
|
for rule in tag.rules:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user