Fix: Kots were not sorted in show voucher.

This commit is contained in:
2025-07-09 14:10:31 +00:00
parent 5317e3de23
commit b2732434f4

View File

@ -68,6 +68,7 @@ def from_id(
.join(Inventory.product) .join(Inventory.product)
.join(ProductVersion, onclause=product_version_onclause) .join(ProductVersion, onclause=product_version_onclause)
.where(Voucher.id == id_) .where(Voucher.id == id_)
.order_by(Kot.code)
.options( .options(
contains_eager(Voucher.food_table), contains_eager(Voucher.food_table),
contains_eager(Voucher.customer), contains_eager(Voucher.customer),
@ -103,8 +104,7 @@ def from_bill(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Bill Number is invalid", detail="Bill Number is invalid",
) )
item = ( item: Voucher | None = db.execute(
db.execute(
select(Voucher) select(Voucher)
.join(Voucher.bills) .join(Voucher.bills)
.join(Bill.regime) .join(Bill.regime)
@ -115,6 +115,7 @@ def from_bill(
.join(Inventory.product) .join(Inventory.product)
.join(ProductVersion, onclause=product_version_onclause) .join(ProductVersion, onclause=product_version_onclause)
.where(Regime.prefix == match.group(1), Bill.bill_number == int(match.group(2))) .where(Regime.prefix == match.group(1), Bill.bill_number == int(match.group(2)))
.order_by(Kot.code)
.options( .options(
contains_eager(Voucher.food_table), contains_eager(Voucher.food_table),
contains_eager(Voucher.customer), contains_eager(Voucher.customer),
@ -124,10 +125,7 @@ def from_bill(
.contains_eager(Product.versions), .contains_eager(Product.versions),
contains_eager(Voucher.bills).contains_eager(Bill.regime), contains_eager(Voucher.bills).contains_eager(Bill.regime),
) )
) ).scalar_one_or_none()
.scalars()
.one_or_none()
)
if item is None: if item is None:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_404_NOT_FOUND,
@ -183,6 +181,7 @@ def from_table(
.join(Inventory.product) .join(Inventory.product)
.join(ProductVersion, onclause=product_version_onclause) .join(ProductVersion, onclause=product_version_onclause)
.where(Voucher.id == v) .where(Voucher.id == v)
.order_by(Kot.code)
.options( .options(
contains_eager(Voucher.food_table), contains_eager(Voucher.food_table),
contains_eager(Voucher.customer), contains_eager(Voucher.customer),