diff --git a/barker/barker/printing/bill.py b/barker/barker/printing/bill.py index 6555eeb..fa06f5d 100644 --- a/barker/barker/printing/bill.py +++ b/barker/barker/printing/bill.py @@ -40,13 +40,15 @@ def print_bill(voucher_id: uuid.UUID, db: Session): key = ( i.product_id, i.is_happy_hour, - tuple(m.modifier_id for m in i.modifiers if m.modifier.show_in_bill), + frozenset(m.modifier_id for m in i.modifiers if m.modifier.show_in_bill), ) if key in items_dict: items_dict[key].quantity += i.quantity + i.quantity = 0 else: items_dict[key] = i + for i in [it for it in items_dict.values() if it.quantity != 0]: get_tax_item(i.tax.id, i.tax.name, i.tax_amount, tax) data = design_bill(voucher, items_dict.values(), tax.values(), db) redis: ArqRedis = asyncio.run(create_pool(redis_settings)) diff --git a/barker/barker/routers/role.py b/barker/barker/routers/role.py index 7929eeb..1eeb252 100644 --- a/barker/barker/routers/role.py +++ b/barker/barker/routers/role.py @@ -69,12 +69,12 @@ def delete_route( with SessionFuture() as db: if db.execute(select(count(user_roles.c.id)).where(user_roles.c.role_id == id_)).scalar_one() > 0: raise HTTPException( - status_code=status.HTTP_501_NOT_IMPLEMENTED, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="This Role has been assigned to users and cannot be deleted.", ) if db.execute(select(count(role_permissions.c.id)).where(role_permissions.c.role_id == id_)).scalar_one() > 0: raise HTTPException( - status_code=status.HTTP_501_NOT_IMPLEMENTED, + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="This Role has permissions and cannot be deleted.", ) item: Role = db.execute(select(Role).where(Role.id == id_)).scalar_one() diff --git a/barker/barker/routers/voucher/save.py b/barker/barker/routers/voucher/save.py index 34caa24..6038669 100644 --- a/barker/barker/routers/voucher/save.py +++ b/barker/barker/routers/voucher/save.py @@ -55,9 +55,11 @@ def save( if update_table: do_update_table(item, guest_book, db) db.commit() - print_kot(item.id, db) + voucher_id = item.id + with SessionFuture() as db: + print_kot(voucher_id, db) if item.voucher_type != VoucherType.KOT: - print_bill(item.id, db) + print_bill(voucher_id, db) except SQLAlchemyError as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, diff --git a/barker/barker/routers/voucher/update.py b/barker/barker/routers/voucher/update.py index bfc79e5..8e15ea7 100644 --- a/barker/barker/routers/voucher/update.py +++ b/barker/barker/routers/voucher/update.py @@ -169,10 +169,12 @@ def update_route( if update_table: do_update_table(item, guest_book, db) db.commit() + voucher_id = item.id + with SessionFuture() as db: if need_to_print_kot: - print_kot(item.id, db) + print_kot(voucher_id, db) if item.voucher_type != VoucherType.KOT: - print_bill(item.id, db) + print_bill(voucher_id, db) except SQLAlchemyError as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,