fix: add missing get_vendors_with_orders_admin method

Add the missing method to OrderService that was being called
from the admin orders API endpoint.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-19 21:49:42 +01:00
parent 2e6f8fdb8a
commit 06fbf8e53c

View File

@@ -1008,6 +1008,34 @@ class OrderService:
return order
def get_vendors_with_orders_admin(self, db: Session) -> list[dict]:
"""Get list of vendors that have orders (admin only)."""
from models.database.vendor import Vendor
# Query vendors with order counts
results = (
db.query(
Vendor.id,
Vendor.name,
Vendor.vendor_code,
func.count(Order.id).label("order_count"),
)
.join(Order, Order.vendor_id == Vendor.id)
.group_by(Vendor.id, Vendor.name, Vendor.vendor_code)
.order_by(func.count(Order.id).desc())
.all()
)
return [
{
"id": row.id,
"name": row.name,
"vendor_code": row.vendor_code,
"order_count": row.order_count,
}
for row in results
]
# Create service instance
order_service = OrderService()