Skip to content

Commit e94560c

Browse files
committed
❇️ [refactor][backend] Rename PaymentType to EventType
1 parent 13e8214 commit e94560c

5 files changed

Lines changed: 43 additions & 31 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""rename paymenttype enum to eventtype
2+
3+
Revision ID: d09182f71aa6
4+
Revises: 7365aeb08d01
5+
Create Date: 2026-06-23 23:26:13.393096
6+
7+
"""
8+
9+
from alembic import op
10+
11+
# revision identifiers, used by Alembic.
12+
revision = 'd09182f71aa6'
13+
down_revision = '7365aeb08d01'
14+
branch_labels = None
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
op.execute("ALTER TYPE paymenttype RENAME TO eventtype")
20+
21+
22+
def downgrade():
23+
op.execute("ALTER TYPE eventtype RENAME TO paymenttype")

backend/kayman/logics/event.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from decimal import Decimal
22

33
from kayman.schemas.api_models import PaymentCreateDetailed
4-
from kayman.schemas.event import PaymentType
4+
from kayman.schemas.event import EventType
55

66

77
def validate_total(details: PaymentCreateDetailed) -> None:
@@ -10,7 +10,7 @@ def validate_total(details: PaymentCreateDetailed) -> None:
1010
return
1111

1212
# Payment type of transfer or exchange is not checked
13-
if details.payment.type in (PaymentType.Transfer, PaymentType.Exchange):
13+
if details.payment.type in (EventType.Transfer, EventType.Exchange):
1414
return
1515

1616
entries_total = Decimal(
@@ -20,14 +20,14 @@ def validate_total(details: PaymentCreateDetailed) -> None:
2020
sum([transaction.amount for transaction in details.transactions])
2121
)
2222

23-
if details.payment.type is PaymentType.Expense:
23+
if details.payment.type is EventType.Expense:
2424
if entries_total != -transactions_total:
2525
raise ValueError(
2626
f"Entries total ({entries_total}) and "
2727
f"transactions total ({-transactions_total}) do not match"
2828
)
2929

30-
if details.payment.type is PaymentType.Income:
30+
if details.payment.type is EventType.Income:
3131
if entries_total != transactions_total:
3232
raise ValueError(
3333
f"Entries total ({entries_total}) and "

backend/kayman/schemas/event.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,16 @@
1414
from kayman.schemas.currency import Currency
1515
from kayman.schemas.transaction import Transaction
1616

17-
#
18-
# Payment Category
19-
#
2017

21-
22-
class PaymentType(enum.Enum):
18+
class EventType(enum.Enum):
2319
Expense = "Expense"
2420
Income = "Income"
2521
Transfer = "Transfer"
2622
Exchange = "Exchange"
2723

2824

29-
#
30-
# Payment
31-
#
32-
33-
3425
class EventBase(SQLModel):
35-
type: PaymentType = Field(
36-
sa_column=Column(sqlmodel.Enum(PaymentType), nullable=False)
37-
)
26+
type: EventType = Field(sa_column=Column(sqlmodel.Enum(EventType), nullable=False))
3827
timestamp: datetime = Field(
3928
sa_column=Column(DateTime(timezone=True), nullable=False),
4029
title="Local timestamp, or timezone-aware timestamp",

backend/kayman/tests/factories/event.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from kayman.schemas import Event
55
from kayman.schemas.api_models import PaymentCreateDetailed
6-
from kayman.schemas.event import PaymentType
6+
from kayman.schemas.event import EventType
77

88

99
class EventFactory(SQLAlchemyModelFactory):
@@ -14,10 +14,10 @@ class Meta:
1414
description = factory.Faker("sentence")
1515
timestamp = factory.Faker("date_time")
1616
timezone = "UTC"
17-
type = factory.Faker("random_element", elements=list(PaymentType))
17+
type = factory.Faker("random_element", elements=list(EventType))
1818

1919
@classmethod
20-
def build_details(cls, type=PaymentType.Expense, entry_num=1, transaction_num=1):
20+
def build_details(cls, type=EventType.Expense, entry_num=1, transaction_num=1):
2121
from kayman.tests.factories.currency import CurrencyFactory
2222
from kayman.tests.factories.payment_entry import PaymentEntryFactory
2323
from kayman.tests.factories.transaction import TransactionFactory
@@ -31,12 +31,12 @@ def build_details(cls, type=PaymentType.Expense, entry_num=1, transaction_num=1)
3131
entries_total = sum([entry.amount * entry.quantity for entry in entries])
3232
transactions_total = sum([transaction.amount for transaction in transactions])
3333

34-
if type is PaymentType.Expense:
34+
if type is EventType.Expense:
3535
# Update last transaction amount to match the total
3636
# entries_total == -transactions_total
3737
transactions[-1].amount -= entries_total + transactions_total
3838

39-
if type is PaymentType.Income:
39+
if type is EventType.Income:
4040
# Update last transaction amount to match the total
4141
# entries_total == transactions_total
4242
transactions[-1].amount -= transactions_total - entries_total
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import pytest
22

33
from kayman.logics.event import validate_total
4-
from kayman.schemas.event import PaymentType
4+
from kayman.schemas.event import EventType
55
from kayman.tests.factories import EventFactory
66

77

88
def test_validate_total_expense():
99
"""Expense: Entries total is matched with transactions total"""
1010
details = EventFactory.build_details(
11-
type=PaymentType.Expense, entry_num=3, transaction_num=5
11+
type=EventType.Expense, entry_num=3, transaction_num=5
1212
)
1313
validate_total(details)
1414

1515

1616
def test_validate_total_expense_multi_currencies():
1717
"""Expense: Multiple currencies are used, validation should be skipped"""
1818
details = EventFactory.build_details(
19-
type=PaymentType.Expense, entry_num=3, transaction_num=5
19+
type=EventType.Expense, entry_num=3, transaction_num=5
2020
)
2121
details.entries[-1].currency_code += "_INVALID" # explicitly change currency
2222
validate_total(details)
@@ -25,7 +25,7 @@ def test_validate_total_expense_multi_currencies():
2525
def test_validate_total_expense_mismatch():
2626
"""Expense: Entries and transactions totals do not match"""
2727
details = EventFactory.build_details(
28-
type=PaymentType.Expense, entry_num=3, transaction_num=5
28+
type=EventType.Expense, entry_num=3, transaction_num=5
2929
)
3030
details.transactions[-1].amount += 1
3131
with pytest.raises(ValueError, match="transactions (.*) not match"):
@@ -35,15 +35,15 @@ def test_validate_total_expense_mismatch():
3535
def test_validate_total_income():
3636
"""Income: Entries total is matched with transactions total"""
3737
details = EventFactory.build_details(
38-
type=PaymentType.Income, entry_num=3, transaction_num=5
38+
type=EventType.Income, entry_num=3, transaction_num=5
3939
)
4040
validate_total(details)
4141

4242

4343
def test_validate_total_income_multi_currencies():
4444
"""Income: Multiple currencies are used, validation should be skipped"""
4545
details = EventFactory.build_details(
46-
type=PaymentType.Income, entry_num=3, transaction_num=5
46+
type=EventType.Income, entry_num=3, transaction_num=5
4747
)
4848
details.entries[-1].currency_code += "_INVALID" # explicitly change currency
4949
validate_total(details)
@@ -52,7 +52,7 @@ def test_validate_total_income_multi_currencies():
5252
def test_validate_total_income_mismatch():
5353
"""Income: Entries and transactions totals do not match"""
5454
details = EventFactory.build_details(
55-
type=PaymentType.Income, entry_num=3, transaction_num=5
55+
type=EventType.Income, entry_num=3, transaction_num=5
5656
)
5757
details.transactions[-1].amount += 1
5858
with pytest.raises(ValueError, match="transactions (.*) not match"):
@@ -62,14 +62,14 @@ def test_validate_total_income_mismatch():
6262
def test_validate_total_transfer():
6363
"""Transfer: Validation should be skipped"""
6464
details = EventFactory.build_details(
65-
type=PaymentType.Transfer, entry_num=3, transaction_num=5
65+
type=EventType.Transfer, entry_num=3, transaction_num=5
6666
)
6767
validate_total(details)
6868

6969

7070
def test_validate_total_exchange():
7171
"""Exchange: Validation should be skipped"""
7272
details = EventFactory.build_details(
73-
type=PaymentType.Exchange, entry_num=3, transaction_num=5
73+
type=EventType.Exchange, entry_num=3, transaction_num=5
7474
)
7575
validate_total(details)

0 commit comments

Comments
 (0)