Compare commits
3 Commits
e670d3ddee
...
7453ffbd3a
| Author | SHA1 | Date | |
|---|---|---|---|
| 7453ffbd3a | |||
| da348c4ffb | |||
| 2da721d53c |
@ -24,35 +24,47 @@ def interactive(manager: Manager):
|
|||||||
quit = False
|
quit = False
|
||||||
next = True
|
next = True
|
||||||
while next:
|
while next:
|
||||||
match (input("(<category>/split/tag/note/quit): ")):
|
match (input("(<category>(:tag)/split/note/skip/quit): ")):
|
||||||
|
case "skip":
|
||||||
|
next = False
|
||||||
|
continue
|
||||||
|
|
||||||
case "quit" | "exit":
|
case "quit" | "exit":
|
||||||
next = False
|
next = False
|
||||||
quit = True
|
quit = True
|
||||||
|
|
||||||
case "split":
|
case "split":
|
||||||
manager.action(Operation.Split, split(transaction, categories))
|
manager.action(Operation.Split, split(transaction, categories, tags))
|
||||||
next = False
|
next = False
|
||||||
|
|
||||||
case "tag":
|
|
||||||
tag = input("tag: ")
|
|
||||||
if tag not in [t.name for t in tags]:
|
|
||||||
session.add([type.Tag(tag)])
|
|
||||||
|
|
||||||
transaction.tags.add(type.TransactionTag(tag))
|
|
||||||
|
|
||||||
case "note":
|
case "note":
|
||||||
note = input("note: ")
|
note = input("note: ")
|
||||||
transaction.note = type.Note(note)
|
transaction.note = type.Note(note)
|
||||||
|
|
||||||
case other:
|
case other:
|
||||||
if other not in [c.name for c in categories]:
|
if len(li := other.split(":")) > 1:
|
||||||
print(f"{other} is not a valid category")
|
_category = li[0]
|
||||||
|
_tags = li[1:]
|
||||||
|
else:
|
||||||
|
_category = other
|
||||||
|
_tags = []
|
||||||
|
|
||||||
|
if _category not in [c.name for c in categories]:
|
||||||
|
print(f"{other} doesn't have a valid category")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
transaction.category = type.TransactionCategory(
|
transaction.category = type.TransactionCategory(
|
||||||
other,
|
_category,
|
||||||
type.CategorySelector(type.Selector_T.manual),
|
type.CategorySelector(type.Selector_T.manual),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for tag in _tags:
|
||||||
|
if tag not in [t.name for t in tags]:
|
||||||
|
session.add([type.Tag(tag)])
|
||||||
|
tags = session.get(type.Tag)
|
||||||
|
|
||||||
|
transaction.tags.add(type.TransactionTag(tag))
|
||||||
|
|
||||||
next = False
|
next = False
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -61,7 +73,9 @@ def interactive(manager: Manager):
|
|||||||
|
|
||||||
|
|
||||||
def split(
|
def split(
|
||||||
original: type.Transaction, categories: Sequence[type.Category]
|
original: type.Transaction,
|
||||||
|
categories: Sequence[type.Category],
|
||||||
|
tags: Sequence[type.Tag],
|
||||||
) -> list[type.Transaction]:
|
) -> list[type.Transaction]:
|
||||||
|
|
||||||
total = original.amount
|
total = original.amount
|
||||||
|
|||||||
@ -197,12 +197,20 @@ class Manager:
|
|||||||
assert len(originals) == 1, ">1 transactions matched {original.id}!"
|
assert len(originals) == 1, ">1 transactions matched {original.id}!"
|
||||||
|
|
||||||
originals[0].split = True
|
originals[0].split = True
|
||||||
transactions = [
|
transactions = []
|
||||||
SplitTransaction(
|
for t in params[1:]:
|
||||||
originals[0].date, t.description, t.amount, originals[0].id
|
if originals[0].date != t.date:
|
||||||
|
t.date = originals[0].date
|
||||||
|
print(
|
||||||
|
f"{t.date} is different from original date {originals[0].date}, using original"
|
||||||
)
|
)
|
||||||
for t in params[1:]
|
|
||||||
]
|
splitted = SplitTransaction(
|
||||||
|
t.date, t.description, t.amount, originals[0].id
|
||||||
|
)
|
||||||
|
splitted.category = t.category
|
||||||
|
transactions.append(splitted)
|
||||||
|
|
||||||
session.add(transactions)
|
session.add(transactions)
|
||||||
|
|
||||||
case Operation.Export:
|
case Operation.Export:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user