
- Create FastAPI app structure - Set up SQLAlchemy with SQLite for database management - Implement invoice and invoice item models - Add Alembic for database migrations - Create invoice generation and retrieval API endpoints - Add health check endpoint - Set up Ruff for linting - Update README with project details
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import datetime
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
String,
|
|
Integer,
|
|
Float,
|
|
DateTime,
|
|
ForeignKey,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class Invoice(Base):
|
|
__tablename__ = "invoices"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
invoice_number = Column(String(255), unique=True, index=True, nullable=False)
|
|
date_created = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
|
|
due_date = Column(DateTime, nullable=False)
|
|
customer_name = Column(String(255), nullable=False)
|
|
customer_email = Column(String(255), nullable=True)
|
|
customer_address = Column(Text, nullable=True)
|
|
total_amount = Column(Float, nullable=False)
|
|
status = Column(String(50), default="PENDING", nullable=False)
|
|
notes = Column(Text, nullable=True)
|
|
|
|
# Relationship with invoice items
|
|
items = relationship("InvoiceItem", back_populates="invoice", cascade="all, delete-orphan")
|
|
|
|
|
|
class InvoiceItem(Base):
|
|
__tablename__ = "invoice_items"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
invoice_id = Column(Integer, ForeignKey("invoices.id"), nullable=False)
|
|
description = Column(String(255), nullable=False)
|
|
quantity = Column(Float, nullable=False)
|
|
unit_price = Column(Float, nullable=False)
|
|
amount = Column(Float, nullable=False)
|
|
|
|
# Relationship with invoice
|
|
invoice = relationship("Invoice", back_populates="items") |