Add supplier and imporve inventory frontend

This commit is contained in:
Urtzi Alfaro
2025-09-18 23:32:53 +02:00
parent ae77a0e1c5
commit d61056df33
40 changed files with 2022 additions and 629 deletions

View File

@@ -138,7 +138,6 @@ class DashboardService:
return SupplierPerformanceInsights(
supplier_id=supplier_id,
supplier_name=supplier['name'],
current_overall_score=current_metrics.get('overall_score', 0),
previous_score=previous_metrics.get('overall_score'),
score_change_percentage=self._calculate_change_percentage(

View File

@@ -7,7 +7,7 @@ import structlog
from typing import List, Optional, Dict, Any
from uuid import UUID
from datetime import datetime
from sqlalchemy.orm import Session
from sqlalchemy.ext.asyncio import AsyncSession
from app.repositories.supplier_repository import SupplierRepository
from app.models.suppliers import Supplier, SupplierStatus, SupplierType
@@ -23,7 +23,7 @@ logger = structlog.get_logger()
class SupplierService:
"""Service for supplier management operations"""
def __init__(self, db: Session):
def __init__(self, db: AsyncSession):
self.db = db
self.repository = SupplierRepository(db)
@@ -37,13 +37,13 @@ class SupplierService:
logger.info("Creating supplier", tenant_id=str(tenant_id), name=supplier_data.name)
# Check for duplicate name
existing = self.repository.get_by_name(tenant_id, supplier_data.name)
existing = await self.repository.get_by_name(tenant_id, supplier_data.name)
if existing:
raise ValueError(f"Supplier with name '{supplier_data.name}' already exists")
# Check for duplicate supplier code if provided
if supplier_data.supplier_code:
existing_code = self.repository.get_by_supplier_code(
existing_code = await self.repository.get_by_supplier_code(
tenant_id, supplier_data.supplier_code
)
if existing_code:
@@ -61,7 +61,7 @@ class SupplierService:
create_data.update({
'tenant_id': tenant_id,
'supplier_code': supplier_code,
'status': SupplierStatus.PENDING_APPROVAL,
'status': SupplierStatus.pending_approval,
'created_by': created_by,
'updated_by': created_by,
'quality_rating': 0.0,
@@ -70,7 +70,7 @@ class SupplierService:
'total_amount': 0.0
})
supplier = self.repository.create(create_data)
supplier = await self.repository.create(create_data)
logger.info(
"Supplier created successfully",
@@ -83,7 +83,7 @@ class SupplierService:
async def get_supplier(self, supplier_id: UUID) -> Optional[Supplier]:
"""Get supplier by ID"""
return self.repository.get_by_id(supplier_id)
return await self.repository.get_by_id(supplier_id)
async def update_supplier(
self,
@@ -138,7 +138,7 @@ class SupplierService:
# Soft delete by changing status
self.repository.update(supplier_id, {
'status': SupplierStatus.INACTIVE,
'status': SupplierStatus.inactive,
'updated_at': datetime.utcnow()
})
@@ -151,7 +151,7 @@ class SupplierService:
search_params: SupplierSearchParams
) -> List[Supplier]:
"""Search suppliers with filters"""
return self.repository.search_suppliers(
return await self.repository.search_suppliers(
tenant_id=tenant_id,
search_term=search_params.search_term,
supplier_type=search_params.supplier_type,
@@ -239,7 +239,7 @@ class SupplierService:
async def get_supplier_statistics(self, tenant_id: UUID) -> Dict[str, Any]:
"""Get supplier statistics for dashboard"""
return self.repository.get_supplier_statistics(tenant_id)
return await self.repository.get_supplier_statistics(tenant_id)
async def get_suppliers_needing_review(
self,