Allow multi-category transactions
through the use of tags. Instead of failing when categorizing a transaction which already has a category, add the new category as a tag for that transaction. Issue #2
This commit is contained in:
parent
a7b74237aa
commit
c6a13cc83a
@ -6,8 +6,8 @@ from pfbudget.db.model import (
|
||||
CategorySelector,
|
||||
Transaction,
|
||||
TransactionCategory,
|
||||
TransactionTag,
|
||||
)
|
||||
from .exceptions import TransactionCategorizedError
|
||||
from .transform import Transformer
|
||||
|
||||
|
||||
@ -24,12 +24,15 @@ class Categorizer(Transformer):
|
||||
def transform_inplace(self, transactions: Sequence[Transaction]) -> None:
|
||||
for rule in self.rules:
|
||||
for transaction in transactions:
|
||||
if transaction.category:
|
||||
raise TransactionCategorizedError(transaction)
|
||||
|
||||
if not rule.matches(transaction):
|
||||
continue
|
||||
|
||||
transaction.category = TransactionCategory(
|
||||
rule.name, CategorySelector.rules
|
||||
)
|
||||
if not transaction.category:
|
||||
transaction.category = TransactionCategory(
|
||||
rule.name, CategorySelector.rules
|
||||
)
|
||||
else:
|
||||
if not transaction.tags:
|
||||
transaction.tags = {TransactionTag(rule.name)}
|
||||
else:
|
||||
transaction.tags.add(TransactionTag(rule.name))
|
||||
|
||||
@ -1,6 +1,2 @@
|
||||
class MoreThanOneMatchError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TransactionCategorizedError(Exception):
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user