|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import datetime as dt |
5 | 6 | from datetime import date, datetime |
6 | 7 | from decimal import Decimal |
7 | 8 | from typing import Literal, Optional |
8 | 9 |
|
9 | 10 | from pydantic import BaseModel, ConfigDict, Field |
10 | 11 |
|
| 12 | +from finwise.models.account_balance import Amount |
| 13 | + |
11 | 14 |
|
12 | 15 | class TransactionCreateRequest(BaseModel): |
13 | 16 | """ |
@@ -50,37 +53,54 @@ class Transaction(BaseModel): |
50 | 53 |
|
51 | 54 | Attributes: |
52 | 55 | 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. |
56 | 60 | description: Transaction description (if set). |
57 | 61 | category_id: Category ID (if categorized). |
58 | | - category_name: Category name (if categorized). |
59 | 62 | type: Transaction type. |
60 | 63 | created_at: When the transaction was created. |
61 | 64 | updated_at: When the transaction was last updated. |
62 | 65 | archived_at: When the transaction was archived (None if active). |
| 66 | + data_import_id: ID of the data import that created this record. |
63 | 67 |
|
64 | 68 | Example: |
65 | 69 | >>> transactions = client.transactions.list() |
66 | 70 | >>> for txn in transactions: |
67 | | - ... print(f"{txn.transaction_date}: {txn.description} ({txn.amount})") |
| 71 | + ... print(f"{txn.date}: {txn.description} ({txn.amount.format()})") |
68 | 72 | """ |
69 | 73 |
|
70 | 74 | 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 |
74 | 79 | description: Optional[str] = None |
75 | 80 | category_id: Optional[str] = Field(None, alias="categoryId") |
76 | | - category_name: Optional[str] = Field(None, alias="categoryName") |
77 | 81 | type: str |
78 | 82 | created_at: datetime = Field(..., alias="createdAt") |
79 | 83 | updated_at: datetime = Field(..., alias="updatedAt") |
80 | 84 | archived_at: Optional[datetime] = Field(None, alias="archivedAt") |
| 85 | + data_import_id: Optional[str] = Field(None, alias="dataImportId") |
81 | 86 |
|
82 | 87 | model_config = ConfigDict(populate_by_name=True) |
83 | 88 |
|
| 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 | + |
84 | 104 | @property |
85 | 105 | def is_archived(self) -> bool: |
86 | 106 | """Check if the transaction is archived.""" |
|
0 commit comments