Skip to main content

Overview

Wallets in FinAI represent different sources of money in your financial life. Each wallet maintains its own balance and can be used for income, expenses, or transfers between wallets.

Database Schema

The Wallet model (located in app/models.py:50) stores wallet information:
class Wallet(db.Model):
    __tablename__ = 'nguontien'

    id = db.Column('MaNguonTien', db.String(8), primary_key=True)
    user_id = db.Column('MaNguoiDung', db.String(8), db.ForeignKey('nguoidung.MaNguoiDung', ondelete='CASCADE'), nullable=False)
    name = db.Column('TenNguonTien', db.String(100), nullable=False)
    type = db.Column('LoaiNguonTien', db.String(50)) # Tiền mặt, Ngân hàng...
    balance = db.Column('SoDu', db.Float, default=0.0)
    created_at = db.Column('NgayTao', db.DateTime, default=datetime.now)

Wallet Types

FinAI supports various wallet types to match real-world money sources:

Cash

Physical cash for daily transactions

Bank Account

Traditional savings and checking accounts

E-Wallet

Digital wallets like Momo, ZaloPay, VNPay

Managing Wallets

1

View All Wallets

Access your wallets through the API endpoint:
GET /api/wallets
Response format (from app/routes/foundation.py:16):
[
  {
    "MaNguonTien": "a1b2c3d4",
    "TenNguonTien": "Tiền mặt",
    "LoaiNguonTien": "Cash",
    "SoDu": 5000000
  },
  {
    "MaNguonTien": "e5f6g7h8",
    "TenNguonTien": "Techcombank",
    "LoaiNguonTien": "Bank",
    "SoDu": 25000000
  }
]
2

Create a New Wallet

Add a new wallet to your account:
POST /api/wallets
Content-Type: application/json

{
  "name": "Momo Wallet",
  "type": "E-Wallet",
  "balance": 1000000
}
Wallet IDs are auto-generated using UUID (app/routes/foundation.py:22). The system creates an 8-character unique identifier.
3

Update Wallet Details

Modify wallet name, type, or manually adjust balance:
PUT /api/wallets/{wallet_id}
Content-Type: application/json

{
  "name": "Momo (Personal)",
  "type": "E-Wallet",
  "balance": 1500000
}
4

Delete a Wallet

Remove a wallet from your account:
DELETE /api/wallets/{wallet_id}
Deleting a wallet will cascade delete all associated transactions due to the foreign key constraint (ondelete='CASCADE').

Balance Management

Wallet balances are automatically updated when you create, edit, or delete transactions. The system handles three transaction types:

Income Transactions

When you record income (app/routes/transaction.py:71):
if db_type == 'thu':
    wallet.balance += amount

Expense Transactions

When you record an expense (app/routes/transaction.py:68-69):
if db_type == 'chi':
    wallet.balance -= amount

Transfer Transactions

When transferring between wallets (app/routes/transaction.py:72-75):
elif db_type == 'chuyen':
    wallet.balance -= amount  # Deduct from source wallet
    dest_wallet = Wallet.query.get(final_dest_id)
    if dest_wallet: dest_wallet.balance += amount  # Add to destination wallet
Transfers are NOT counted as expenses in reports. The AI chatbot is specifically trained to exclude transfers when calculating total spending (app/ai_service.py:94-97).

Multi-Wallet Workflows

  1. Create a “Cash” wallet for daily expenses
  2. Create a “Bank Savings” wallet for long-term money
  3. When you spend cash, record it as an expense from the Cash wallet
  4. When you deposit money, create a transfer transaction from Cash to Bank Savings
  5. View your total balance across all wallets in the dashboard
  1. Create separate wallets for Momo, ZaloPay, and ShopeePay
  2. Track which e-wallet gives you the best rewards
  3. Use the Reports feature to analyze spending by wallet
  4. Make informed decisions about which e-wallet to prioritize

Security Considerations

All wallet operations require authentication (@api_login_required decorator in app/routes/foundation.py:11). Users can only access and modify their own wallets through the user_id foreign key constraint.
  • Transactions - Record income, expenses, and transfers
  • Reports - Analyze spending patterns by wallet
  • Budgets - Set spending limits across all wallets

Build docs developers (and LLMs) love