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,
|
CategorySelector,
|
||||||
Transaction,
|
Transaction,
|
||||||
TransactionCategory,
|
TransactionCategory,
|
||||||
|
TransactionTag,
|
||||||
)
|
)
|
||||||
from .exceptions import TransactionCategorizedError
|
|
||||||
from .transform import Transformer
|
from .transform import Transformer
|
||||||
|
|
||||||
|
|
||||||
@ -24,12 +24,15 @@ class Categorizer(Transformer):
|
|||||||
def transform_inplace(self, transactions: Sequence[Transaction]) -> None:
|
def transform_inplace(self, transactions: Sequence[Transaction]) -> None:
|
||||||
for rule in self.rules:
|
for rule in self.rules:
|
||||||
for transaction in transactions:
|
for transaction in transactions:
|
||||||
if transaction.category:
|
|
||||||
raise TransactionCategorizedError(transaction)
|
|
||||||
|
|
||||||
if not rule.matches(transaction):
|
if not rule.matches(transaction):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
transaction.category = TransactionCategory(
|
if not transaction.category:
|
||||||
rule.name, CategorySelector.rules
|
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):
|
class MoreThanOneMatchError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TransactionCategorizedError(Exception):
|
|
||||||
pass
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user