From 1b4c26733d5af6d8da9400efc5e6a44222f65efa Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Fri, 24 Mar 2023 08:49:19 +0530 Subject: [PATCH] Chore: Refactor nil inventories and kots checking --- barker/barker/routers/voucher/save.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/barker/barker/routers/voucher/save.py b/barker/barker/routers/voucher/save.py index bb864f7..88de77b 100644 --- a/barker/barker/routers/voucher/save.py +++ b/barker/barker/routers/voucher/save.py @@ -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,