Fix: Section Printer update would keep adding multiple default rows.
Fix: Kot select printer would have 1-2 rows, one with the null menu category and another (maybe) with the correct menu category.
This commit is contained in:
parent
862892d7a1
commit
438e99b6b0
@ -99,7 +99,7 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by(SectionPrinter.menu_category_id)
|
.order_by(SectionPrinter.menu_category_id)
|
||||||
).one()
|
).first()
|
||||||
key = (printer.id, copies)
|
key = (printer.id, copies)
|
||||||
if key not in my_hash:
|
if key not in my_hash:
|
||||||
my_hash[key] = (printer, [])
|
my_hash[key] = (printer, [])
|
||||||
|
@ -29,18 +29,16 @@ def save(
|
|||||||
try:
|
try:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
current = []
|
current = []
|
||||||
default_copies = 0
|
default_id = uuid.uuid4()
|
||||||
for mcs in data:
|
for mcs in data:
|
||||||
if mcs.menu_category is None and mcs.printer is None:
|
if mcs.menu_category is None and mcs.printer is None:
|
||||||
raise ValueError("Please choose a default printer")
|
raise ValueError("Please choose a default printer")
|
||||||
if mcs.printer is None:
|
if mcs.printer is None:
|
||||||
continue
|
continue
|
||||||
if mcs.menu_category is None:
|
|
||||||
default_copies = mcs.copies
|
|
||||||
stmt = (
|
stmt = (
|
||||||
pg_insert(SectionPrinter)
|
pg_insert(SectionPrinter)
|
||||||
.values(
|
.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,
|
menu_category_id=mcs.menu_category.id_ if mcs.menu_category is not None else None,
|
||||||
section_id=id_,
|
section_id=id_,
|
||||||
printer_id=mcs.printer.id_,
|
printer_id=mcs.printer.id_,
|
||||||
@ -59,7 +57,7 @@ def save(
|
|||||||
and_(
|
and_(
|
||||||
SectionPrinter.section_id == id_,
|
SectionPrinter.section_id == id_,
|
||||||
SectionPrinter.menu_category_id == None, # noqa: E711
|
SectionPrinter.menu_category_id == None, # noqa: E711
|
||||||
SectionPrinter.copies != default_copies,
|
SectionPrinter.id != default_id,
|
||||||
),
|
),
|
||||||
and_(
|
and_(
|
||||||
SectionPrinter.section_id == id_,
|
SectionPrinter.section_id == id_,
|
||||||
@ -121,15 +119,19 @@ def report(section_id: Optional[uuid.UUID], db: Session) -> List[schemas.Section
|
|||||||
).all()
|
).all()
|
||||||
list_ = []
|
list_ = []
|
||||||
for mc_id, mc_name in [(None, None)] + menu_categories:
|
for mc_id, mc_name in [(None, None)] + menu_categories:
|
||||||
section_printer = db.execute(
|
section_printer = (
|
||||||
select(SectionPrinter).where(
|
db.execute(
|
||||||
SectionPrinter.section_id == section_id,
|
select(SectionPrinter).where(
|
||||||
SectionPrinter.menu_category_id == mc_id,
|
SectionPrinter.section_id == section_id,
|
||||||
|
SectionPrinter.menu_category_id == mc_id,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
).scalar_one()
|
.scalars()
|
||||||
|
.one_or_none()
|
||||||
|
)
|
||||||
list_.append(
|
list_.append(
|
||||||
schemas.SectionPrinter(
|
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),
|
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,
|
copies=0 if section_printer is None else section_printer.copies,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user