Spaces:
Sleeping
Sleeping
Commit ·
b415e0c
1
Parent(s): ea7352f
feat: add invoice creation logic with SQLAlchemy
Browse files- models/invoice.py +5 -3
models/invoice.py
CHANGED
|
@@ -6,7 +6,7 @@ from core.database import Base
|
|
| 6 |
class Invoice(Base):
|
| 7 |
__tablename__ = "invoices"
|
| 8 |
|
| 9 |
-
# Auto-incrementing ID
|
| 10 |
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
| 11 |
|
| 12 |
# User selected date (defaults to now)
|
|
@@ -22,14 +22,16 @@ class Invoice(Base):
|
|
| 22 |
|
| 23 |
items = relationship("InvoiceItem", back_populates="invoice", cascade="all, delete-orphan")
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
def invoice_number(self):
|
| 27 |
return f"INV-{self.id:04d}"
|
| 28 |
|
| 29 |
|
| 30 |
class InvoiceItem(Base):
|
| 31 |
__tablename__ = "invoice_items"
|
| 32 |
-
|
|
|
|
| 33 |
invoice_id = Column(Integer, ForeignKey("invoices.id"))
|
| 34 |
description = Column(String)
|
| 35 |
quantity = Column(Integer)
|
|
|
|
| 6 |
class Invoice(Base):
|
| 7 |
__tablename__ = "invoices"
|
| 8 |
|
| 9 |
+
# Auto-incrementing ID
|
| 10 |
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
| 11 |
|
| 12 |
# User selected date (defaults to now)
|
|
|
|
| 22 |
|
| 23 |
items = relationship("InvoiceItem", back_populates="invoice", cascade="all, delete-orphan")
|
| 24 |
|
| 25 |
+
# This MUST be indented inside the class
|
| 26 |
+
@property
|
| 27 |
def invoice_number(self):
|
| 28 |
return f"INV-{self.id:04d}"
|
| 29 |
|
| 30 |
|
| 31 |
class InvoiceItem(Base):
|
| 32 |
__tablename__ = "invoice_items"
|
| 33 |
+
|
| 34 |
+
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
| 35 |
invoice_id = Column(Integer, ForeignKey("invoices.id"))
|
| 36 |
description = Column(String)
|
| 37 |
quantity = Column(Integer)
|