Change min_amount/max_amount columns for min/max

Simplifies the action creation.
This commit is contained in:
Luís Murta 2022-12-18 00:28:07 +00:00
parent a2b2f2c1d1
commit 6c33a94a5f
Signed by: satprog
GPG Key ID: 169EF1BBD7049F94
3 changed files with 55 additions and 6 deletions

View File

@ -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 ###

View File

@ -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

View File

@ -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)