Feature: Open bill using bill number

This commit is contained in:
2020-12-24 12:58:46 +05:30
parent 98c75f66c9
commit 161896154d
17 changed files with 234 additions and 29 deletions

View File

@ -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)