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
|
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()
|
device: Device = db.execute(select(Device).where(Device.id == device_id)).scalars().one_or_none()
|
||||||
if device is None:
|
if device is None:
|
||||||
device = Device.create(db)
|
device = Device.create(db)
|
||||||
|
@ -2,7 +2,7 @@ import asyncio
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import List
|
from typing import Any, Dict, List, Tuple
|
||||||
|
|
||||||
from arq import ArqRedis, create_pool
|
from arq import ArqRedis, create_pool
|
||||||
from barker.core.config import settings
|
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):
|
def print_kot(voucher_id: uuid.UUID, db: Session):
|
||||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == voucher_id)).scalar_one()
|
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]
|
kot: Kot = voucher.kots[-1]
|
||||||
product_date = (
|
product_date = (
|
||||||
voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
|
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):
|
def add_products(modifier_category: ModifierCategory, menu_categories: List[schemas.MenuCategoryLink], db: Session):
|
||||||
for mc in menu_categories:
|
for mc in menu_categories:
|
||||||
for p in mc.products:
|
for p in mc.products:
|
||||||
old = [x for x in modifier_category.products if x.id == p.id_]
|
old = next([x for x in modifier_category.products if x.id == p.id_], None)
|
||||||
old = None if len(old) == 0 else old[0]
|
|
||||||
if p.enabled and old is None:
|
if p.enabled and old is None:
|
||||||
product_object = db.execute(select(Product).where(Product.id == p.id_)).scalar_one()
|
product_object = db.execute(select(Product).where(Product.id == p.id_)).scalar_one()
|
||||||
modifier_category.products.append(product_object)
|
modifier_category.products.append(product_object)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from typing import List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
import barker.schemas.product as schemas
|
import barker.schemas.product as schemas
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ def sort_order(
|
|||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
indexes = {}
|
indexes: Dict[uuid.UUID, int] = {}
|
||||||
for item in data:
|
for item in data:
|
||||||
if item.menu_category.id_ in indexes:
|
if item.menu_category.id_ in indexes:
|
||||||
indexes[item.menu_category.id_] += 1
|
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):
|
def add_permissions(role: Role, permissions: List[schemas.PermissionItem], db: Session):
|
||||||
for permission in permissions:
|
for permission in permissions:
|
||||||
gp = [p for p in role.permissions if p.id == permission.id_]
|
gp = next([p for p in role.permissions if p.id == permission.id_], None)
|
||||||
gp = None if len(gp) == 0 else gp[0]
|
|
||||||
if permission.enabled and gp is None:
|
if permission.enabled and gp is None:
|
||||||
role.permissions.append(db.execute(select(Permission).where(Permission.id == permission.id_)).scalar_one())
|
role.permissions.append(db.execute(select(Permission).where(Permission.id == permission.id_)).scalar_one())
|
||||||
elif not permission.enabled and gp:
|
elif not permission.enabled and gp:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from typing import List
|
from typing import Dict, List
|
||||||
|
|
||||||
import barker.schemas.product as schemas
|
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]]:
|
def product_list(db: Session) -> List[List[schemas.Product]]:
|
||||||
dict_ = {}
|
dict_: Dict[uuid.UUID, List[schemas.Product]] = {}
|
||||||
list_ = (
|
list_ = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(ProductVersion)
|
select(ProductVersion)
|
||||||
|
@ -95,8 +95,7 @@ def update_route(
|
|||||||
|
|
||||||
def add_roles(user: User, roles: List[schemas.RoleItem], db: Session):
|
def add_roles(user: User, roles: List[schemas.RoleItem], db: Session):
|
||||||
for role in roles:
|
for role in roles:
|
||||||
ug = [g for g in user.roles if g.id == role.id_]
|
ug = next([g for g in user.roles if g.id == role.id_], None)
|
||||||
ug = None if len(ug) == 0 else ug[0]
|
|
||||||
if role.enabled and ug is None:
|
if role.enabled and ug is None:
|
||||||
user.roles.append(db.execute(select(Role).where(Role.id == role.id_)).scalar_one())
|
user.roles.append(db.execute(select(Role).where(Role.id == role.id_)).scalar_one())
|
||||||
elif not role.enabled and ug:
|
elif not role.enabled and ug:
|
||||||
|
@ -3,7 +3,7 @@ import uuid
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import List, Optional
|
from typing import Dict, List, Optional, Tuple
|
||||||
|
|
||||||
import barker.schemas.split as schemas
|
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:
|
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:
|
for i in inventories:
|
||||||
key = (i.product_id, i.is_happy_hour)
|
key = (i.product_id, i.is_happy_hour)
|
||||||
quantities[key] += i.quantity
|
quantities[key] += i.quantity
|
||||||
for i in quantities.values():
|
for j in quantities.values():
|
||||||
if i < 0:
|
if j < 0:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user