Feature: In the Beer Sale Report, you can choose the type of consumption
Chore: Sorted the product sale report by name Fix: Voided bills now also include the old bill number
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from datetime import date, timedelta
|
||||
from operator import or_
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Security
|
||||
from sqlalchemy.sql.expression import func, select
|
||||
@ -23,6 +24,10 @@ router = APIRouter()
|
||||
def beer_consumption(
|
||||
start_date: date = Depends(report_start_date),
|
||||
finish_date: date = Depends(report_finish_date),
|
||||
r: Optional[bool] = True,
|
||||
h: Optional[bool] = True,
|
||||
st: Optional[bool] = True,
|
||||
n: Optional[bool] = True,
|
||||
user: UserToken = Security(get_user, scopes=["beer-sale-report"]),
|
||||
):
|
||||
check_audit_permission(start_date, user.permissions)
|
||||
@ -30,31 +35,39 @@ def beer_consumption(
|
||||
"day", Voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES)
|
||||
).label("day")
|
||||
sum_ = func.sum(Inventory.quantity * ProductVersion.quantity).label("sum")
|
||||
query = (
|
||||
select(day, ProductVersion.name, sum_)
|
||||
.join(Voucher.kots)
|
||||
.join(Kot.inventories)
|
||||
.join(Inventory.product)
|
||||
.where(
|
||||
day >= start_date,
|
||||
day <= finish_date,
|
||||
or_(
|
||||
ProductVersion.valid_from == None, # noqa: E711
|
||||
ProductVersion.valid_from <= day,
|
||||
),
|
||||
or_(
|
||||
ProductVersion.valid_till == None, # noqa: E711
|
||||
ProductVersion.valid_till >= day,
|
||||
),
|
||||
)
|
||||
)
|
||||
if h is False and r is not False:
|
||||
query = query.where(Inventory.is_happy_hour == h)
|
||||
if r is False and h is not False:
|
||||
query = query.where(Inventory.is_happy_hour != r)
|
||||
vt = []
|
||||
if h is True or r is True:
|
||||
vt.append(VoucherType.REGULAR_BILL)
|
||||
if st is True:
|
||||
vt.append(VoucherType.STAFF)
|
||||
if n is True:
|
||||
vt.append(VoucherType.NO_CHARGE)
|
||||
|
||||
with SessionFuture() as db:
|
||||
list_ = db.execute(
|
||||
select(day, ProductVersion.name, sum_)
|
||||
.join(Voucher.kots)
|
||||
.join(Kot.inventories)
|
||||
.join(Inventory.product)
|
||||
.where(
|
||||
day >= start_date,
|
||||
day <= finish_date,
|
||||
or_(
|
||||
ProductVersion.valid_from == None, # noqa: E711
|
||||
ProductVersion.valid_from <= day,
|
||||
),
|
||||
or_(
|
||||
ProductVersion.valid_till == None, # noqa: E711
|
||||
ProductVersion.valid_till >= day,
|
||||
),
|
||||
Voucher.voucher_type.in_(
|
||||
[
|
||||
VoucherType.REGULAR_BILL,
|
||||
VoucherType.NO_CHARGE,
|
||||
VoucherType.STAFF,
|
||||
]
|
||||
),
|
||||
)
|
||||
query.where(Voucher.voucher_type.in_(vt))
|
||||
.group_by(day, ProductVersion.name)
|
||||
.having(sum_ != 0)
|
||||
.order_by(day, ProductVersion.name)
|
||||
@ -72,6 +85,10 @@ def beer_consumption(
|
||||
return {
|
||||
"startDate": start_date.strftime("%d-%b-%Y"),
|
||||
"finishDate": finish_date.strftime("%d-%b-%Y"),
|
||||
"regular": r,
|
||||
"happy": h,
|
||||
"staff": st,
|
||||
"nc": n,
|
||||
"headers": headers,
|
||||
"data": data,
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ def product_sale_report(s: date, f: date, db: Session):
|
||||
Voucher.voucher_type,
|
||||
Inventory.is_happy_hour,
|
||||
)
|
||||
.order_by(SaleCategory.name, MenuCategory.name)
|
||||
.order_by(SaleCategory.name, MenuCategory.name, ProductVersion.full_name)
|
||||
).all()
|
||||
info = []
|
||||
for id_, name, type_, hh, quantity in list_:
|
||||
|
||||
@ -84,9 +84,9 @@ def void_and_issue_new_bill(
|
||||
guest_book = get_guest_book(g, db)
|
||||
item: Voucher = do_save(data, old.voucher_type, guest_book, db, user)
|
||||
db.flush()
|
||||
old.reason = f"Bill Discounted or Changed / Old Bill: {old.full_bill_id} / New Bill: {item.full_bill_id}."
|
||||
old.bill_id = None
|
||||
old.voucher_type = VoucherType.VOID
|
||||
old.reason = f"Bill Discounted / Changed. New Bill ID is {item.full_bill_id}"
|
||||
do_update_settlements(old, [SettleSchema(id=SettleOption.VOID(), amount=round(old.amount))], db)
|
||||
|
||||
if update_table:
|
||||
|
||||
Reference in New Issue
Block a user