invoices, order handling, db updates

This commit is contained in:
2026-02-14 23:09:21 +07:00
parent a3aaafd7ac
commit 50b1a8f80c
28 changed files with 508 additions and 44 deletions

View File

@@ -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]: