Fix: Could not open bill with bill number or voucher id
This commit is contained in:
@ -59,25 +59,29 @@ def from_id(
|
|||||||
ProductVersion.valid_till >= Voucher.date,
|
ProductVersion.valid_till >= Voucher.date,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
item: Voucher = db.execute(
|
item: Voucher = (
|
||||||
select(Voucher)
|
db.execute(
|
||||||
.join(Voucher.food_table)
|
select(Voucher)
|
||||||
.join(Voucher.customer, isouter=True)
|
.join(Voucher.food_table)
|
||||||
.join(Voucher.kots)
|
.join(Voucher.customer, isouter=True)
|
||||||
.join(Kot.inventories)
|
.join(Voucher.kots)
|
||||||
.join(Inventory.product)
|
.join(Kot.inventories)
|
||||||
.join(ProductVersion, onclause=product_version_onclause)
|
.join(Inventory.product)
|
||||||
.where(Voucher.id == id_)
|
.join(ProductVersion, onclause=product_version_onclause)
|
||||||
.order_by(Kot.code)
|
.where(Voucher.id == id_)
|
||||||
.options(
|
.order_by(Kot.code)
|
||||||
contains_eager(Voucher.food_table),
|
.options(
|
||||||
contains_eager(Voucher.customer),
|
contains_eager(Voucher.food_table),
|
||||||
contains_eager(Voucher.kots)
|
contains_eager(Voucher.customer),
|
||||||
.contains_eager(Kot.inventories)
|
contains_eager(Voucher.kots)
|
||||||
.contains_eager(Inventory.product)
|
.contains_eager(Kot.inventories)
|
||||||
.contains_eager(Product.versions),
|
.contains_eager(Inventory.product)
|
||||||
|
.contains_eager(Product.versions),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
).scalar_one()
|
.unique()
|
||||||
|
.scalar_one()
|
||||||
|
)
|
||||||
return voucher_info(item, db)
|
return voucher_info(item, db)
|
||||||
|
|
||||||
|
|
||||||
@ -104,28 +108,32 @@ 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: Voucher | None = db.execute(
|
item: Voucher | None = (
|
||||||
select(Voucher)
|
db.execute(
|
||||||
.join(Voucher.bills)
|
select(Voucher)
|
||||||
.join(Bill.regime)
|
.join(Voucher.bills)
|
||||||
.join(Voucher.food_table)
|
.join(Bill.regime)
|
||||||
.join(Voucher.customer, isouter=True)
|
.join(Voucher.food_table)
|
||||||
.join(Voucher.kots)
|
.join(Voucher.customer, isouter=True)
|
||||||
.join(Kot.inventories)
|
.join(Voucher.kots)
|
||||||
.join(Inventory.product)
|
.join(Kot.inventories)
|
||||||
.join(ProductVersion, onclause=product_version_onclause)
|
.join(Inventory.product)
|
||||||
.where(Regime.prefix == match.group(1), Bill.bill_number == int(match.group(2)))
|
.join(ProductVersion, onclause=product_version_onclause)
|
||||||
.order_by(Kot.code)
|
.where(Regime.prefix == match.group(1), Bill.bill_number == int(match.group(2)))
|
||||||
.options(
|
.order_by(Kot.code)
|
||||||
contains_eager(Voucher.food_table),
|
.options(
|
||||||
contains_eager(Voucher.customer),
|
contains_eager(Voucher.food_table),
|
||||||
contains_eager(Voucher.kots)
|
contains_eager(Voucher.customer),
|
||||||
.contains_eager(Kot.inventories)
|
contains_eager(Voucher.kots)
|
||||||
.contains_eager(Inventory.product)
|
.contains_eager(Kot.inventories)
|
||||||
.contains_eager(Product.versions),
|
.contains_eager(Inventory.product)
|
||||||
contains_eager(Voucher.bills).contains_eager(Bill.regime),
|
.contains_eager(Product.versions),
|
||||||
|
contains_eager(Voucher.bills).contains_eager(Bill.regime),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
).scalar_one_or_none()
|
.unique()
|
||||||
|
.scalar_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,
|
||||||
@ -192,8 +200,7 @@ def from_table(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.unique()
|
.unique()
|
||||||
.scalars()
|
.scalar_one()
|
||||||
.one()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if guest is not None:
|
if guest is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user