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