Overview
Transactions are the core of FinAI’s financial tracking system. Every time money moves in or out of your wallets, it’s recorded as a transaction with detailed information including amount, date, category, and description.Database Schema
TheTransaction model (app/models.py:78) is the most important table in the system:
Transaction Types
Income (Thu)
Money coming into your wallets
Expense (Chi)
Money going out of your wallets
Transfer (Chuyển)
Money moving between your own wallets
Recording Transactions
List All Transactions
Retrieve your transaction history sorted by date:Response (
app/routes/transaction.py:18-30):Create a New Transaction
Add an income, expense, or transfer:
The system maps UI types to database types (
app/routes/transaction.py:40):expense→chiincome→thutransfer→chuyen
Update an Existing Transaction
The update process automatically handles balance corrections:Balance correction logic (
app/routes/transaction.py:94-125):- Reverse the old transaction’s effect on wallet balances
- Apply the new transaction data
- Update wallets with the new amounts
Transaction Workflows
Recording an Expense
AI Suggests Category
The system calls
/api/predict-category and suggests “Ăn uống” with 95% confidenceTransferring Between Wallets
Example: Moving money from Cash to Bank
Example: Moving money from Cash to Bank
When creating a transfer transaction:The system:
- Deducts 2,000,000 VND from Cash wallet
- Adds 2,000,000 VND to Bank wallet
- Stores both wallet IDs in the transaction (
wallet_idanddest_wallet_id) - Does NOT count this as an expense in reports
AI Integration
Transactions leverage two AI-powered fields:AI Category Prediction
When you create a transaction, the system can predict the category:Transaction Date Handling
Transactions support backdating for recording past expenses:You can record transactions from any date, making it easy to catch up on expenses you forgot to log.
Response Format
Successful transaction operations return:Balance Consistency
The system maintains balance consistency through database transactions. All wallet updates happen within the same database commit:db.session.rollback() restores the previous state.
Related Features
- Wallets - Manage your money sources
- AI Categorization - Automatic category suggestions
- Reports - Analyze transaction patterns
- Budgets - Track spending against limits
