Fix: Beer Sale Report checking for wrong dates.

This commit is contained in:
Amritanshu Agrawal 2021-08-09 21:02:51 +05:30
parent 5402d229f8
commit 5e0e99340e

View File

@ -1,4 +1,4 @@
from datetime import date, datetime, time, timedelta
from datetime import date, timedelta
from operator import or_
from fastapi import APIRouter, Depends, Security
@ -26,13 +26,9 @@ def beer_consumption(
user: UserToken = Security(get_user, scopes=["beer-sale-report"]),
):
check_audit_permission(start_date, user.permissions)
s = datetime.combine(start_date, time()) + timedelta(
minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES
)
f = datetime.combine(finish_date, time()) + timedelta(
days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES
)
day = func.date_trunc("day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).label("day")
day = func.date_trunc(
"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")
with SessionFuture() as db:
list_ = db.execute(
@ -41,8 +37,8 @@ def beer_consumption(
.join(Kot.inventories)
.join(Inventory.product)
.where(
day >= s,
day <= f,
day >= start_date,
day <= finish_date,
or_(
ProductVersion.valid_from == None, # noqa: E711
ProductVersion.valid_from <= day,