Fix: Modifier Category was showing products from out of category.
This commit is contained in:
@ -6,9 +6,7 @@ from functools import reduce
|
|||||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||||
from sqlalchemy import and_, or_, select
|
from sqlalchemy import and_, or_, select
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from sqlalchemy.orm import Session, joinedload
|
from sqlalchemy.orm import Session, contains_eager
|
||||||
|
|
||||||
import barker.schemas.modifier_category as schemas
|
|
||||||
|
|
||||||
from ..core.security import get_current_active_user as get_user
|
from ..core.security import get_current_active_user as get_user
|
||||||
from ..db.session import SessionFuture
|
from ..db.session import SessionFuture
|
||||||
@ -16,6 +14,7 @@ from ..models.menu_category import MenuCategory
|
|||||||
from ..models.modifier_category import ModifierCategory
|
from ..models.modifier_category import ModifierCategory
|
||||||
from ..models.product import Product
|
from ..models.product import Product
|
||||||
from ..models.product_version import ProductVersion
|
from ..models.product_version import ProductVersion
|
||||||
|
from ..schemas import modifier_category as schemas
|
||||||
from ..schemas.product_link import ProductLink as ProductLinkSchema
|
from ..schemas.product_link import ProductLink as ProductLinkSchema
|
||||||
from ..schemas.user_token import UserToken
|
from ..schemas.user_token import UserToken
|
||||||
from . import effective_date
|
from . import effective_date
|
||||||
@ -104,6 +103,17 @@ def show_blank(
|
|||||||
@router.get("/list")
|
@router.get("/list")
|
||||||
def show_list(date_: date = Depends(effective_date), user: UserToken = Depends(get_user)):
|
def show_list(date_: date = Depends(effective_date), user: UserToken = Depends(get_user)):
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
|
product_version_onclause = and_(
|
||||||
|
ProductVersion.menu_category_id == MenuCategory.id,
|
||||||
|
or_(
|
||||||
|
ProductVersion.valid_from == None, # noqa: E711
|
||||||
|
ProductVersion.valid_from <= date_,
|
||||||
|
),
|
||||||
|
or_(
|
||||||
|
ProductVersion.valid_till == None, # noqa: E711
|
||||||
|
ProductVersion.valid_till >= date_,
|
||||||
|
),
|
||||||
|
)
|
||||||
list_ = (
|
list_ = (
|
||||||
db.execute(select(ModifierCategory).order_by(ModifierCategory.sort_order).order_by(ModifierCategory.name))
|
db.execute(select(ModifierCategory).order_by(ModifierCategory.sort_order).order_by(ModifierCategory.name))
|
||||||
.scalars()
|
.scalars()
|
||||||
@ -112,23 +122,9 @@ def show_list(date_: date = Depends(effective_date), user: UserToken = Depends(g
|
|||||||
menu_categories = (
|
menu_categories = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(MenuCategory)
|
select(MenuCategory)
|
||||||
.join(MenuCategory.products)
|
.join(ProductVersion, onclause=product_version_onclause)
|
||||||
.where(
|
|
||||||
and_(
|
|
||||||
or_(
|
|
||||||
ProductVersion.valid_from == None, # noqa: E711
|
|
||||||
ProductVersion.valid_from <= date_,
|
|
||||||
),
|
|
||||||
or_(
|
|
||||||
ProductVersion.valid_till == None, # noqa: E711
|
|
||||||
ProductVersion.valid_till >= date_,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name)
|
.order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name)
|
||||||
.options(
|
.options(contains_eager(MenuCategory.products))
|
||||||
joinedload(MenuCategory.products, innerjoin=True),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.unique()
|
.unique()
|
||||||
.scalars()
|
.scalars()
|
||||||
@ -197,26 +193,23 @@ def show_id(
|
|||||||
|
|
||||||
|
|
||||||
def modifier_category_info(item: ModifierCategory, date_: date, db: Session) -> schemas.ModifierCategory:
|
def modifier_category_info(item: ModifierCategory, date_: date, db: Session) -> schemas.ModifierCategory:
|
||||||
|
product_version_onclause = and_(
|
||||||
|
ProductVersion.menu_category_id == MenuCategory.id,
|
||||||
|
or_(
|
||||||
|
ProductVersion.valid_from == None, # noqa: E711
|
||||||
|
ProductVersion.valid_from <= date_,
|
||||||
|
),
|
||||||
|
or_(
|
||||||
|
ProductVersion.valid_till == None, # noqa: E711
|
||||||
|
ProductVersion.valid_till >= date_,
|
||||||
|
),
|
||||||
|
)
|
||||||
menu_categories = (
|
menu_categories = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(MenuCategory)
|
select(MenuCategory)
|
||||||
.join(MenuCategory.products)
|
.join(ProductVersion, onclause=product_version_onclause)
|
||||||
.where(
|
|
||||||
and_(
|
|
||||||
or_(
|
|
||||||
ProductVersion.valid_from == None, # noqa: E711
|
|
||||||
ProductVersion.valid_from <= date_,
|
|
||||||
),
|
|
||||||
or_(
|
|
||||||
ProductVersion.valid_till == None, # noqa: E711
|
|
||||||
ProductVersion.valid_till >= date_,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name)
|
.order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name)
|
||||||
.options(
|
.options(contains_eager(MenuCategory.products))
|
||||||
joinedload(MenuCategory.products, innerjoin=True),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.unique()
|
.unique()
|
||||||
.scalars()
|
.scalars()
|
||||||
@ -249,26 +242,23 @@ def modifier_category_info(item: ModifierCategory, date_: date, db: Session) ->
|
|||||||
|
|
||||||
|
|
||||||
def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryBlank:
|
def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryBlank:
|
||||||
|
product_version_onclause = and_(
|
||||||
|
ProductVersion.menu_category_id == MenuCategory.id,
|
||||||
|
or_(
|
||||||
|
ProductVersion.valid_from == None, # noqa: E711
|
||||||
|
ProductVersion.valid_from <= date_,
|
||||||
|
),
|
||||||
|
or_(
|
||||||
|
ProductVersion.valid_till == None, # noqa: E711
|
||||||
|
ProductVersion.valid_till >= date_,
|
||||||
|
),
|
||||||
|
)
|
||||||
menu_categories = (
|
menu_categories = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(MenuCategory)
|
select(MenuCategory)
|
||||||
.join(MenuCategory.products)
|
.join(ProductVersion, onclause=product_version_onclause)
|
||||||
.where(
|
|
||||||
and_(
|
|
||||||
or_(
|
|
||||||
ProductVersion.valid_from == None, # noqa: E711
|
|
||||||
ProductVersion.valid_from <= date_,
|
|
||||||
),
|
|
||||||
or_(
|
|
||||||
ProductVersion.valid_till == None, # noqa: E711
|
|
||||||
ProductVersion.valid_till >= date_,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name)
|
.order_by(MenuCategory.sort_order, ProductVersion.sort_order, ProductVersion.name)
|
||||||
.options(
|
.options(contains_eager(MenuCategory.products))
|
||||||
joinedload(MenuCategory.products, innerjoin=True),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.unique()
|
.unique()
|
||||||
.scalars()
|
.scalars()
|
||||||
|
|||||||
Reference in New Issue
Block a user