Fix rule's values limits
They are supposed to catch also the explicit values, so the limits are inclusive.
This commit is contained in:
parent
95eff24418
commit
a7b74237aa
@ -485,16 +485,16 @@ class Rule(Base):
|
||||
valid = re.compile(self.regex, re.IGNORECASE)
|
||||
|
||||
ops = (
|
||||
Rule.exists(self.start, lambda r: r < t.date),
|
||||
Rule.exists(self.end, lambda r: r > t.date),
|
||||
Rule.exists(self.start, lambda r: t.date >= r),
|
||||
Rule.exists(self.end, lambda r: t.date <= r),
|
||||
Rule.exists(self.description, lambda r: r == t.description),
|
||||
Rule.exists(
|
||||
valid,
|
||||
lambda r: r.search(t.description) if t.description else False,
|
||||
),
|
||||
Rule.exists(self.bank, lambda r: r == t.bank),
|
||||
Rule.exists(self.min, lambda r: r < t.amount),
|
||||
Rule.exists(self.max, lambda r: r > t.amount),
|
||||
Rule.exists(self.min, lambda r: t.amount >= r),
|
||||
Rule.exists(self.max, lambda r: t.amount <= r),
|
||||
)
|
||||
|
||||
if all(ops):
|
||||
|
||||
@ -5,6 +5,7 @@ import mocks.categories as mock
|
||||
|
||||
from pfbudget.db.model import (
|
||||
BankTransaction,
|
||||
Category,
|
||||
CategoryRule,
|
||||
CategorySelector,
|
||||
TransactionCategory,
|
||||
@ -110,3 +111,17 @@ class TestTransform:
|
||||
|
||||
for t in transactions:
|
||||
assert t.category == TransactionCategory("cat#1", CategorySelector.rules)
|
||||
|
||||
def test_rule_limits(self):
|
||||
transactions = [
|
||||
BankTransaction(date.today(), "", Decimal("-60"), bank="Bank#1"),
|
||||
BankTransaction(date.today(), "", Decimal("-120"), bank="Bank#1"),
|
||||
]
|
||||
|
||||
cat = Category("cat")
|
||||
cat.rules = [CategoryRule(min=-120, max=-60)]
|
||||
for r in cat.rules:
|
||||
r.name = cat.name
|
||||
|
||||
transactions = Categorizer(cat.rules).transform(transactions)
|
||||
assert all(t.category.name == cat.name for t in transactions)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user