Chore: Refactor nil inventories and kots checking

This commit is contained in:
Amritanshu Agrawal 2023-03-24 08:49:19 +05:30
parent 88bda14002
commit 1b4c26733d

View File

@ -92,9 +92,12 @@ def do_save(
user.id_,
)
db.add(item)
for dk in data.kots:
# Filter out nil inventories
dk.inventories = [dki for dki in dk.inventories if round(dki.quantity, 2) != 0]
# Filter out nil kots
data.kots = [k for k in data.kots if len(k.inventories) > 0]
for k in data.kots:
if not len(k.inventories):
continue
if not happy_hour_items_balanced(k.inventories):
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,