feat: implement complete CMT backend with API endpoints and test suite
- Add 7 core API endpoints: users, transactions, partners, products, inventory, payments, credit - Implement role-based authentication (admin/write/read-only access) - Add comprehensive database models with proper relationships - Include full test coverage for all endpoints and business logic - Set up Alembic migrations and Docker configuration - Configure FastAPI app with CORS and database integration
This commit is contained in:
@@ -14,12 +14,11 @@ The models include:
|
||||
- Inventory
|
||||
"""
|
||||
|
||||
from sqlmodel import SQLModel, Field, UniqueConstraint
|
||||
from sqlmodel import SQLModel, Field
|
||||
from datetime import datetime, date
|
||||
from sqlalchemy import Column, DateTime, func, Enum as SQLEnum
|
||||
from enum import Enum
|
||||
from sqlalchemy import Column, String, CheckConstraint, DateTime, func, Enum as SQLEnum
|
||||
from typing import Optional
|
||||
from base import UserRole, PartnerType, TransactionType, TransactionStatus, PaymentMethod
|
||||
from .base import UserRole, PartnerType, TransactionType, TransactionStatus, PaymentMethod
|
||||
|
||||
|
||||
class User(SQLModel, table=True):
|
||||
@@ -157,7 +156,7 @@ class Transaction_details(SQLModel, table=True):
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
partner_id: int = Field(nullable=False, foreign_key="partner.id")
|
||||
product_id: str = Field(nullable=False, foreign_key="product.id")
|
||||
product_id: int = Field(nullable=False, foreign_key="product.id")
|
||||
qty: int = Field(nullable=False)
|
||||
selling_price: int = Field(nullable=False)
|
||||
|
||||
@@ -193,11 +192,12 @@ class Payment(SQLModel, table=True):
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
transaction_id: int = Field(nullable=False, foreign_key="transactions.id")
|
||||
payment_method: PaymentMethod = Field(
|
||||
payment_method: str = Field(
|
||||
sa_column=Column(
|
||||
SQLEnum(PaymentMethod),
|
||||
String(10),
|
||||
CheckConstraint("payment_method IN ('momo', 'bank', 'cash')"),
|
||||
nullable=False,
|
||||
default=PaymentMethod.CASH
|
||||
default="cash"
|
||||
)
|
||||
)
|
||||
paid_amount: int = Field(nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user