-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
397 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
default_profile = "generate-inv" | ||
default_profile = "linux" | ||
|
||
[profiles.generate-inv] | ||
[profiles.linux] | ||
adapter = "sqlite" | ||
conn_str = [ "/Users/kb/.local/share/generate-inv/generate-inv.db" ] | ||
conn_str = [ | ||
"/home/kb/.local/share/generate-inv/generate-inv.db", | ||
] | ||
keymap_name = [ "vscode" ] | ||
limit = 100000 | ||
theme = "nord" | ||
|
||
[profiles.macos] | ||
adapter = "sqlite" | ||
conn_str = [ | ||
"/Users/kb/.local/share/generate-inv/generate-inv.db", | ||
] | ||
keymap_name = [ "vscode" ] | ||
limit = 100000 | ||
theme = "nord" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"dotenv" | ||
"dotenv", | ||
"pytest" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,74 @@ | ||
"""Database schema for the invoice generator. | ||
Cody instructions: | ||
- Use SQLAlchemy v2.0 and above | ||
- Use sQLAlchemy ORM Unit Work pattern | ||
- Use SQLite for the database | ||
""" | ||
|
||
from sqlalchemy import Float, ForeignKey, Integer, String, create_engine | ||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship | ||
|
||
from . import DB_FILE | ||
|
||
ENGINE = create_engine(f"sqlite:///{DB_FILE}", echo=True, echo_pool=True) | ||
DB_ENGINE = create_engine(f"sqlite:///{DB_FILE}", echo=False) | ||
|
||
|
||
class Base(DeclarativeBase): | ||
class DbBase(DeclarativeBase): | ||
pass | ||
|
||
|
||
class Address(Base): | ||
class DbAddress(DbBase): | ||
"""Address table mirrors Address model in the types.py file.""" | ||
|
||
__tablename__ = "addresses" | ||
|
||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) | ||
address_line1: Mapped[str] = mapped_column(String(255), nullable=False) | ||
address_line2: Mapped[str] = mapped_column(String(255), nullable=True) | ||
city: Mapped[str] = mapped_column(String(100), nullable=False) | ||
province: Mapped[str] = mapped_column(String(100), nullable=False) | ||
postal_code: Mapped[str] = mapped_column(String(7), nullable=False) | ||
country: Mapped[str] = mapped_column(String(100), nullable=False, default="Canada") | ||
address_line1: Mapped[str] = mapped_column(String, nullable=False) | ||
address_line2: Mapped[str] = mapped_column(String, nullable=True) | ||
city: Mapped[str] = mapped_column(String, nullable=False) | ||
province: Mapped[str] = mapped_column(String, nullable=False) | ||
postal_code: Mapped[str] = mapped_column(String, nullable=False) | ||
country: Mapped[str] = mapped_column(String, nullable=False, default="Canada") | ||
|
||
|
||
class Company(Base): | ||
class DbCompany(DbBase): | ||
"""Company table mirrors Company model in the types.py file.""" | ||
|
||
__tablename__ = "companies" | ||
|
||
company_id: Mapped[str] = mapped_column(String(5), primary_key=True) | ||
company_name: Mapped[str] = mapped_column(String(255), nullable=False) | ||
phone_number: Mapped[str] = mapped_column(String(20), nullable=False) | ||
email: Mapped[str] = mapped_column(String(255), nullable=False) | ||
website: Mapped[str] = mapped_column(String(255), nullable=False) | ||
company_id: Mapped[str] = mapped_column(String, primary_key=True) | ||
company_name: Mapped[str] = mapped_column(String, nullable=False) | ||
phone_number: Mapped[str] = mapped_column(String, nullable=False) | ||
email: Mapped[str] = mapped_column(String, nullable=False) | ||
website: Mapped[str] = mapped_column(String, nullable=False) | ||
|
||
# Foreign key relationships for addresses | ||
address_billing_fk: Mapped[int] = mapped_column(ForeignKey("addresses.id"), nullable=False) | ||
address_shipping_fk: Mapped[int] = mapped_column(ForeignKey("addresses.id"), nullable=True) | ||
|
||
# Relationship definitions | ||
address_billing: Mapped["Address"] = relationship("Address", foreign_keys=[address_billing_fk]) | ||
address_shipping: Mapped["Address"] = relationship( | ||
"Address", foreign_keys=[address_shipping_fk] | ||
address_billing: Mapped["DbAddress"] = relationship( | ||
DbAddress, foreign_keys=[address_billing_fk] | ||
) | ||
address_shipping: Mapped["DbAddress"] = relationship( | ||
DbAddress, foreign_keys=[address_shipping_fk] | ||
) | ||
|
||
|
||
class InvoiceItems(Base): | ||
class DbInvoiceItems(DbBase): | ||
"""Invoice items table mirrors InvoiceItem model in the types.py file.""" | ||
|
||
__tablename__ = "invoice_items" | ||
|
||
item_sku: Mapped[str] = mapped_column(String(5), primary_key=True) | ||
item_info: Mapped[str] = mapped_column(String(255), nullable=False) | ||
quantity: Mapped[int] = mapped_column(Integer(), nullable=False) | ||
item_sku: Mapped[str] = mapped_column(String, primary_key=True) | ||
item_info: Mapped[str] = mapped_column(String, nullable=False) | ||
quantity: Mapped[int] = mapped_column(Integer, nullable=False) | ||
unit_price: Mapped[float] = mapped_column(Float(precision=2), nullable=False) | ||
total_price: Mapped[float] = mapped_column(Float(precision=2), nullable=False) | ||
|
||
|
||
DbBase.metadata.create_all(DB_ENGINE) | ||
|
||
|
||
if __name__ == "__main__": | ||
Base.metadata.drop_all(ENGINE) | ||
Base.metadata.create_all(ENGINE) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from pydantic import model_validator | ||
from sqlmodel import Field, SQLModel, create_engine | ||
|
||
from . import DB_FILE | ||
|
||
DB_ENGINE = create_engine(f"sqlite:///{DB_FILE}", echo=False) | ||
|
||
|
||
class InvoiceItem(SQLModel, table=True): | ||
id: int | None = Field( | ||
default=None, | ||
primary_key=True, | ||
) | ||
item_sku: str = Field( | ||
description="Stock Keeping Unit (SKU) number, must be 4 uppercase letters followed by 1 number", | ||
) | ||
item_info: str = Field( | ||
description="Item or service short information description", | ||
) | ||
quantity: int = Field( | ||
description="Quantity of items", | ||
) | ||
unit_price: float = Field( | ||
description="Price per unit", | ||
) | ||
total_price: float = Field( | ||
description="Total price for the item", | ||
default=0.0, | ||
) | ||
|
||
@model_validator(mode="after") | ||
def calculate_total_price(self) -> "InvoiceItem": | ||
self.total_price = self.quantity * self.unit_price | ||
return self | ||
|
||
@property | ||
def unit_price_formatted(self) -> str: | ||
return f"${self.unit_price:,.2f}" | ||
|
||
@property | ||
def total_price_formatted(self) -> str: | ||
return f"${self.total_price:,.2f}" | ||
|
||
|
||
SQLModel.metadata.create_all(DB_ENGINE) | ||
|
||
if __name__ == "__main__": | ||
pass |
Oops, something went wrong.