Feature: Open bill using bill number
This commit is contained in:
@ -46,22 +46,34 @@ def from_bill(
|
||||
item: Voucher = db.query(Voucher)
|
||||
if re.compile(r"^\d{2,}-\d{4}$").match(id_):
|
||||
item = item.filter(
|
||||
Voucher.bill_id == int(id_.replace("-", "")),
|
||||
Voucher.voucher_type.in_([1, 3]),
|
||||
Voucher.bill_id == int(id_.replace("-", "")), Voucher.voucher_type == VoucherType.REGULAR_BILL
|
||||
)
|
||||
elif re.compile(r"^K-\d+$").match(id_):
|
||||
item = item.filter(
|
||||
Voucher.kot_id == int(id_.replace("K-", "")),
|
||||
Voucher.voucher_type == VoucherType.KOT,
|
||||
)
|
||||
elif re.compile(r"^NC-\d+$").match(id_):
|
||||
item = item.filter(
|
||||
Voucher.bill_id == int(id_.replace("NC-", "")),
|
||||
Voucher.voucher_type == 2,
|
||||
Voucher.voucher_type == VoucherType.NO_CHARGE,
|
||||
)
|
||||
elif re.compile(r"^ST-\d+$").match(id_):
|
||||
item = item.filter(
|
||||
Voucher.bill_id == int(id_.replace("ST-", "")),
|
||||
Voucher.voucher_type == 4,
|
||||
Voucher.voucher_type == VoucherType.STAFF,
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail="Bill Number is invalid",
|
||||
)
|
||||
item = item.first()
|
||||
if item is None:
|
||||
return {}
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Bill not found",
|
||||
)
|
||||
return voucher_info(item, db)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user