Skip to content

Commit f7c7e48

Browse files
committed
✨ [feat][backend] account timezone field
1 parent c3c74fb commit f7c7e48

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Add nullable timezone to account
2+
3+
Revision ID: db51787ee569
4+
Revises: 3f6b892b23da
5+
Create Date: 2026-06-10 00:30:51.945994
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
11+
from alembic import op
12+
from kayman.schemas._custom_types import SATimezone
13+
14+
# revision identifiers, used by Alembic.
15+
revision = "db51787ee569"
16+
down_revision = "3f6b892b23da"
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade():
22+
op.add_column("account", sa.Column("timezone", SATimezone(), nullable=True))
23+
24+
25+
def downgrade():
26+
op.drop_column("account", "timezone")

backend/kayman/schemas/account.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from decimal import Decimal
22
from typing import TYPE_CHECKING
33

4-
from sqlmodel import Field, Relationship, SQLModel
4+
from pydantic_extra_types.timezone_name import TimeZoneName
5+
from sqlmodel import Column, Field, Relationship, SQLModel
6+
7+
from kayman.schemas._custom_types import SATimezone
58

69
if TYPE_CHECKING:
710
from kayman.schemas.currency import Currency
@@ -11,12 +14,14 @@
1114
class AccountBase(SQLModel):
1215
name: str
1316
currency_code: str = Field(foreign_key="currency.code")
17+
timezone: TimeZoneName | None = None
1418

1519

1620
class Account(AccountBase, table=True):
1721
__tablename__ = "account"
1822
id: int | None = Field(primary_key=True, default=None)
1923
balance: Decimal
24+
timezone: TimeZoneName | None = Field(sa_column=Column(SATimezone(), nullable=True))
2025
currency: "Currency" = Relationship(back_populates="accounts")
2126
transactions: list["Transaction"] = Relationship(back_populates="account")
2227

@@ -28,6 +33,7 @@ class AccountCreate(AccountBase):
2833
class AccountRead(AccountBase):
2934
id: int
3035
balance: Decimal
36+
timezone: TimeZoneName | None = None
3137

3238

3339
class AccountUpdate(SQLModel):

backend/kayman/tests/crud/test_account.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_create_account(session: Session):
2525
assert db_account.id is not None
2626
assert db_account.name == account.name
2727
assert db_account.currency_code == account.currency_code
28+
assert db_account.timezone == account.timezone
2829
assert db_account.balance == 0
2930

3031

@@ -35,6 +36,7 @@ def test_read_account(session: Session):
3536
assert db_account.id == account.id
3637
assert db_account.name == account.name
3738
assert db_account.currency_code == account.currency_code
39+
assert db_account.timezone == account.timezone
3840
assert db_account.balance == account.balance
3941

4042

@@ -50,6 +52,7 @@ def test_read_accounts(session: Session):
5052
for account, db_account in zip(accounts, db_accounts, strict=True):
5153
assert db_account.balance == account.balance
5254
assert db_account.currency_code == account.currency_code
55+
assert db_account.timezone == account.timezone
5356
assert db_account.id == account.id
5457
assert db_account.name == account.name
5558

@@ -63,6 +66,7 @@ def test_read_accounts_by_ids(session: Session):
6366
for account, db_account in zip(interest_accounts, db_accounts, strict=True):
6467
assert db_account.balance == account.balance
6568
assert db_account.currency_code == account.currency_code
69+
assert db_account.timezone == account.timezone
6670
assert db_account.id == account.id
6771
assert db_account.name == account.name
6872

@@ -94,6 +98,7 @@ def test_update_accounts(session: Session):
9498
assert updated_account.id == account.id
9599
assert updated_account.name == account_update.name # Updated
96100
assert updated_account.currency_code == account.currency_code # Not updated
101+
assert updated_account.timezone == account.timezone # Not updated
97102
assert updated_account.balance == account.balance # Not updated
98103

99104

@@ -124,6 +129,7 @@ def test_update_account_balances(session: Session):
124129
assert updated_account.id == account.id
125130
assert updated_account.name == account.name
126131
assert updated_account.currency_code == account.currency_code
132+
assert updated_account.timezone == account.timezone
127133
assert updated_account.balance == balance + amount
128134

129135

@@ -138,13 +144,15 @@ def test_update_account_balances_no_commit(session: Session, session_2: Session)
138144
assert updated_account.id == account.id
139145
assert updated_account.name == account.name
140146
assert updated_account.currency_code == account.currency_code
147+
assert updated_account.timezone == account.timezone
141148
assert updated_account.balance == account_balance + account_amounts[account.id]
142149

143150
# The account balance should not be updated from other sessions (yet)
144151
session_2_account = session_2.get(Account, account.id)
145152
assert session_2_account.id == account.id
146153
assert session_2_account.name == account.name
147154
assert session_2_account.currency_code == account.currency_code
155+
assert session_2_account.timezone == account.timezone
148156
assert session_2_account.balance == account_balance
149157

150158
# Commit the change from main session
@@ -156,6 +164,7 @@ def test_update_account_balances_no_commit(session: Session, session_2: Session)
156164
assert session_2_account.id == account.id
157165
assert session_2_account.name == account.name
158166
assert session_2_account.currency_code == account.currency_code
167+
assert session_2_account.timezone == account.timezone
159168
assert session_2_account.balance == account_balance + account_amounts[account.id]
160169

161170

backend/kayman/tests/factories/account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ class Meta:
1414
currency = factory.SubFactory("kayman.tests.factories.currency.CurrencyFactory")
1515
currency_code = factory.SelfAttribute("currency.code")
1616
balance = factory.Faker("pydecimal", left_digits=5, right_digits=2)
17+
timezone = "UTC"

0 commit comments

Comments
 (0)