diff --git a/barker/barker/models/bill.py b/barker/barker/models/bill.py index bbe5c7f8..10688460 100644 --- a/barker/barker/models/bill.py +++ b/barker/barker/models/bill.py @@ -2,8 +2,7 @@ import uuid from typing import TYPE_CHECKING -from sqlalchemy import Boolean, ForeignKey, Integer, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, ForeignKey, Integer, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -22,15 +21,11 @@ class Bill: UniqueConstraint("regime_id", "bill_number"), ) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - regime_id: Mapped[int] = mapped_column("regime_id", Integer, ForeignKey("regimes.id"), nullable=False) - voucher_id: Mapped[uuid.UUID] = mapped_column( - "voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False - ) - is_valid: Mapped[bool] = mapped_column("is_valid", Boolean, nullable=False) - bill_number: Mapped[int] = mapped_column("bill_number", Integer) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + regime_id: Mapped[int] = mapped_column(Integer, ForeignKey("regimes.id"), nullable=False) + voucher_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("vouchers.id"), nullable=False) + is_valid: Mapped[bool] = mapped_column(Boolean, nullable=False) + bill_number: Mapped[int] = mapped_column(Integer, nullable=False) voucher: Mapped["Voucher"] = relationship(back_populates="bills") regime: Mapped["Regime"] = relationship(back_populates="bills") diff --git a/barker/barker/models/customer.py b/barker/barker/models/customer.py index 7488f1a0..999150f4 100644 --- a/barker/barker/models/customer.py +++ b/barker/barker/models/customer.py @@ -1,9 +1,8 @@ import uuid -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List -from sqlalchemy import Boolean, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from sqlalchemy.sql import expression @@ -18,16 +17,12 @@ if TYPE_CHECKING: class Customer: __tablename__ = "customers" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False) - phone: Mapped[str] = mapped_column("phone", Unicode(255), nullable=False, unique=True) - address: Mapped[Optional[str]] = mapped_column("address", Unicode(255), nullable=True) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False) + phone: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + address: Mapped[str | None] = mapped_column(Text, nullable=True) - print_in_bill: Mapped[bool] = mapped_column( - "print_in_bill", Boolean, server_default=expression.false(), insert_default=False, nullable=False - ) + print_in_bill: Mapped[bool] = mapped_column(Boolean, server_default=expression.false(), nullable=False) discounts: Mapped[List["CustomerDiscount"]] = relationship(back_populates="customer") diff --git a/barker/barker/models/customer_discount.py b/barker/barker/models/customer_discount.py index 325be739..5418a79b 100644 --- a/barker/barker/models/customer_discount.py +++ b/barker/barker/models/customer_discount.py @@ -4,8 +4,7 @@ from datetime import datetime from decimal import Decimal from typing import TYPE_CHECKING -from sqlalchemy import ForeignKey, Numeric, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, Numeric, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -21,16 +20,10 @@ class CustomerDiscount: __tablename__ = "customer_discount" __table_args__ = (UniqueConstraint("customer_id", "sale_category_id"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - customer_id: Mapped[uuid.UUID] = mapped_column( - "customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=False - ) - sale_category_id: Mapped[uuid.UUID] = mapped_column( - "sale_category_id", UUID(as_uuid=True), ForeignKey("sale_categories.id"), nullable=False - ) - discount: Mapped[Decimal] = mapped_column("discount", Numeric(precision=15, scale=5), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + customer_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("customers.id"), nullable=False) + sale_category_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sale_categories.id"), nullable=False) + discount: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False) customer: Mapped["Customer"] = relationship(back_populates="discounts") sale_category: Mapped["SaleCategory"] = relationship("SaleCategory") diff --git a/barker/barker/models/db_setting.py b/barker/barker/models/db_setting.py index 1bdd01a9..fb084aa8 100644 --- a/barker/barker/models/db_setting.py +++ b/barker/barker/models/db_setting.py @@ -1,7 +1,6 @@ import uuid -from sqlalchemy import JSON, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import JSON, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column from ..db.base_class import reg @@ -11,11 +10,9 @@ from ..db.base_class import reg class DbSetting: __tablename__ = "settings" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) - data = mapped_column("data", JSON) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) + data = mapped_column(JSON, nullable=False) def __init__(self, id_=None, name=None, data=None): self.id = id_ diff --git a/barker/barker/models/device.py b/barker/barker/models/device.py index f2be1b5c..e56b93ea 100644 --- a/barker/barker/models/device.py +++ b/barker/barker/models/device.py @@ -6,8 +6,7 @@ from datetime import datetime from typing import TYPE_CHECKING, List from barker.models.login_history import LoginHistory -from sqlalchemy import Boolean, DateTime, ForeignKey, Unicode, desc, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, DateTime, ForeignKey, Text, Uuid, desc, text from sqlalchemy.orm import Mapped, Session, mapped_column, relationship from ..db.base_class import reg @@ -21,15 +20,11 @@ if TYPE_CHECKING: class Device: __tablename__ = "devices" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) - enabled: Mapped[bool] = mapped_column("enabled", Boolean, nullable=False) - section_id: Mapped[uuid.UUID] = mapped_column( - "section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False - ) - creation_date: Mapped[datetime] = mapped_column("creation_date", DateTime(), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) + enabled: Mapped[bool] = mapped_column(Boolean, nullable=False) + section_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sections.id"), nullable=False) + creation_date: Mapped[datetime] = mapped_column(DateTime(), nullable=False) section: Mapped["Section"] = relationship(back_populates="devices") login_history: Mapped[List["LoginHistory"]] = relationship( diff --git a/barker/barker/models/food_table.py b/barker/barker/models/food_table.py index 7ff34522..912d1299 100644 --- a/barker/barker/models/food_table.py +++ b/barker/barker/models/food_table.py @@ -1,9 +1,8 @@ import uuid -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING -from sqlalchemy import Boolean, ForeignKey, Integer, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, ForeignKey, Integer, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -18,19 +17,15 @@ if TYPE_CHECKING: class FoodTable: __tablename__ = "food_tables" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) - seats: Mapped[int] = mapped_column("seats", Integer, nullable=False) - section_id: Mapped[uuid.UUID] = mapped_column( - "section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False - ) - is_active: Mapped[bool] = mapped_column("is_active", Boolean, nullable=False) - sort_order: Mapped[bool] = mapped_column("sort_order", Integer, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + seats: Mapped[int] = mapped_column(Integer, nullable=False) + section_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sections.id"), nullable=False) + is_active: Mapped[bool] = mapped_column(Boolean, nullable=False) + sort_order: Mapped[bool] = mapped_column(Integer, nullable=False) section: Mapped["Section"] = relationship("Section", foreign_keys=section_id) - status: Mapped[Optional["Overview"]] = relationship(back_populates="food_table", uselist=False) + status: Mapped["Overview" | None] = relationship(back_populates="food_table", uselist=False) @property def __name__(self): diff --git a/barker/barker/models/guest_book.py b/barker/barker/models/guest_book.py index efbf4f6b..29ff5095 100644 --- a/barker/barker/models/guest_book.py +++ b/barker/barker/models/guest_book.py @@ -1,10 +1,9 @@ import uuid from datetime import datetime -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING -from sqlalchemy import DateTime, ForeignKey, Integer, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import DateTime, ForeignKey, Integer, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -18,17 +17,13 @@ if TYPE_CHECKING: @reg.mapped_as_dataclass(unsafe_hash=True) class GuestBook: __tablename__ = "guest_book" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - customer_id: Mapped[uuid.UUID] = mapped_column( - "customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=False - ) - pax: Mapped[int] = mapped_column("pax", Integer, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + customer_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("customers.id"), nullable=False) + pax: Mapped[int] = mapped_column(Integer, nullable=False) date: Mapped[datetime] = mapped_column("creation_date", DateTime(), nullable=False) customer: Mapped["Customer"] = relationship("Customer") - status: Mapped[Optional["Overview"]] = relationship(back_populates="guest", uselist=False) + status: Mapped["Overview" | None] = relationship(back_populates="guest", uselist=False) def __init__(self, pax=None, id_=None, customer_id=None, customer=None, date_=None): self.customer_id = customer_id diff --git a/barker/barker/models/inventory.py b/barker/barker/models/inventory.py index a3697b20..7ec2fffc 100644 --- a/barker/barker/models/inventory.py +++ b/barker/barker/models/inventory.py @@ -11,12 +11,12 @@ from sqlalchemy import ( Integer, Numeric, UniqueConstraint, + Uuid, case, func, text, type_coerce, ) -from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import Mapped, mapped_column, relationship @@ -34,22 +34,16 @@ class Inventory: __tablename__ = "inventories" __table_args__ = (UniqueConstraint("kot_id", "product_id", "is_happy_hour", "price"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - kot_id: Mapped[uuid.UUID] = mapped_column( - "kot_id", UUID(as_uuid=True), ForeignKey("kots.id"), nullable=False, index=True - ) - product_id: Mapped[uuid.UUID] = mapped_column( - "product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False - ) - quantity: Mapped[Decimal] = mapped_column("quantity", Numeric(precision=15, scale=2), nullable=False) - price: Mapped[Decimal] = mapped_column("price", Numeric(precision=15, scale=2), nullable=False) - is_happy_hour: Mapped[bool] = mapped_column("is_happy_hour", Boolean, nullable=False) - tax_rate: Mapped[Decimal] = mapped_column("tax_rate", Numeric(precision=15, scale=5), nullable=False) - tax_id: Mapped[uuid.UUID] = mapped_column("tax_id", UUID(as_uuid=True), ForeignKey("taxes.id"), nullable=False) - discount: Mapped[Decimal] = mapped_column("discount", Numeric(precision=15, scale=5), nullable=False) - sort_order: Mapped[int] = mapped_column("sort_order", Integer, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + kot_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("kots.id"), nullable=False, index=True) + product_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("products.id"), nullable=False) + quantity: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) + price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) + is_happy_hour: Mapped[bool] = mapped_column(Boolean, nullable=False) + tax_rate: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False) + tax_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("taxes.id"), nullable=False) + discount: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False) + sort_order: Mapped[int] = mapped_column(Integer, nullable=False) kot: Mapped["Kot"] = relationship(back_populates="inventories") tax: Mapped["Tax"] = relationship(back_populates="inventories") diff --git a/barker/barker/models/inventory_modifier.py b/barker/barker/models/inventory_modifier.py index 93472ef7..98106624 100644 --- a/barker/barker/models/inventory_modifier.py +++ b/barker/barker/models/inventory_modifier.py @@ -3,8 +3,7 @@ import uuid from decimal import Decimal from typing import TYPE_CHECKING -from sqlalchemy import ForeignKey, Numeric, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, Numeric, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -20,16 +19,10 @@ class InventoryModifier: __tablename__ = "inventory_modifiers" __table_args__ = (UniqueConstraint("inventory_id", "modifier_id"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - inventory_id: Mapped[uuid.UUID] = mapped_column( - "inventory_id", UUID(as_uuid=True), ForeignKey("inventories.id"), nullable=False - ) - modifier_id: Mapped[uuid.UUID] = mapped_column( - "modifier_id", UUID(as_uuid=True), ForeignKey("modifiers.id"), nullable=False - ) - price: Mapped[Decimal] = mapped_column("price", Numeric(precision=15, scale=2), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + inventory_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("inventories.id"), nullable=False) + modifier_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("modifiers.id"), nullable=False) + price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) inventory: Mapped["Inventory"] = relationship(back_populates="modifiers") modifier: Mapped["Modifier"] = relationship("Modifier") diff --git a/barker/barker/models/kot.py b/barker/barker/models/kot.py index e67a6351..66e85d5f 100644 --- a/barker/barker/models/kot.py +++ b/barker/barker/models/kot.py @@ -3,8 +3,7 @@ import uuid from datetime import datetime from typing import TYPE_CHECKING, List -from sqlalchemy import DateTime, ForeignKey, Integer, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import DateTime, ForeignKey, Integer, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -21,25 +20,21 @@ if TYPE_CHECKING: class Kot: __tablename__ = "kots" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) voucher_id: Mapped[uuid.UUID] = mapped_column( - "voucher_id", - UUID(as_uuid=True), + Uuid, ForeignKey("vouchers.id"), nullable=False, index=True, ) - code: Mapped[int] = mapped_column("code", Integer, nullable=False, unique=True) + code: Mapped[int] = mapped_column(Integer, nullable=False, unique=True) food_table_id: Mapped[uuid.UUID] = mapped_column( - "food_table_id", - UUID(as_uuid=True), + Uuid, ForeignKey("food_tables.id"), nullable=False, ) - date: Mapped[datetime] = mapped_column("date", DateTime, nullable=False, index=True) - user_id: Mapped[uuid.UUID] = mapped_column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) + date: Mapped[datetime] = mapped_column(DateTime, nullable=False, index=True) + user_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("users.id"), nullable=False) voucher: Mapped["Voucher"] = relationship(back_populates="kots") user: Mapped["User"] = relationship(backref="kots") diff --git a/barker/barker/models/login_history.py b/barker/barker/models/login_history.py index 989dd072..9447676a 100644 --- a/barker/barker/models/login_history.py +++ b/barker/barker/models/login_history.py @@ -3,8 +3,7 @@ import uuid from datetime import datetime from typing import TYPE_CHECKING -from sqlalchemy import DateTime, ForeignKey, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import DateTime, ForeignKey, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -19,17 +18,14 @@ if TYPE_CHECKING: class LoginHistory: __tablename__ = "login_history" __table_args__ = (UniqueConstraint("user_id", "device_id", "date"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - user_id: Mapped[uuid.UUID] = mapped_column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + user_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("users.id"), nullable=False) device_id: Mapped[uuid.UUID] = mapped_column( - "device_id", - UUID(as_uuid=True), + Uuid, ForeignKey("devices.id"), nullable=False, ) - date: Mapped[datetime] = mapped_column("date", DateTime(), nullable=False) + date: Mapped[datetime] = mapped_column(DateTime(), nullable=False) device: Mapped["Device"] = relationship(back_populates="login_history") user: Mapped["User"] = relationship(back_populates="login_history") diff --git a/barker/barker/models/menu_category.py b/barker/barker/models/menu_category.py index 866e79ff..536bee7b 100644 --- a/barker/barker/models/menu_category.py +++ b/barker/barker/models/menu_category.py @@ -2,8 +2,7 @@ import uuid from typing import TYPE_CHECKING, List -from sqlalchemy import Boolean, Integer, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, Integer, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -17,14 +16,12 @@ if TYPE_CHECKING: class MenuCategory: __tablename__ = "menu_categories" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) - is_active: Mapped[bool] = mapped_column("is_active", Boolean, nullable=False) - is_fixture: Mapped[bool] = mapped_column("is_fixture", Boolean, nullable=False) - sort_order: Mapped[int] = mapped_column("sort_order", Integer, nullable=False) + is_active: Mapped[bool] = mapped_column(Boolean, nullable=False) + is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False) + sort_order: Mapped[int] = mapped_column(Integer, nullable=False) products: Mapped[List["ProductVersion"]] = relationship(back_populates="menu_category") diff --git a/barker/barker/models/modifier.py b/barker/barker/models/modifier.py index 3e861cc0..7950b29f 100644 --- a/barker/barker/models/modifier.py +++ b/barker/barker/models/modifier.py @@ -3,8 +3,7 @@ import uuid from decimal import Decimal from typing import TYPE_CHECKING -from sqlalchemy import Boolean, ForeignKey, Numeric, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, ForeignKey, Numeric, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -18,16 +17,13 @@ if TYPE_CHECKING: class Modifier: __tablename__ = "modifiers" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) - show_in_bill: Mapped[bool] = mapped_column("show_in_bill", Boolean, nullable=False) - price: Mapped[Decimal] = mapped_column("price", Numeric(precision=15, scale=2), nullable=False) - is_active: Mapped[bool] = mapped_column("is_active", Boolean, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + show_in_bill: Mapped[bool] = mapped_column(Boolean, nullable=False) + price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) + is_active: Mapped[bool] = mapped_column(Boolean, nullable=False) modifier_category_id: Mapped[uuid.UUID] = mapped_column( - "modifier_category_id", - UUID(as_uuid=True), + Uuid, ForeignKey("modifier_categories.id"), nullable=False, ) diff --git a/barker/barker/models/modifier_category.py b/barker/barker/models/modifier_category.py index b9245eb8..45eb6449 100644 --- a/barker/barker/models/modifier_category.py +++ b/barker/barker/models/modifier_category.py @@ -1,10 +1,9 @@ import uuid -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List from barker.models.modifier_category_product import ModifierCategoryProduct -from sqlalchemy import Boolean, Integer, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, Integer, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -19,14 +18,12 @@ if TYPE_CHECKING: class ModifierCategory: __tablename__ = "modifier_categories" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) - minimum: Mapped[int] = mapped_column("minimum", Integer, nullable=False) - maximum: Mapped[Optional[int]] = mapped_column("maximum", Integer, nullable=True) - is_active: Mapped[bool] = mapped_column("is_active", Boolean, nullable=False) - sort_order: Mapped[int] = mapped_column("sort_order", Integer, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + minimum: Mapped[int] = mapped_column(Integer, nullable=False) + maximum: Mapped[int | None] = mapped_column(Integer, nullable=True) + is_active: Mapped[bool] = mapped_column(Boolean, nullable=False) + sort_order: Mapped[int] = mapped_column(Integer, nullable=False) products: Mapped[List["Product"]] = relationship( secondary=ModifierCategoryProduct.__table__, # type: ignore[attr-defined] diff --git a/barker/barker/models/modifier_category_product.py b/barker/barker/models/modifier_category_product.py index e76a20f2..0ad8f012 100644 --- a/barker/barker/models/modifier_category_product.py +++ b/barker/barker/models/modifier_category_product.py @@ -1,7 +1,6 @@ import uuid -from sqlalchemy import ForeignKey, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column from ..db.base_class import reg @@ -12,15 +11,10 @@ class ModifierCategoryProduct: __tablename__ = "modifier_categories_products" __table_args__ = (UniqueConstraint("product_id", "modifier_category_id"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - product_id: Mapped[uuid.UUID] = mapped_column( - "product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False - ) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + product_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("products.id"), nullable=False) modifier_category_id: Mapped[uuid.UUID] = mapped_column( - "modifier_category_id", - UUID(as_uuid=True), + Uuid, ForeignKey("modifier_categories.id"), nullable=False, ) diff --git a/barker/barker/models/overview.py b/barker/barker/models/overview.py index f5fea541..6f9d3813 100644 --- a/barker/barker/models/overview.py +++ b/barker/barker/models/overview.py @@ -2,8 +2,7 @@ import uuid from typing import TYPE_CHECKING -from sqlalchemy import ForeignKey, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -18,27 +17,21 @@ if TYPE_CHECKING: @reg.mapped_as_dataclass(unsafe_hash=True) class Overview: __tablename__ = "overview" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) voucher_id: Mapped[uuid.UUID] = mapped_column( - "voucher_id", - UUID(as_uuid=True), + Uuid, ForeignKey("vouchers.id"), nullable=False, unique=True, ) food_table_id: Mapped[uuid.UUID] = mapped_column( - "food_table_id", - UUID(as_uuid=True), + Uuid, ForeignKey("food_tables.id"), nullable=False, unique=True, ) - guest_book_id: Mapped[uuid.UUID] = mapped_column( - "guest_book_id", UUID(as_uuid=True), ForeignKey("guest_book.id"), unique=True, nullable=True - ) - status: Mapped[str] = mapped_column("status", Unicode(255), nullable=False) + guest_book_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("guest_book.id"), unique=True, nullable=True) + status: Mapped[str] = mapped_column(Text, nullable=False) voucher: Mapped["Voucher"] = relationship(back_populates="status") food_table: Mapped["FoodTable"] = relationship(back_populates="status") diff --git a/barker/barker/models/permission.py b/barker/barker/models/permission.py index 445947e7..2ccdb74a 100644 --- a/barker/barker/models/permission.py +++ b/barker/barker/models/permission.py @@ -2,8 +2,7 @@ import uuid from typing import TYPE_CHECKING, List -from sqlalchemy import Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -18,10 +17,8 @@ if TYPE_CHECKING: class Permission: __tablename__ = "permissions" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) roles: Mapped[List["Role"]] = relationship( secondary=RolePermission.__table__, back_populates="permissions" # type: ignore[attr-defined] diff --git a/barker/barker/models/printer.py b/barker/barker/models/printer.py index 65948c77..918b4138 100644 --- a/barker/barker/models/printer.py +++ b/barker/barker/models/printer.py @@ -1,7 +1,6 @@ import uuid -from sqlalchemy import Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column from ..db.base_class import reg @@ -11,12 +10,10 @@ from ..db.base_class import reg class Printer: __tablename__ = "printers" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) - address: Mapped[str] = mapped_column("address", Unicode(255), nullable=False) - cut_code: Mapped[str] = mapped_column("cut_code", Unicode(255), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) + address: Mapped[str] = mapped_column(Text, nullable=False) + cut_code: Mapped[str] = mapped_column(Text, nullable=False) def __init__(self, name=None, address=None, cut_code=None, id_=None): self.id = id_ diff --git a/barker/barker/models/product.py b/barker/barker/models/product.py index d86b08aa..9e1a5a43 100644 --- a/barker/barker/models/product.py +++ b/barker/barker/models/product.py @@ -3,8 +3,7 @@ import uuid from typing import TYPE_CHECKING, List from barker.models.modifier_category_product import ModifierCategoryProduct -from sqlalchemy import text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -19,9 +18,7 @@ if TYPE_CHECKING: @reg.mapped_as_dataclass(unsafe_hash=True) class Product: __tablename__ = "products" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) versions: Mapped[List["ProductVersion"]] = relationship(back_populates="product") inventories: Mapped[List["Inventory"]] = relationship(back_populates="product") modifier_categories: Mapped[List["ModifierCategory"]] = relationship( diff --git a/barker/barker/models/product_version.py b/barker/barker/models/product_version.py index ff0428b7..f6af8fd5 100644 --- a/barker/barker/models/product_version.py +++ b/barker/barker/models/product_version.py @@ -2,7 +2,7 @@ import uuid from datetime import date from decimal import Decimal -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING from barker.models.product import Product from sqlalchemy import ( @@ -11,13 +11,13 @@ from sqlalchemy import ( ForeignKey, Integer, Numeric, - Unicode, + Text, + Uuid, case, func, text, ) from sqlalchemy.dialects import postgresql -from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import Mapped, mapped_column, relationship @@ -32,34 +32,28 @@ if TYPE_CHECKING: @reg.mapped_as_dataclass(unsafe_hash=True) class ProductVersion: __tablename__ = "product_versions" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - product_id: Mapped[uuid.UUID] = mapped_column( - "product_id", UUID(as_uuid=True), ForeignKey("products.id"), nullable=False - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False) - units: Mapped[str] = mapped_column("units", Unicode(255), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + product_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("products.id"), nullable=False) + name: Mapped[str] = mapped_column(Text, nullable=False) + units: Mapped[str] = mapped_column(Text, nullable=False) menu_category_id: Mapped[uuid.UUID] = mapped_column( - "menu_category_id", - UUID(as_uuid=True), + Uuid, ForeignKey("menu_categories.id"), nullable=False, ) sale_category_id: Mapped[uuid.UUID] = mapped_column( - "sale_category_id", - UUID(as_uuid=True), + Uuid, ForeignKey("sale_categories.id"), nullable=False, ) - price: Mapped[Decimal] = mapped_column("price", Numeric(precision=15, scale=2), nullable=False) - has_happy_hour: Mapped[bool] = mapped_column("has_happy_hour", Boolean, nullable=False) - is_not_available: Mapped[bool] = mapped_column("is_not_available", Boolean, nullable=False) - quantity: Mapped[Decimal] = mapped_column("quantity", Numeric(precision=15, scale=2), nullable=False) - sort_order: Mapped[int] = mapped_column("sort_order", Integer, nullable=False) + price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) + has_happy_hour: Mapped[bool] = mapped_column(Boolean, nullable=False) + is_not_available: Mapped[bool] = mapped_column(Boolean, nullable=False) + quantity: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) + sort_order: Mapped[int] = mapped_column(Integer, nullable=False) - valid_from: Mapped[Optional[date]] = mapped_column("valid_from", Date(), nullable=True) - valid_till: Mapped[Optional[date]] = mapped_column("valid_till", Date(), nullable=True) + valid_from: Mapped[date | None] = mapped_column(Date(), nullable=True) + valid_till: Mapped[date | None] = mapped_column(Date(), nullable=True) menu_category: Mapped["MenuCategory"] = relationship(back_populates="products") sale_category: Mapped["SaleCategory"] = relationship(back_populates="products") diff --git a/barker/barker/models/regime.py b/barker/barker/models/regime.py index 5ecac1cd..f16eb915 100644 --- a/barker/barker/models/regime.py +++ b/barker/barker/models/regime.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, List -from sqlalchemy import Boolean, Integer, Unicode +from sqlalchemy import Boolean, Integer, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -15,11 +15,11 @@ if TYPE_CHECKING: class Regime: __tablename__ = "regimes" - id: Mapped[int] = mapped_column("id", Integer, primary_key=True) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) - header: Mapped[str] = mapped_column("header", Unicode(255), nullable=False) - prefix: Mapped[str] = mapped_column("prefix", Unicode(255), nullable=False, unique=True) - is_fixture: Mapped[bool] = mapped_column("is_fixture", Boolean, nullable=False) + id: Mapped[int] = mapped_column(Integer, primary_key=True) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + header: Mapped[str] = mapped_column(Text, nullable=False) + prefix: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False) taxes: Mapped[List["Tax"]] = relationship(back_populates="regime") bills: Mapped[List["Bill"]] = relationship(back_populates="regime") diff --git a/barker/barker/models/reprint.py b/barker/barker/models/reprint.py index e560bc0c..79f3a7ea 100644 --- a/barker/barker/models/reprint.py +++ b/barker/barker/models/reprint.py @@ -3,8 +3,7 @@ import uuid from datetime import datetime from typing import TYPE_CHECKING -from sqlalchemy import DateTime, ForeignKey, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import DateTime, ForeignKey, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -19,18 +18,15 @@ if TYPE_CHECKING: class Reprint: __tablename__ = "reprints" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - date: Mapped[datetime] = mapped_column("date", DateTime, nullable=False, index=True) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + date: Mapped[datetime] = mapped_column(DateTime, nullable=False, index=True) voucher_id: Mapped[uuid.UUID] = mapped_column( - "voucher_id", - UUID(as_uuid=True), + Uuid, ForeignKey("vouchers.id"), nullable=False, index=True, ) - user_id: Mapped[uuid.UUID] = mapped_column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) + user_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("users.id"), nullable=False) user: Mapped["User"] = relationship(backref="reprints") voucher: Mapped["Voucher"] = relationship(back_populates="reprints") diff --git a/barker/barker/models/role.py b/barker/barker/models/role.py index abc9a34c..bf266c11 100644 --- a/barker/barker/models/role.py +++ b/barker/barker/models/role.py @@ -3,8 +3,7 @@ import uuid from typing import TYPE_CHECKING, List from barker.models.role_permission import RolePermission -from sqlalchemy import Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -18,10 +17,8 @@ if TYPE_CHECKING: class Role: __tablename__ = "roles" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) permissions: Mapped[List["Permission"]] = relationship( "Permission", secondary=RolePermission.__table__, back_populates="roles" # type: ignore[attr-defined] diff --git a/barker/barker/models/role_permission.py b/barker/barker/models/role_permission.py index 36261d0b..caf9f9f0 100644 --- a/barker/barker/models/role_permission.py +++ b/barker/barker/models/role_permission.py @@ -1,7 +1,6 @@ import uuid -from sqlalchemy import ForeignKey, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column from ..db.base_class import reg @@ -11,13 +10,10 @@ from ..db.base_class import reg class RolePermission: __tablename__ = "role_permissions" __table_args__ = (UniqueConstraint("permission_id", "role_id"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) permission_id: Mapped[uuid.UUID] = mapped_column( - "permission_id", - UUID(as_uuid=True), + Uuid, ForeignKey("permissions.id"), nullable=False, ) - role_id: Mapped[uuid.UUID] = mapped_column("role_id", UUID(as_uuid=True), ForeignKey("roles.id"), nullable=False) + role_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("roles.id"), nullable=False) diff --git a/barker/barker/models/sale_category.py b/barker/barker/models/sale_category.py index e5991644..8d01c83b 100644 --- a/barker/barker/models/sale_category.py +++ b/barker/barker/models/sale_category.py @@ -3,8 +3,7 @@ import uuid from decimal import Decimal from typing import TYPE_CHECKING, List -from sqlalchemy import ForeignKey, Numeric, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, Numeric, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -19,12 +18,10 @@ if TYPE_CHECKING: class SaleCategory: __tablename__ = "sale_categories" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) - discount_limit: Mapped[Decimal] = mapped_column("discount_limit", Numeric(precision=15, scale=5), nullable=False) - tax_id: Mapped[uuid.UUID] = mapped_column("tax_id", UUID(as_uuid=True), ForeignKey("taxes.id"), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + discount_limit: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False) + tax_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("taxes.id"), nullable=False) tax: Mapped["Tax"] = relationship(back_populates="sale_categories") products: Mapped[List["ProductVersion"]] = relationship(back_populates="sale_category") diff --git a/barker/barker/models/section.py b/barker/barker/models/section.py index bbd5ec0e..25f27b50 100644 --- a/barker/barker/models/section.py +++ b/barker/barker/models/section.py @@ -2,8 +2,7 @@ import uuid from typing import TYPE_CHECKING, List -from sqlalchemy import Boolean, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -17,11 +16,9 @@ if TYPE_CHECKING: class Section: __tablename__ = "sections" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) - is_fixture: Mapped[bool] = mapped_column("is_fixture", Boolean, nullable=False, insert_default=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) + is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False, insert_default=False) devices: Mapped[List["Device"]] = relationship(back_populates="section") diff --git a/barker/barker/models/section_printer.py b/barker/barker/models/section_printer.py index 1d44a0ed..7bd7db7a 100644 --- a/barker/barker/models/section_printer.py +++ b/barker/barker/models/section_printer.py @@ -2,8 +2,7 @@ import uuid from typing import TYPE_CHECKING -from sqlalchemy import ForeignKey, Integer, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, Integer, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -20,19 +19,11 @@ class SectionPrinter: __tablename__ = "section_printers" __table_args__ = (UniqueConstraint("sale_category_id", "section_id"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - sale_category_id: Mapped[uuid.UUID] = mapped_column( - "sale_category_id", UUID(as_uuid=True), ForeignKey("sale_categories.id"), nullable=True - ) - section_id: Mapped[uuid.UUID] = mapped_column( - "section_id", UUID(as_uuid=True), ForeignKey("sections.id"), nullable=False - ) - printer_id: Mapped[uuid.UUID] = mapped_column( - "printer_id", UUID(as_uuid=True), ForeignKey("printers.id"), nullable=False - ) - copies: Mapped[int] = mapped_column("copies", Integer, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + sale_category_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sale_categories.id"), nullable=True) + section_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("sections.id"), nullable=False) + printer_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("printers.id"), nullable=False) + copies: Mapped[int] = mapped_column(Integer, nullable=False) sale_category: Mapped["SaleCategory"] = relationship(backref="section_printers") section: Mapped["Section"] = relationship(backref="section_printers") diff --git a/barker/barker/models/settle_option.py b/barker/barker/models/settle_option.py index ef335638..355c7377 100644 --- a/barker/barker/models/settle_option.py +++ b/barker/barker/models/settle_option.py @@ -1,6 +1,6 @@ from barker.models.reporting_level import ReportingLevel from barker.models.voucher_type import VoucherType -from sqlalchemy import Boolean, Enum, Integer, Unicode +from sqlalchemy import Boolean, Enum, Integer, Text from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.sql import expression @@ -11,16 +11,12 @@ from ..db.base_class import reg class SettleOption: __tablename__ = "settle_options" - id: Mapped[int] = mapped_column("id", Integer, primary_key=True) - name: Mapped[str] = mapped_column("name", Unicode(255), unique=True, nullable=False) - voucher_type: Mapped[VoucherType] = mapped_column("voucher_type", Enum(VoucherType), nullable=False) - reporting_level: Mapped[ReportingLevel] = mapped_column("reporting_level", Enum(ReportingLevel), nullable=False) - has_reason: Mapped[bool] = mapped_column( - "has_reason", Boolean, nullable=False, server_default=expression.false(), insert_default=False - ) - is_fixture: Mapped[bool] = mapped_column( - "is_fixture", Boolean, nullable=False, server_default=expression.false(), insert_default=False - ) + id: Mapped[int] = mapped_column(Integer, primary_key=True) + name: Mapped[str] = mapped_column(Text, unique=True, nullable=False) + voucher_type: Mapped[VoucherType] = mapped_column(Enum(VoucherType), nullable=False) + reporting_level: Mapped[ReportingLevel] = mapped_column(Enum(ReportingLevel), nullable=False) + has_reason: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default=expression.false()) + is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default=expression.false()) def __init__(self, name=None, voucher_type=None, reporting_level=None, has_reason=None, is_fixture=None, id_=None): self.id = id_ diff --git a/barker/barker/models/settlement.py b/barker/barker/models/settlement.py index 301e6b08..55e8b119 100644 --- a/barker/barker/models/settlement.py +++ b/barker/barker/models/settlement.py @@ -3,8 +3,7 @@ import uuid from decimal import Decimal from typing import TYPE_CHECKING -from sqlalchemy import ForeignKey, Integer, Numeric, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, Integer, Numeric, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -20,18 +19,15 @@ class Settlement: __tablename__ = "settlements" __table_args__ = (UniqueConstraint("voucher_id", "settled"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) voucher_id: Mapped[uuid.UUID] = mapped_column( - "voucher_id", - UUID(as_uuid=True), + Uuid, ForeignKey("vouchers.id"), nullable=False, index=True, ) - settled: Mapped[int] = mapped_column("settled", Integer, ForeignKey("settle_options.id"), nullable=False) - amount: Mapped[Decimal] = mapped_column("amount", Numeric(precision=15, scale=2), nullable=False) + settled: Mapped[int] = mapped_column(Integer, ForeignKey("settle_options.id"), nullable=False) + amount: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False) settle_option: Mapped["SettleOption"] = relationship("SettleOption") voucher: Mapped["Voucher"] = relationship(back_populates="settlements") diff --git a/barker/barker/models/tax.py b/barker/barker/models/tax.py index d6b3aaf1..9344d08f 100644 --- a/barker/barker/models/tax.py +++ b/barker/barker/models/tax.py @@ -3,8 +3,7 @@ import uuid from decimal import Decimal from typing import TYPE_CHECKING, List -from sqlalchemy import Boolean, ForeignKey, Integer, Numeric, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, ForeignKey, Integer, Numeric, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -20,13 +19,11 @@ if TYPE_CHECKING: class Tax: __tablename__ = "taxes" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False, unique=True) - rate: Mapped[Decimal] = mapped_column("rate", Numeric(precision=15, scale=5), nullable=False) - regime_id: Mapped[int] = mapped_column("regime_id", Integer, ForeignKey("regimes.id"), nullable=False) - is_fixture: Mapped[bool] = mapped_column("is_fixture", Boolean, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False, unique=True) + rate: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=5), nullable=False) + regime_id: Mapped[int] = mapped_column(Integer, ForeignKey("regimes.id"), nullable=False) + is_fixture: Mapped[bool] = mapped_column(Boolean, nullable=False) sale_categories: Mapped[List["SaleCategory"]] = relationship(back_populates="tax") inventories: Mapped[List["Inventory"]] = relationship(back_populates="tax") diff --git a/barker/barker/models/user.py b/barker/barker/models/user.py index 80f1da12..1a2f3d09 100644 --- a/barker/barker/models/user.py +++ b/barker/barker/models/user.py @@ -5,8 +5,7 @@ from typing import TYPE_CHECKING, List from barker.models.login_history import LoginHistory from barker.models.user_role import UserRole -from sqlalchemy import Boolean, Index, Unicode, desc, func, select, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import Boolean, Index, Text, Uuid, desc, func, select, text from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import Mapped, Session, mapped_column, relationship @@ -20,12 +19,10 @@ if TYPE_CHECKING: @reg.mapped_as_dataclass(unsafe_hash=True) class User: __tablename__ = "users" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False) - _password: Mapped[str] = mapped_column("password", Unicode(60), nullable=False) - locked_out: Mapped[bool] = mapped_column("locked_out", Boolean, nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + name: Mapped[str] = mapped_column(Text, nullable=False) + _password: Mapped[str] = mapped_column("password", Text, nullable=False) + locked_out: Mapped[bool] = mapped_column(Boolean, nullable=False) roles: Mapped[List["Role"]] = relationship( "Role", secondary=UserRole.__table__, order_by="Role.name" # type: ignore[attr-defined] diff --git a/barker/barker/models/user_role.py b/barker/barker/models/user_role.py index 3e48ddb1..69efa7b2 100644 --- a/barker/barker/models/user_role.py +++ b/barker/barker/models/user_role.py @@ -1,7 +1,6 @@ import uuid -from sqlalchemy import ForeignKey, UniqueConstraint, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import ForeignKey, UniqueConstraint, Uuid, text from sqlalchemy.orm import Mapped, mapped_column from ..db.base_class import reg @@ -12,8 +11,6 @@ class UserRole: __tablename__ = "user_roles" __table_args__ = (UniqueConstraint("user_id", "role_id"),) - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - user_id: Mapped[uuid.UUID] = mapped_column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) - role_id: Mapped[uuid.UUID] = mapped_column("role_id", UUID(as_uuid=True), ForeignKey("roles.id"), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + user_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("users.id"), nullable=False) + role_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("roles.id"), nullable=False) diff --git a/barker/barker/models/voucher.py b/barker/barker/models/voucher.py index 02e64dea..97a6f185 100644 --- a/barker/barker/models/voucher.py +++ b/barker/barker/models/voucher.py @@ -1,10 +1,9 @@ import uuid from datetime import datetime -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List -from sqlalchemy import DateTime, Enum, ForeignKey, Integer, Unicode, text -from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy import DateTime, Enum, ForeignKey, Integer, Text, Uuid, text from sqlalchemy.orm import Mapped, mapped_column, relationship from ..db.base_class import reg @@ -26,27 +25,22 @@ if TYPE_CHECKING: class Voucher: __tablename__ = "vouchers" - id: Mapped[uuid.UUID] = mapped_column( - "id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4 - ) - date: Mapped[datetime] = mapped_column("date", DateTime, nullable=False, index=True) - pax: Mapped[int] = mapped_column("pax", Integer, nullable=False) - kot_id: Mapped[uuid.UUID] = mapped_column("kot_id", Integer, nullable=False, unique=True) - creation_date: Mapped[datetime] = mapped_column("creation_date", DateTime(), nullable=False) - last_edit_date: Mapped[datetime] = mapped_column("last_edit_date", DateTime(), nullable=False) + id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()")) + date: Mapped[datetime] = mapped_column(DateTime, nullable=False, index=True) + pax: Mapped[int] = mapped_column(Integer, nullable=False) + kot_id: Mapped[uuid.UUID] = mapped_column(Integer, nullable=False, unique=True) + creation_date: Mapped[datetime] = mapped_column(DateTime(), nullable=False) + last_edit_date: Mapped[datetime] = mapped_column(DateTime(), nullable=False) food_table_id: Mapped[uuid.UUID] = mapped_column( - "food_table_id", - UUID(as_uuid=True), + Uuid, ForeignKey("food_tables.id"), nullable=False, ) - customer_id: Mapped[uuid.UUID | None] = mapped_column( - "customer_id", UUID(as_uuid=True), ForeignKey("customers.id"), nullable=True - ) - narration: Mapped[str] = mapped_column("narration", Unicode(1000), nullable=True) - reason: Mapped[str] = mapped_column("reason", Unicode(255), nullable=True) - voucher_type: Mapped[VoucherType] = mapped_column("voucher_type", Enum(VoucherType), nullable=False) - user_id: Mapped[uuid.UUID] = mapped_column("user_id", UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) + customer_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, ForeignKey("customers.id"), nullable=True) + narration: Mapped[str] = mapped_column(Text, nullable=True) + reason: Mapped[str] = mapped_column(Text, nullable=True) + voucher_type: Mapped[VoucherType] = mapped_column(Enum(VoucherType), nullable=False) + user_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("users.id"), nullable=False) user: Mapped["User"] = relationship(backref="vouchers") food_table: Mapped["FoodTable"] = relationship(backref="vouchers") @@ -69,7 +63,7 @@ class Voucher: back_populates="voucher", cascade="delete, delete-orphan", ) - status: Mapped[Optional["Overview"]] = relationship(back_populates="voucher", uselist=False) + status: Mapped["Overview" | None] = relationship(back_populates="voucher", uselist=False) def __init__( self, diff --git a/barker/barker/routers/reports/product_sale_report.py b/barker/barker/routers/reports/product_sale_report.py index dd6c1ae2..60db0116 100644 --- a/barker/barker/routers/reports/product_sale_report.py +++ b/barker/barker/routers/reports/product_sale_report.py @@ -88,8 +88,8 @@ def product_sale_report(s: date, f: date, db: Session): .order_by(SaleCategory.name, MenuCategory.name, ProductVersion.full_name) ).all() info: list[Any] = [] - for id_, name, type_, hh, quantity in list_: - type_ = to_camel(VoucherType(type_).name) + for id_, name, v_type, hh, quantity in list_: + type_ = to_camel(VoucherType(v_type).name) old = [i for i in info if i["id"] == id_ and i["isHappyHour"] == hh] if len(old): if type_ not in old[0]: diff --git a/barker/barker/schemas/__init__.py b/barker/barker/schemas/__init__.py index 1b7e4a22..7065768f 100644 --- a/barker/barker/schemas/__init__.py +++ b/barker/barker/schemas/__init__.py @@ -1,3 +1,13 @@ +from decimal import Decimal +from typing import Annotated + +from pydantic import PlainSerializer + + def to_camel(string: str) -> str: first, *others = string.split("_") return "".join([first.lower()] + [word.capitalize() for word in others]) + + +# Custom serializer to serialize decimal as float and not as string as is the default behaviour in Pydantic V2 +Daf = Annotated[Decimal, PlainSerializer(lambda x: float(x), return_type=float, when_used="unless-none")] diff --git a/barker/barker/schemas/bill_settlement_report.py b/barker/barker/schemas/bill_settlement_report.py index e2b9fb7f..d4462c20 100644 --- a/barker/barker/schemas/bill_settlement_report.py +++ b/barker/barker/schemas/bill_settlement_report.py @@ -1,16 +1,15 @@ from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel class BillSettlementItem(BaseModel): date_: datetime bill_id: str settlement: str - amount: Decimal + amount: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @field_validator("date_", mode="before") diff --git a/barker/barker/schemas/cashier_report.py b/barker/barker/schemas/cashier_report.py index 61efe369..2c9f7067 100644 --- a/barker/barker/schemas/cashier_report.py +++ b/barker/barker/schemas/cashier_report.py @@ -1,15 +1,14 @@ from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel from .user import UserLink class NameAmount(BaseModel): name: str - amount: Decimal + amount: Daf model_config = ConfigDict(str_strip_whitespace=True) @@ -29,7 +28,7 @@ class InfoItem(BaseModel): date: datetime bill_id: str customer: str - amount: Decimal + amount: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @field_validator("date", mode="before") diff --git a/barker/barker/schemas/customer.py b/barker/barker/schemas/customer.py index 40e113af..c923150d 100644 --- a/barker/barker/schemas/customer.py +++ b/barker/barker/schemas/customer.py @@ -1,17 +1,15 @@ import uuid -from decimal import Decimal - from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel class CustomerDiscount(BaseModel): id_: uuid.UUID name: str - discount: Decimal = Field(ge=0, default=0, le=1) - limit: Decimal = Field(ge=0, default=0, le=1) + discount: Daf = Field(ge=0, default=0, le=1) + limit: Daf = Field(ge=0, default=0, le=1) model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/discount_item.py b/barker/barker/schemas/discount_item.py index 56739e05..9312bac0 100644 --- a/barker/barker/schemas/discount_item.py +++ b/barker/barker/schemas/discount_item.py @@ -1,15 +1,15 @@ import uuid -from decimal import Decimal - from barker.schemas import to_camel from pydantic import BaseModel, ConfigDict, Field +from . import Daf + class DiscountItem(BaseModel): id_: uuid.UUID name: str - discount: Decimal | None = Field(ge=0, default=0, le=1) - limit: Decimal - customer: Decimal + discount: Daf | None = Field(ge=0, default=0, le=1) + limit: Daf + customer: Daf model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/discount_report.py b/barker/barker/schemas/discount_report.py index 73549313..2be8e089 100644 --- a/barker/barker/schemas/discount_report.py +++ b/barker/barker/schemas/discount_report.py @@ -1,14 +1,13 @@ from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel class DiscountReportItem(BaseModel): name: str - amount: Decimal + amount: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/menu_engineering_report.py b/barker/barker/schemas/menu_engineering_report.py index d18c4ff3..69e75fcb 100644 --- a/barker/barker/schemas/menu_engineering_report.py +++ b/barker/barker/schemas/menu_engineering_report.py @@ -1,24 +1,23 @@ import uuid from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel class MeItem(BaseModel): id_: uuid.UUID name: str - price: Decimal - average: Decimal + price: Daf + average: Daf sale_category: str menu_category: str - quantity: Decimal - sales: Decimal - quantity_percent: Decimal - sales_percent: Decimal + quantity: Daf + sales: Daf + quantity_percent: Daf + sales_percent: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/modifier.py b/barker/barker/schemas/modifier.py index dfd476fd..a9e5cb68 100644 --- a/barker/barker/schemas/modifier.py +++ b/barker/barker/schemas/modifier.py @@ -1,17 +1,15 @@ import uuid -from decimal import Decimal - from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel from .modifier_category import ModifierCategoryLink class ModifierIn(BaseModel): name: str = Field(..., min_length=1) show_in_bill: bool - price: Decimal = Field(ge=0, default=0) + price: Daf = Field(ge=0, default=0) is_active: bool modifier_category: ModifierCategoryLink model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @@ -30,6 +28,6 @@ class ModifierLink(BaseModel): class ModifierBlank(BaseModel): name: str show_in_bill: bool - price: Decimal + price: Daf is_active: bool model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/product.py b/barker/barker/schemas/product.py index 69dffd33..2f08c8ec 100644 --- a/barker/barker/schemas/product.py +++ b/barker/barker/schemas/product.py @@ -1,11 +1,10 @@ import uuid from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel from .menu_category import MenuCategoryLink from .sale_category import SaleCategoryLink @@ -15,10 +14,10 @@ class ProductIn(BaseModel): units: str menu_category: MenuCategoryLink = Field(...) sale_category: SaleCategoryLink = Field(...) - price: Decimal # = Field(ge=0, default=0) + price: Daf # = Field(ge=0, default=0) has_happy_hour: bool is_not_available: bool - quantity: Decimal = Field(ge=0, default=0) + quantity: Daf = Field(ge=0, default=0) is_active: bool sort_order: int model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @@ -61,10 +60,10 @@ class Product(ProductIn): class ProductBlank(BaseModel): name: str units: str - price: Decimal + price: Daf has_happy_hour: bool is_not_available: bool - quantity: Decimal + quantity: Daf is_active: bool sort_order: int model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/receive_payment.py b/barker/barker/schemas/receive_payment.py index 4ea08379..3b6ee97f 100644 --- a/barker/barker/schemas/receive_payment.py +++ b/barker/barker/schemas/receive_payment.py @@ -1,13 +1,11 @@ -from decimal import Decimal - from pydantic import BaseModel, ConfigDict -from . import to_camel +from . import Daf, to_camel class ReceivePaymentItem(BaseModel): id_: int - amount: Decimal + amount: Daf model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/sale_category.py b/barker/barker/schemas/sale_category.py index 0bbd777c..4857aa12 100644 --- a/barker/barker/schemas/sale_category.py +++ b/barker/barker/schemas/sale_category.py @@ -1,16 +1,14 @@ import uuid -from decimal import Decimal - from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel from .tax import TaxLink class SaleCategoryIn(BaseModel): name: str = Field(..., min_length=1) - discount_limit: Decimal = Field(ge=0, default=0, le=1) + discount_limit: Daf = Field(ge=0, default=0, le=1) tax: TaxLink = Field(...) model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @@ -22,15 +20,15 @@ class SaleCategory(SaleCategoryIn): class SaleCategoryBlank(BaseModel): name: str - discount_limit: Decimal + discount_limit: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) class SaleCategoryForDiscount(BaseModel): id_: uuid.UUID name: str - discount_limit: Decimal - discount: Decimal + discount_limit: Daf + discount: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/sale_report.py b/barker/barker/schemas/sale_report.py index 161d50d1..b71314bf 100644 --- a/barker/barker/schemas/sale_report.py +++ b/barker/barker/schemas/sale_report.py @@ -1,15 +1,14 @@ from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel from .user import UserLink class SaleReportItem(BaseModel): name: str - amount: Decimal + amount: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/tax.py b/barker/barker/schemas/tax.py index 6ca206aa..8bf5b0e4 100644 --- a/barker/barker/schemas/tax.py +++ b/barker/barker/schemas/tax.py @@ -1,16 +1,14 @@ import uuid -from decimal import Decimal - from barker.schemas.regime import RegimeLink from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel class TaxIn(BaseModel): name: str = Field(..., min_length=1) - rate: Decimal = Field(ge=0, default=0) + rate: Daf = Field(ge=0, default=0) regime: RegimeLink = Field(...) is_fixture: bool model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @@ -23,7 +21,7 @@ class Tax(TaxIn): class TaxBlank(BaseModel): name: str - rate: Decimal = Field(ge=0, default=0) + rate: Daf = Field(ge=0, default=0) is_fixture: bool model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @@ -31,5 +29,5 @@ class TaxBlank(BaseModel): class TaxLink(BaseModel): id_: uuid.UUID = Field(...) name: str | None = None - rate: Decimal | None = None + rate: Daf | None = None model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/tax_report.py b/barker/barker/schemas/tax_report.py index d2e6afb3..65a91719 100644 --- a/barker/barker/schemas/tax_report.py +++ b/barker/barker/schemas/tax_report.py @@ -1,16 +1,15 @@ from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel class TaxReportItem(BaseModel): name: str - tax_rate: Decimal - sale_amount: Decimal - amount: Decimal + tax_rate: Daf + sale_amount: Daf + amount: Daf model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/update_product_prices.py b/barker/barker/schemas/update_product_prices.py index ac695f8d..93a1f64f 100644 --- a/barker/barker/schemas/update_product_prices.py +++ b/barker/barker/schemas/update_product_prices.py @@ -1,18 +1,17 @@ import uuid from datetime import date, datetime -from decimal import Decimal from pydantic import BaseModel, ConfigDict, field_serializer, field_validator -from . import to_camel +from . import Daf, to_camel class UpdateProductPricesItem(BaseModel): id: uuid.UUID name: str - old_price: Decimal - new_price: Decimal + old_price: Daf + new_price: Daf model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/voucher.py b/barker/barker/schemas/voucher.py index 6ef4cf3b..cb2dbffb 100644 --- a/barker/barker/schemas/voucher.py +++ b/barker/barker/schemas/voucher.py @@ -4,7 +4,7 @@ from decimal import Decimal from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator -from . import to_camel +from . import Daf, to_camel from .customer import CustomerLink from .modifier import ModifierLink from .product_link import ProductLink @@ -15,40 +15,40 @@ from .tax import TaxLink class Inventory(BaseModel): id_: uuid.UUID | None = None product: ProductLink - quantity: Decimal - price: Decimal | None = None + quantity: Daf + price: Daf | None = None tax: TaxLink | None = None - tax_rate: Decimal | None = None - discount: Decimal = Field(ge=0, le=1) + tax_rate: Daf | None = None + discount: Daf = Field(ge=0, le=1) is_happy_hour: bool modifiers: list[ModifierLink] - amount: Decimal | None = None + amount: Daf | None = None model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) @field_validator("quantity") @classmethod - def _quantity(cls, value: Decimal | None) -> Decimal: + def _quantity(cls, value: Daf | None) -> Daf: if value is None: return Decimal(0) return round(value, 2) @field_validator("price") @classmethod - def _price(cls, value: Decimal | None) -> Decimal: + def _price(cls, value: Daf | None) -> Daf: if value is None: return Decimal(0) return round(value, 2) @field_validator("tax_rate") @classmethod - def _tax_rate(cls, value: Decimal | None) -> Decimal: + def _tax_rate(cls, value: Daf | None) -> Daf: if value is None: return Decimal(0) return round(value, 5) @field_validator("discount") @classmethod - def _discount(cls, value: Decimal | None) -> Decimal: + def _discount(cls, value: Daf | None) -> Daf: if value is None: return Decimal(0) return round(value, 5) diff --git a/barker/pyproject.toml b/barker/pyproject.toml index e82c3200..bd8d7bf7 100644 --- a/barker/pyproject.toml +++ b/barker/pyproject.toml @@ -7,7 +7,7 @@ authors = ["tanshu "] [tool.poetry.dependencies] python = "^3.11" uvicorn = {extras = ["standard"], version = "^0.21.1"} -fastapi = {extras = ["all"], version = "^0.100.0"} +fastapi = {extras = ["all"], version = "^0.101.1"} python-jose = {extras = ["cryptography"], version = "^3.3.0"} passlib = {extras = ["bcrypt"], version = "^1.7.4"} psycopg2-binary = "^2.9.6" @@ -17,7 +17,7 @@ PyJWT = "^2.8.0" alembic = "^1.11.1" itsdangerous = "^2.1.2" python-dotenv = "^1.0.0" -pydantic = {extras = ["dotenv"], version = "^2.0.3"} +pydantic = {extras = ["dotenv"], version = "^2.1.1"} starlette = "^0.27.0" arq = "^0.25.0" aiohttp = "^3.8.5"