Skip to content

Commit 6db20c6

Browse files
committed
fix: list transactions
1 parent 1ce98ba commit 6db20c6

4 files changed

Lines changed: 45 additions & 26 deletions

File tree

docs/usage/transactions.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ transaction = client.transactions.create(
3636

3737
```python
3838
# Basic listing
39-
transactions = client.transactions.list(account_id="acc_123")
39+
transactions = client.transactions.list()
4040

4141
# With date filters
4242
transactions = client.transactions.list(
43-
account_id="acc_123",
4443
start_date=date(2024, 1, 1),
4544
end_date=date(2024, 1, 31),
4645
type="expense",
4746
)
4847

4948
for txn in transactions:
50-
print(f"{txn.transaction_date}: {txn.description} ({txn.amount})")
49+
print(f"{txn.transaction_date}: {txn.description} ({txn.amount.format()})")
5150
```
5251

52+
!!! note "Filtering"
53+
The API supports filtering by `category_id`, `start_date`, `end_date`, and `type`. Filtering by account ID is not supported.
54+
5355
## Archive a Transaction
5456

5557
```python

src/finwise/models/transaction.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
from __future__ import annotations
44

5+
import datetime as dt
56
from datetime import date, datetime
67
from decimal import Decimal
78
from typing import Literal, Optional
89

910
from pydantic import BaseModel, ConfigDict, Field
1011

12+
from finwise.models.account_balance import Amount
13+
1114

1215
class TransactionCreateRequest(BaseModel):
1316
"""
@@ -50,37 +53,54 @@ class Transaction(BaseModel):
5053
5154
Attributes:
5255
id: Unique transaction identifier.
53-
account_id: ID of the account.
54-
amount: Transaction amount.
55-
transaction_date: Date of the transaction.
56+
user_id: ID of the user who owns this transaction.
57+
account_id: ID of the account (nullable).
58+
amount: Transaction amount with currency.
59+
date: Date/time of the transaction.
5660
description: Transaction description (if set).
5761
category_id: Category ID (if categorized).
58-
category_name: Category name (if categorized).
5962
type: Transaction type.
6063
created_at: When the transaction was created.
6164
updated_at: When the transaction was last updated.
6265
archived_at: When the transaction was archived (None if active).
66+
data_import_id: ID of the data import that created this record.
6367
6468
Example:
6569
>>> transactions = client.transactions.list()
6670
>>> for txn in transactions:
67-
... print(f"{txn.transaction_date}: {txn.description} ({txn.amount})")
71+
... print(f"{txn.date}: {txn.description} ({txn.amount.format()})")
6872
"""
6973

7074
id: str
71-
account_id: str = Field(..., alias="accountId")
72-
amount: Decimal
73-
transaction_date: date = Field(..., alias="transactionDate")
75+
user_id: str = Field(..., alias="userId")
76+
account_id: Optional[str] = Field(None, alias="accountId")
77+
amount: Amount
78+
date: datetime
7479
description: Optional[str] = None
7580
category_id: Optional[str] = Field(None, alias="categoryId")
76-
category_name: Optional[str] = Field(None, alias="categoryName")
7781
type: str
7882
created_at: datetime = Field(..., alias="createdAt")
7983
updated_at: datetime = Field(..., alias="updatedAt")
8084
archived_at: Optional[datetime] = Field(None, alias="archivedAt")
85+
data_import_id: Optional[str] = Field(None, alias="dataImportId")
8186

8287
model_config = ConfigDict(populate_by_name=True)
8388

89+
@property
90+
def value(self) -> Decimal:
91+
"""Get the transaction amount value."""
92+
return self.amount.amount
93+
94+
@property
95+
def currency(self) -> str:
96+
"""Get the currency code."""
97+
return self.amount.currency_code
98+
99+
@property
100+
def transaction_date(self) -> dt.date:
101+
"""Get the transaction date (for backwards compatibility)."""
102+
return self.date.date()
103+
84104
@property
85105
def is_archived(self) -> bool:
86106
"""Check if the transaction is archived."""

src/finwise/resources/transactions.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def create(
110110
def list(
111111
self,
112112
*,
113-
account_id: Optional[str] = None,
114113
category_id: Optional[str] = None,
115114
start_date: Optional[date] = None,
116115
end_date: Optional[date] = None,
@@ -119,11 +118,10 @@ def list(
119118
"""
120119
List transactions with optional filtering.
121120
122-
Note: The API does not support pagination for this endpoint.
121+
Note: The API does not support pagination or filtering by account ID.
123122
All matching transactions are returned.
124123
125124
Args:
126-
account_id: Optional filter by account ID.
127125
category_id: Optional filter by category ID.
128126
start_date: Optional filter for transactions on or after this date.
129127
end_date: Optional filter for transactions on or before this date.
@@ -136,24 +134,19 @@ def list(
136134
>>> # List all transactions
137135
>>> transactions = client.transactions.list()
138136
>>> for txn in transactions:
139-
... print(f"{txn.description}: {txn.amount}")
137+
... print(f"{txn.description}: {txn.amount.format()}")
140138
>>>
141139
>>> # Filter by date range
142140
>>> transactions = client.transactions.list(
143141
... start_date=date(2024, 1, 1),
144142
... end_date=date(2024, 1, 31),
145143
... )
146144
>>>
147-
>>> # Filter by account and type
148-
>>> expenses = client.transactions.list(
149-
... account_id="acc_123",
150-
... type="expense",
151-
... )
145+
>>> # Filter by type
146+
>>> expenses = client.transactions.list(type="expense")
152147
"""
153148
params: dict[str, str] = {}
154149

155-
if account_id:
156-
params["accountId"] = account_id
157150
if category_id:
158151
params["categoryId"] = category_id
159152
if start_date:

tests/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,20 @@ def sample_transaction() -> dict[str, Any]:
9999
"""Sample transaction response data."""
100100
return {
101101
"id": "txn_789xyz",
102+
"userId": "user_123",
102103
"accountId": "acc_123abc",
103-
"amount": "-50.00",
104-
"transactionDate": "2024-01-15",
104+
"amount": {
105+
"amount": "-50.00",
106+
"currencyCode": "USD",
107+
},
108+
"date": "2024-01-15T10:00:00Z",
105109
"description": "Grocery shopping",
106110
"categoryId": "cat_groceries",
107-
"categoryName": "Groceries",
108111
"type": "expense",
109112
"createdAt": "2024-01-15T10:00:00Z",
110113
"updatedAt": "2024-01-15T10:00:00Z",
111114
"archivedAt": None,
115+
"dataImportId": None,
112116
}
113117

114118

0 commit comments

Comments
 (0)