From 6c33a94a5f3aede21b4a5e62d102396dd301830a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Murta?= Date: Sun, 18 Dec 2022 00:28:07 +0000 Subject: [PATCH] Change min_amount/max_amount columns for min/max Simplifies the action creation. --- alembic/versions/753c0bfb2062_rule_min_max.py | 49 +++++++++++++++++++ pfbudget/core/categorizer.py | 8 +-- pfbudget/db/model.py | 4 +- 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 alembic/versions/753c0bfb2062_rule_min_max.py diff --git a/alembic/versions/753c0bfb2062_rule_min_max.py b/alembic/versions/753c0bfb2062_rule_min_max.py new file mode 100644 index 0000000..5e32010 --- /dev/null +++ b/alembic/versions/753c0bfb2062_rule_min_max.py @@ -0,0 +1,49 @@ +"""Rule min/max + +Revision ID: 753c0bfb2062 +Revises: e36e6321568e +Create Date: 2022-12-18 00:24:03.861461+00:00 + +""" +from alembic import op + + +# revision identifiers, used by Alembic. +revision = "753c0bfb2062" +down_revision = "e36e6321568e" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "categories_rules", + "min_amount", + new_column_name="min", + schema="transactions", + ) + op.alter_column( + "categories_rules", + "max_amount", + new_column_name="max", + schema="transactions", + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + "categories_rules", + "min", + new_column_name="min_amount", + schema="transactions", + ) + op.alter_column( + "categories_rules", + "max", + new_column_name="max_amount", + schema="transactions", + ) + # ### end Alembic commands ### diff --git a/pfbudget/core/categorizer.py b/pfbudget/core/categorizer.py index 674c1aa..4348986 100644 --- a/pfbudget/core/categorizer.py +++ b/pfbudget/core/categorizer.py @@ -75,11 +75,11 @@ class Categorizer: if rule.bank: if rule.bank != transaction.bank: continue - if rule.min_amount: - if rule.min_amount > transaction.amount: + if rule.min: + if rule.min > transaction.amount: continue - if rule.max_amount: - if rule.max_amount < transaction.amount: + if rule.max: + if rule.max < transaction.amount: continue # passed all conditions, assign category diff --git a/pfbudget/db/model.py b/pfbudget/db/model.py index 4384cd6..b506783 100644 --- a/pfbudget/db/model.py +++ b/pfbudget/db/model.py @@ -183,8 +183,8 @@ class CategoryRule(Base): description: Mapped[Optional[str]] regex: Mapped[Optional[str]] bank: Mapped[Optional[str]] - min_amount: Mapped[Optional[money]] - max_amount: Mapped[Optional[money]] + min: Mapped[Optional[money]] + max: Mapped[Optional[money]] def __hash__(self): return hash(self.id)