diff --git a/barker/barker/models/inventory.py b/barker/barker/models/inventory.py
index bdd74b58..0f21fbbd 100644
--- a/barker/barker/models/inventory.py
+++ b/barker/barker/models/inventory.py
@@ -53,7 +53,7 @@ class Inventory:
type_: Mapped[InventoryType] = mapped_column(
"type", Enum(InventoryType), server_default=text("regular"), nullable=False
)
- parent_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, ForeignKey("inventories.id"), nullable=True)
+ parent_id: Mapped[uuid.UUID | None] = mapped_column(Uuid, ForeignKey("inventories.id"), nullable=True, index=True)
kot: Mapped[Kot] = relationship(back_populates="inventories")
tax: Mapped[Tax] = relationship(back_populates="inventories")
diff --git a/barker/barker/models/inventory_modifier.py b/barker/barker/models/inventory_modifier.py
index 3adf8152..a8ad07df 100644
--- a/barker/barker/models/inventory_modifier.py
+++ b/barker/barker/models/inventory_modifier.py
@@ -22,7 +22,7 @@ class InventoryModifier:
__table_args__ = (UniqueConstraint("inventory_id", "modifier_id"),)
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()"))
- inventory_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("inventories.id"), nullable=False)
+ inventory_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("inventories.id"), nullable=False, index=True)
modifier_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("modifiers.id"), nullable=False)
price: Mapped[Decimal] = mapped_column(Numeric(precision=15, scale=2), nullable=False)
diff --git a/barker/barker/models/role_includes.py b/barker/barker/models/role_includes.py
index 4c11ca94..0044e4a2 100644
--- a/barker/barker/models/role_includes.py
+++ b/barker/barker/models/role_includes.py
@@ -24,5 +24,5 @@ class RoleInclude:
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text("gen_random_uuid()"))
- role_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("roles.id"), nullable=False)
- included_role_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("roles.id"), nullable=False)
+ role_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("roles.id"), nullable=False, index=True)
+ included_role_id: Mapped[uuid.UUID] = mapped_column(Uuid, ForeignKey("roles.id"), nullable=False, index=True)
diff --git a/barker/barker/routers/product.py b/barker/barker/routers/product.py
index 1e4408f3..1da9cee3 100644
--- a/barker/barker/routers/product.py
+++ b/barker/barker/routers/product.py
@@ -32,7 +32,7 @@ from ..schemas.sale_category import SaleCategoryLink
from ..schemas.stock_keeping_unit import StockKeepingUnit as StockKeepingUnitSchema
from ..schemas.tax import TaxLink
from ..schemas.user_token import UserToken
-from . import _pv_onclause, _sv_onclause, effective_date
+from . import _pv_active, _pv_onclause, _sv_onclause, effective_date
router = APIRouter()
@@ -241,7 +241,6 @@ def update_route(
or new_data_sku.has_happy_hour != sku.has_happy_hour
or new_data_sku.menu_category.id_ != sku.menu_category_id
)
- print(f"SKU Changed: {sku_changed} for {sku.id}")
sku.sku.sort_order = new_data_sku.sort_order
sku.sku.is_not_available = new_data_sku.is_not_available
if sku_changed:
@@ -471,7 +470,6 @@ def show_term(
) -> list[ProductQuery]:
product_version_onclause = _pv_onclause(date_)
sku_version_onclause = _sv_onclause(date_)
- print(f"Fetching products for MenuCategory: {mc}, SaleCategory: {sc}, Date: {date_}")
list_: list[ProductQuery] = []
query = (
select(SkuVersion)
@@ -525,17 +523,6 @@ def show_id(
date_: date = Depends(effective_date),
user: UserToken = Security(get_user, scopes=["products"]),
) -> schemas.Product:
- pv_active = and_(
- ProductVersion.product_id == id_,
- or_(ProductVersion.valid_from == None, ProductVersion.valid_from <= date_), # noqa: E711
- or_(ProductVersion.valid_till == None, ProductVersion.valid_till >= date_), # noqa: E711
- )
-
- sku_version_onclause = and_(
- SkuVersion.sku_id == StockKeepingUnit.id,
- or_(SkuVersion.valid_from == None, SkuVersion.valid_from <= date_), # noqa: E711
- or_(SkuVersion.valid_till == None, SkuVersion.valid_till >= date_), # noqa: E711
- )
with SessionFuture() as db:
version: ProductVersion = (
db.execute(
@@ -543,9 +530,9 @@ def show_id(
.join(ProductVersion.sale_category)
.join(ProductVersion.product)
.join(Product.skus)
- .join(SkuVersion, onclause=sku_version_onclause)
+ .join(SkuVersion, onclause=_sv_onclause(date_))
.join(SkuVersion.menu_category)
- .where(pv_active)
+ .where(ProductVersion.product_id == id_, _pv_active(date_))
.order_by(
StockKeepingUnit.sort_order,
SkuVersion.units,
diff --git a/barker/barker/routers/reports/beer_sale_report.py b/barker/barker/routers/reports/beer_sale_report.py
index af86afff..b6349f7c 100644
--- a/barker/barker/routers/reports/beer_sale_report.py
+++ b/barker/barker/routers/reports/beer_sale_report.py
@@ -1,3 +1,5 @@
+import uuid
+
from datetime import date, timedelta
from fastapi import APIRouter, Depends, Security
@@ -16,6 +18,7 @@ from ...models.stock_keeping_unit import StockKeepingUnit
from ...models.voucher import Voucher
from ...models.voucher_type import VoucherType
from ...schemas.beer_consumption_report import BeerConsumptionReport, BeerConsumptionReportItem
+from ...schemas.menu_category import MenuCategoryLink
from ...schemas.user_token import UserToken
from .. import _pv_onclause, _sv_onclause
from . import check_audit_permission, report_finish_date, report_start_date
@@ -28,6 +31,7 @@ router = APIRouter()
def beer_consumption(
start_date: date = Depends(report_start_date),
finish_date: date = Depends(report_finish_date),
+ m: uuid.UUID | None = None, # Menu Category
r: bool | None = True,
h: bool | None = True,
st: bool | None = True,
@@ -47,6 +51,7 @@ def beer_consumption(
.join(Kot.inventories)
.join(Inventory.sku)
.join(SkuVersion, onclause=sku_version_onclause)
+ .join(SkuVersion.menu_category)
.join(StockKeepingUnit.product)
.join(ProductVersion, onclause=product_version_onclause)
.where(
@@ -55,6 +60,8 @@ def beer_consumption(
day <= finish_date,
)
)
+ if m:
+ query = query.where(SkuVersion.menu_category_id == m)
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:
@@ -89,6 +96,7 @@ def beer_consumption(
return BeerConsumptionReport(
start_date=start_date,
finish_date=finish_date,
+ menu_category=MenuCategoryLink(id_=m, name="", skus=[]) if m else None,
regular=r,
happy=h,
staff=st,
diff --git a/barker/barker/schemas/beer_consumption_report.py b/barker/barker/schemas/beer_consumption_report.py
index 42c670a8..b4083ef4 100644
--- a/barker/barker/schemas/beer_consumption_report.py
+++ b/barker/barker/schemas/beer_consumption_report.py
@@ -13,6 +13,7 @@ from pydantic import (
)
from . import Daf, to_camel
+from .menu_category import MenuCategoryLink
class BeerConsumptionReportItem(BaseModel):
@@ -56,6 +57,7 @@ class BeerConsumptionReportItem(BaseModel):
class BeerConsumptionReport(BaseModel):
start_date: date
finish_date: date
+ menu_category: MenuCategoryLink | None
regular: bool | None
happy: bool | None
staff: bool | None
diff --git a/bookie/src/app/beer-sale-report/beer-sale-report.component.html b/bookie/src/app/beer-sale-report/beer-sale-report.component.html
index 6b5d8969..aa8e90eb 100644
--- a/bookie/src/app/beer-sale-report/beer-sale-report.component.html
+++ b/bookie/src/app/beer-sale-report/beer-sale-report.component.html
@@ -31,6 +31,16 @@