Updates
This commit is contained in:
@@ -27,7 +27,7 @@ def _build_session_access_query(session: AuthSession):
|
||||
def _load_product_for_calculation(db: Session, tenant_id: str, product_id: int) -> Product | None:
|
||||
return db.scalar(
|
||||
select(Product)
|
||||
.where(Product.id == product_id, Product.tenant_id == tenant_id)
|
||||
.where(Product.id == product_id, Product.tenant_id == tenant_id, Product.visible.is_(True))
|
||||
.options(selectinload(Product.mix).selectinload(Mix.ingredients).selectinload(MixIngredient.raw_material))
|
||||
)
|
||||
|
||||
@@ -122,7 +122,7 @@ def build_mix_calculator_options(db: Session, *, tenant_id: str) -> dict:
|
||||
|
||||
products = db.scalars(
|
||||
select(Product)
|
||||
.where(Product.tenant_id == tenant_id)
|
||||
.where(Product.tenant_id == tenant_id, Product.visible.is_(True))
|
||||
.options(joinedload(Product.mix))
|
||||
.order_by(Product.client_name, Product.name)
|
||||
).all()
|
||||
@@ -191,11 +191,12 @@ def serialize_mix_calculator_session(session_record: MixCalculatorSession, auth_
|
||||
}
|
||||
|
||||
|
||||
def list_mix_calculator_sessions(db: Session, *, auth_session: AuthSession) -> list[dict]:
|
||||
def list_mix_calculator_sessions(db: Session, *, auth_session: AuthSession, limit: int = 100) -> list[dict]:
|
||||
sessions = db.scalars(
|
||||
_build_session_access_query(auth_session)
|
||||
.options(selectinload(MixCalculatorSession.lines))
|
||||
.order_by(MixCalculatorSession.created_at.desc(), MixCalculatorSession.id.desc())
|
||||
.limit(limit)
|
||||
).all()
|
||||
return [serialize_mix_calculator_session(session_record, auth_session) for session_record in sessions]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user