From 43a884144b5bc1e3e9bc6dd3428be2b8ba63c0bf Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Tue, 17 Dec 2024 09:47:25 +0530 Subject: [PATCH] Fix: Issues flagged by mypy --- barker/barker/routers/guest_book.py | 3 +-- barker/barker/routers/modifier_category.py | 2 -- barker/barker/schemas/customer.py | 6 ++++-- barker/barker/schemas/discount_item.py | 5 ++++- barker/barker/schemas/modifier.py | 4 +++- barker/barker/schemas/product.py | 3 ++- barker/barker/schemas/sale_category.py | 4 +++- barker/barker/schemas/tax.py | 6 ++++-- 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/barker/barker/routers/guest_book.py b/barker/barker/routers/guest_book.py index 84b8c32..2ec893b 100644 --- a/barker/barker/routers/guest_book.py +++ b/barker/barker/routers/guest_book.py @@ -104,13 +104,12 @@ def update_route( def delete_route( id_: uuid.UUID, user: UserToken = Security(get_user, scopes=["customers"]), -) -> schemas.GuestBookIn: +) -> None: try: with SessionFuture() as db: item: GuestBook = db.execute(select(GuestBook).where(GuestBook.id == id_)).scalar_one() db.delete(item) db.commit() - return blank_guest_book_info() except SQLAlchemyError as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, diff --git a/barker/barker/routers/modifier_category.py b/barker/barker/routers/modifier_category.py index af93ac0..739f676 100644 --- a/barker/barker/routers/modifier_category.py +++ b/barker/barker/routers/modifier_category.py @@ -233,7 +233,6 @@ def modifier_category_info(item: ModifierCategory, date_: date, db: Session) -> schemas.MenuCategoryLink( id_=mc.id, name=mc.name, - enabled=False, products=[ ProductLinkSchema( id_=p.product_id, @@ -284,7 +283,6 @@ def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategor schemas.MenuCategoryLink( id_=mc.id, name=mc.name, - enabled=False, products=[ProductLinkSchema(id_=p.product_id, name=p.name, enabled=False) for p in mc.products], ) for mc in menu_categories diff --git a/barker/barker/schemas/customer.py b/barker/barker/schemas/customer.py index c923150..82d51e2 100644 --- a/barker/barker/schemas/customer.py +++ b/barker/barker/schemas/customer.py @@ -1,5 +1,7 @@ import uuid +from decimal import Decimal + from pydantic import BaseModel, ConfigDict, Field from . import Daf, to_camel @@ -8,8 +10,8 @@ from . import Daf, to_camel class CustomerDiscount(BaseModel): id_: uuid.UUID name: str - discount: Daf = Field(ge=0, default=0, le=1) - limit: Daf = Field(ge=0, default=0, le=1) + discount: Daf = Field(ge=Decimal(0), default=Decimal(0), le=Decimal(1)) + limit: Daf = Field(ge=Decimal(0), default=Decimal(0), le=Decimal(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 b681c91..8aebb6b 100644 --- a/barker/barker/schemas/discount_item.py +++ b/barker/barker/schemas/discount_item.py @@ -1,5 +1,8 @@ import uuid +from decimal import Decimal +from typing import Annotated + from pydantic import BaseModel, ConfigDict, Field from . import Daf, to_camel @@ -8,7 +11,7 @@ from . import Daf, to_camel class DiscountItem(BaseModel): id_: uuid.UUID name: str - discount: Daf | None = Field(ge=0, default=0, le=1) + discount: Annotated[Daf | None, Field(ge=Decimal(0), default=Decimal(0), le=Decimal(1))] limit: Daf customer: Daf model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) diff --git a/barker/barker/schemas/modifier.py b/barker/barker/schemas/modifier.py index a9e5cb6..341df23 100644 --- a/barker/barker/schemas/modifier.py +++ b/barker/barker/schemas/modifier.py @@ -1,5 +1,7 @@ import uuid +from decimal import Decimal + from pydantic import BaseModel, ConfigDict, Field from . import Daf, to_camel @@ -9,7 +11,7 @@ from .modifier_category import ModifierCategoryLink class ModifierIn(BaseModel): name: str = Field(..., min_length=1) show_in_bill: bool - price: Daf = Field(ge=0, default=0) + price: Daf = Field(ge=Decimal(0), default=Decimal(0)) is_active: bool modifier_category: ModifierCategoryLink 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 2f08c8e..96b5d1e 100644 --- a/barker/barker/schemas/product.py +++ b/barker/barker/schemas/product.py @@ -1,6 +1,7 @@ import uuid from datetime import date, datetime +from decimal import Decimal from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator @@ -17,7 +18,7 @@ class ProductIn(BaseModel): price: Daf # = Field(ge=0, default=0) has_happy_hour: bool is_not_available: bool - quantity: Daf = Field(ge=0, default=0) + quantity: Daf = Field(ge=Decimal(0), default=Decimal(0)) 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/sale_category.py b/barker/barker/schemas/sale_category.py index 4857aa1..cdafafb 100644 --- a/barker/barker/schemas/sale_category.py +++ b/barker/barker/schemas/sale_category.py @@ -1,5 +1,7 @@ import uuid +from decimal import Decimal + from pydantic import BaseModel, ConfigDict, Field from . import Daf, to_camel @@ -8,7 +10,7 @@ from .tax import TaxLink class SaleCategoryIn(BaseModel): name: str = Field(..., min_length=1) - discount_limit: Daf = Field(ge=0, default=0, le=1) + discount_limit: Daf = Field(ge=Decimal(0), default=Decimal(0), le=Decimal(1)) tax: TaxLink = Field(...) 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 f407f89..7cea67a 100644 --- a/barker/barker/schemas/tax.py +++ b/barker/barker/schemas/tax.py @@ -1,5 +1,7 @@ import uuid +from decimal import Decimal + from pydantic import BaseModel, ConfigDict, Field from . import Daf, to_camel @@ -8,7 +10,7 @@ from .regime import RegimeLink class TaxIn(BaseModel): name: str = Field(..., min_length=1) - rate: Daf = Field(ge=0, default=0) + rate: Daf = Field(ge=Decimal(0), default=Decimal(0)) regime: RegimeLink = Field(...) is_fixture: bool model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True) @@ -21,7 +23,7 @@ class Tax(TaxIn): class TaxBlank(BaseModel): name: str - rate: Daf = Field(ge=0, default=0) + rate: Daf = Field(ge=Decimal(0), default=Decimal(0)) is_fixture: bool model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)