
Features: - User authentication with JWT - Client management with CRUD operations - Invoice generation and management - SQLite database with Alembic migrations - Detailed project documentation
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
from sqlalchemy import Column, Date, Float, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.models.base import ModelBase, TimestampMixin
|
|
|
|
|
|
class Invoice(ModelBase, TimestampMixin):
|
|
"""
|
|
Invoice model
|
|
"""
|
|
user_id = Column(Integer, ForeignKey("user.id", ondelete="CASCADE"), nullable=False)
|
|
client_id = Column(Integer, ForeignKey("client.id", ondelete="CASCADE"), nullable=False)
|
|
invoice_number = Column(String, nullable=False, index=True)
|
|
status = Column(String, nullable=False, default="draft") # draft, sent, paid
|
|
issued_date = Column(Date, nullable=True)
|
|
due_date = Column(Date, nullable=True)
|
|
notes = Column(Text, nullable=True)
|
|
total_amount = Column(Float, nullable=False, default=0.0)
|
|
pdf_path = Column(String, nullable=True)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="invoices")
|
|
client = relationship("Client", back_populates="invoices")
|
|
items = relationship("InvoiceItem", back_populates="invoice", cascade="all, delete-orphan")
|
|
|
|
|
|
class InvoiceItem(ModelBase, TimestampMixin):
|
|
"""
|
|
Invoice item model
|
|
"""
|
|
invoice_id = Column(Integer, ForeignKey("invoice.id", ondelete="CASCADE"), nullable=False)
|
|
description = Column(String, nullable=False)
|
|
quantity = Column(Float, nullable=False, default=1.0)
|
|
unit_price = Column(Float, nullable=False, default=0.0)
|
|
|
|
# Relationships
|
|
invoice = relationship("Invoice", back_populates="items") |