From 8c5d9418509d9cb740afb201bd926a54a448c652 Mon Sep 17 00:00:00 2001 From: tanshu Date: Sun, 4 Jul 2021 08:32:55 +0530 Subject: [PATCH] Fix: Kots with product quantity = 0 were allowed. So blank kots could be added. --- barker/barker/routers/voucher/update.py | 6 +++++- bookie/src/app/sales/bill.service.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/barker/barker/routers/voucher/update.py b/barker/barker/routers/voucher/update.py index 492c9cf..9fc9b99 100644 --- a/barker/barker/routers/voucher/update.py +++ b/barker/barker/routers/voucher/update.py @@ -103,7 +103,11 @@ def update_route( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Happy hour products are not balanced.", ) - for k in (k for k in data.kots if k.id_ is None and len(k.inventories) > 0): + for k in ( + k + for k in data.kots + if k.id_ is None and len([i for i in k.inventories if round(i.quantity, 2) != 0]) > 0 + ): need_to_print_kot = True code = db.execute(select(func.coalesce(func.max(Kot.code), 0) + 1)).scalar_one() kot = Kot(item.id, code, item.food_table_id, now, item.user_id) diff --git a/bookie/src/app/sales/bill.service.ts b/bookie/src/app/sales/bill.service.ts index 893dadd..dd69ee6 100644 --- a/bookie/src/app/sales/bill.service.ts +++ b/bookie/src/app/sales/bill.service.ts @@ -237,7 +237,7 @@ export class BillService { printKot(guestBookId: string | null): Observable { const item = JSON.parse(JSON.stringify(this.bill)); const newKot = this.bill.kots.find((k) => k.id === undefined) as Kot; - if (newKot.inventories.length === 0) { + if (newKot.inventories.filter((x) => x.quantity !== 0).length === 0) { return throwError('Cannot print a blank KOT\nPlease add some products!'); } if (!this.happyHourItemsBalanced() || this.happyHourItemsMoreThanRegular()) {