invoices, order handling, db updates
This commit is contained in:
@@ -2,7 +2,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import delete, func, select, update
|
||||
from typing import Optional
|
||||
|
||||
from db.models.orders import OrderItem
|
||||
from db.models.orders import Order, OrderItem, OrderStatus
|
||||
|
||||
|
||||
class OrderItemRepository:
|
||||
@@ -29,6 +29,19 @@ class OrderItemRepository:
|
||||
stmt = select(func.count(OrderItem.id)).where(OrderItem.order_id == order_id)
|
||||
return await session.scalar(stmt) or 0
|
||||
|
||||
async def get_items_count_by_customer(
|
||||
self, session: AsyncSession, customer: int
|
||||
) -> int:
|
||||
count = await session.scalar(
|
||||
select(func.count(OrderItem.id))
|
||||
.join(Order)
|
||||
.where(
|
||||
Order.customer == customer,
|
||||
Order.status == OrderStatus.DRAFT,
|
||||
)
|
||||
)
|
||||
return int(count)
|
||||
|
||||
async def get_item_by_order_and_product(
|
||||
self, session: AsyncSession, *, order_id: int, product_id: int
|
||||
) -> Optional[OrderItem]:
|
||||
|
||||
Reference in New Issue
Block a user