Chore: some mypy fixes
This commit is contained in:
parent
7a2ccb7fb1
commit
09a8fdfecc
@ -65,7 +65,7 @@ def authenticate_user(username: str, password: str, db: Session) -> Optional[Use
|
||||
return user
|
||||
|
||||
|
||||
def device_allowed(user: UserModel, device_id: Optional[uuid.UUID], db: Session = None) -> Tuple[bool, Device]:
|
||||
def device_allowed(user: UserModel, device_id: Optional[uuid.UUID], db: Session) -> Tuple[bool, Device]:
|
||||
device: Device = db.execute(select(Device).where(Device.id == device_id)).scalars().one_or_none()
|
||||
if device is None:
|
||||
device = Device.create(db)
|
||||
|
@ -2,7 +2,7 @@ import asyncio
|
||||
import uuid
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import List
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from arq import ArqRedis, create_pool
|
||||
from barker.core.config import settings
|
||||
@ -66,7 +66,7 @@ def design_kot(voucher: Voucher, kot: Kot, items: List[Inventory], copy_number:
|
||||
|
||||
def print_kot(voucher_id: uuid.UUID, db: Session):
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == voucher_id)).scalar_one()
|
||||
my_hash = {}
|
||||
my_hash: Dict[Tuple[uuid.UUID, int], Tuple[Printer, List[Any]]] = {}
|
||||
kot: Kot = voucher.kots[-1]
|
||||
product_date = (
|
||||
voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
|
||||
|
@ -299,8 +299,7 @@ def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategor
|
||||
def add_products(modifier_category: ModifierCategory, menu_categories: List[schemas.MenuCategoryLink], db: Session):
|
||||
for mc in menu_categories:
|
||||
for p in mc.products:
|
||||
old = [x for x in modifier_category.products if x.id == p.id_]
|
||||
old = None if len(old) == 0 else old[0]
|
||||
old = next([x for x in modifier_category.products if x.id == p.id_], None)
|
||||
if p.enabled and old is None:
|
||||
product_object = db.execute(select(Product).where(Product.id == p.id_)).scalar_one()
|
||||
modifier_category.products.append(product_object)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, timedelta
|
||||
from typing import List, Optional
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import barker.schemas.product as schemas
|
||||
|
||||
@ -38,7 +38,7 @@ def sort_order(
|
||||
):
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
indexes = {}
|
||||
indexes: Dict[uuid.UUID, int] = {}
|
||||
for item in data:
|
||||
if item.menu_category.id_ in indexes:
|
||||
indexes[item.menu_category.id_] += 1
|
||||
|
@ -143,8 +143,7 @@ def role_blank(db: Session) -> schemas.RoleBlank:
|
||||
|
||||
def add_permissions(role: Role, permissions: List[schemas.PermissionItem], db: Session):
|
||||
for permission in permissions:
|
||||
gp = [p for p in role.permissions if p.id == permission.id_]
|
||||
gp = None if len(gp) == 0 else gp[0]
|
||||
gp = next([p for p in role.permissions if p.id == permission.id_], None)
|
||||
if permission.enabled and gp is None:
|
||||
role.permissions.append(db.execute(select(Permission).where(Permission.id == permission.id_)).scalar_one())
|
||||
elif not permission.enabled and gp:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
|
||||
from datetime import date, timedelta
|
||||
from typing import List
|
||||
from typing import Dict, List
|
||||
|
||||
import barker.schemas.product as schemas
|
||||
|
||||
@ -183,7 +183,7 @@ def show_list(user: UserToken = Security(get_user, scopes=["temporal-products"])
|
||||
|
||||
|
||||
def product_list(db: Session) -> List[List[schemas.Product]]:
|
||||
dict_ = {}
|
||||
dict_: Dict[uuid.UUID, List[schemas.Product]] = {}
|
||||
list_ = (
|
||||
db.execute(
|
||||
select(ProductVersion)
|
||||
|
@ -95,8 +95,7 @@ def update_route(
|
||||
|
||||
def add_roles(user: User, roles: List[schemas.RoleItem], db: Session):
|
||||
for role in roles:
|
||||
ug = [g for g in user.roles if g.id == role.id_]
|
||||
ug = None if len(ug) == 0 else ug[0]
|
||||
ug = next([g for g in user.roles if g.id == role.id_], None)
|
||||
if role.enabled and ug is None:
|
||||
user.roles.append(db.execute(select(Role).where(Role.id == role.id_)).scalar_one())
|
||||
elif not role.enabled and ug:
|
||||
|
@ -3,7 +3,7 @@ import uuid
|
||||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from typing import List, Optional
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
import barker.schemas.split as schemas
|
||||
|
||||
@ -171,12 +171,12 @@ def happy_hour_items_balanced(inventories: List[Inventory]) -> bool:
|
||||
|
||||
|
||||
def are_product_quantities_positive(inventories: List[Inventory]) -> bool:
|
||||
quantities = defaultdict(Decimal)
|
||||
quantities: Dict[Tuple[uuid.UUID, bool], Decimal] = defaultdict(Decimal)
|
||||
for i in inventories:
|
||||
key = (i.product_id, i.is_happy_hour)
|
||||
quantities[key] += i.quantity
|
||||
for i in quantities.values():
|
||||
if i < 0:
|
||||
for j in quantities.values():
|
||||
if j < 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user