diff --git a/barker/barker/printing/kot.py b/barker/barker/printing/kot.py index b0fe55d..66522c8 100644 --- a/barker/barker/printing/kot.py +++ b/barker/barker/printing/kot.py @@ -99,7 +99,7 @@ def print_kot(voucher_id: uuid.UUID, db: Session): ) ) .order_by(SectionPrinter.menu_category_id) - ).one() + ).first() key = (printer.id, copies) if key not in my_hash: my_hash[key] = (printer, []) diff --git a/barker/barker/routers/section_printer.py b/barker/barker/routers/section_printer.py index 16dbc91..295934d 100644 --- a/barker/barker/routers/section_printer.py +++ b/barker/barker/routers/section_printer.py @@ -29,18 +29,16 @@ def save( try: with SessionFuture() as db: current = [] - default_copies = 0 + default_id = uuid.uuid4() for mcs in data: if mcs.menu_category is None and mcs.printer is None: raise ValueError("Please choose a default printer") if mcs.printer is None: continue - if mcs.menu_category is None: - default_copies = mcs.copies stmt = ( pg_insert(SectionPrinter) .values( - id=uuid.uuid4(), + id=default_id if mcs.menu_category is None else uuid.uuid4(), menu_category_id=mcs.menu_category.id_ if mcs.menu_category is not None else None, section_id=id_, printer_id=mcs.printer.id_, @@ -59,7 +57,7 @@ def save( and_( SectionPrinter.section_id == id_, SectionPrinter.menu_category_id == None, # noqa: E711 - SectionPrinter.copies != default_copies, + SectionPrinter.id != default_id, ), and_( SectionPrinter.section_id == id_, @@ -121,15 +119,19 @@ def report(section_id: Optional[uuid.UUID], db: Session) -> List[schemas.Section ).all() list_ = [] for mc_id, mc_name in [(None, None)] + menu_categories: - section_printer = db.execute( - select(SectionPrinter).where( - SectionPrinter.section_id == section_id, - SectionPrinter.menu_category_id == mc_id, + section_printer = ( + db.execute( + select(SectionPrinter).where( + SectionPrinter.section_id == section_id, + SectionPrinter.menu_category_id == mc_id, + ) ) - ).scalar_one() + .scalars() + .one_or_none() + ) list_.append( schemas.SectionPrinter( - menuCategory=None if mc_id is None else schemas.MenuCategoryLink(id=mc_id, name=mc_name), + menuCategory=None if mc_id is None else schemas.MenuCategoryLink(id=mc_id, name=mc_name, products=[]), printer=None if section_printer is None else schemas.PrinterLink(id=section_printer.printer_id), copies=0 if section_printer is None else section_printer.copies, )