Add user delete process 2
This commit is contained in:
@@ -17,6 +17,7 @@ from app.schemas.purchase_order_schemas import (
|
||||
PurchaseOrderCreate,
|
||||
PurchaseOrderUpdate,
|
||||
PurchaseOrderResponse,
|
||||
PurchaseOrderWithSupplierResponse,
|
||||
PurchaseOrderApproval,
|
||||
DeliveryCreate,
|
||||
DeliveryResponse,
|
||||
@@ -75,7 +76,7 @@ async def create_purchase_order(
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/{po_id}", response_model=PurchaseOrderResponse)
|
||||
@router.get("/{po_id}", response_model=PurchaseOrderWithSupplierResponse)
|
||||
async def get_purchase_order(
|
||||
tenant_id: str,
|
||||
po_id: str,
|
||||
@@ -91,7 +92,7 @@ async def get_purchase_order(
|
||||
if not po:
|
||||
raise HTTPException(status_code=404, detail="Purchase order not found")
|
||||
|
||||
return PurchaseOrderResponse.model_validate(po)
|
||||
return PurchaseOrderWithSupplierResponse.model_validate(po)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
|
||||
@@ -50,7 +50,7 @@ class PurchaseOrderItemResponse(PurchaseOrderBase):
|
||||
tenant_id: uuid.UUID
|
||||
purchase_order_id: uuid.UUID
|
||||
inventory_product_id: uuid.UUID # Changed from ingredient_id to match model
|
||||
ingredient_name: Optional[str] = None
|
||||
product_name: Optional[str] = None
|
||||
ordered_quantity: Decimal
|
||||
received_quantity: Decimal
|
||||
unit_price: Decimal
|
||||
@@ -109,6 +109,29 @@ class PurchaseOrderApproval(PurchaseOrderBase):
|
||||
approved_by: Optional[uuid.UUID] = None
|
||||
|
||||
|
||||
class SupplierSummary(PurchaseOrderBase):
|
||||
"""Schema for supplier summary - matches the structure returned by suppliers service"""
|
||||
id: str
|
||||
name: str
|
||||
supplier_code: Optional[str] = None
|
||||
email: Optional[str] = None
|
||||
phone: Optional[str] = None
|
||||
contact_person: Optional[str] = None
|
||||
address_line1: Optional[str] = None
|
||||
city: Optional[str] = None
|
||||
country: Optional[str] = None
|
||||
supplier_type: Optional[str] = None
|
||||
status: Optional[str] = None
|
||||
mobile: Optional[str] = None
|
||||
website: Optional[str] = None
|
||||
payment_terms: Optional[str] = None
|
||||
standard_lead_time: Optional[int] = None
|
||||
quality_rating: Optional[float] = None
|
||||
delivery_rating: Optional[float] = None
|
||||
total_orders: Optional[int] = None
|
||||
total_amount: Optional[float] = None
|
||||
|
||||
|
||||
class PurchaseOrderResponse(PurchaseOrderBase):
|
||||
"""Schema for purchase order responses"""
|
||||
id: uuid.UUID
|
||||
@@ -155,6 +178,11 @@ class PurchaseOrderResponse(PurchaseOrderBase):
|
||||
items: List[PurchaseOrderItemResponse] = []
|
||||
|
||||
|
||||
class PurchaseOrderWithSupplierResponse(PurchaseOrderResponse):
|
||||
"""Schema for purchase order responses with supplier information"""
|
||||
supplier: Optional[SupplierSummary] = None
|
||||
|
||||
|
||||
class PurchaseOrderSummary(PurchaseOrderBase):
|
||||
"""Schema for purchase order summary (list view)"""
|
||||
id: uuid.UUID
|
||||
|
||||
@@ -613,9 +613,37 @@ class PurchaseOrderService:
|
||||
if supplier:
|
||||
# Set supplier_name as a dynamic attribute on the model instance
|
||||
po.supplier_name = supplier.get('name', 'Unknown Supplier')
|
||||
|
||||
# Create a supplier summary object with the required fields for the frontend
|
||||
# Using the same structure as the suppliers service SupplierSummary schema
|
||||
supplier_summary = {
|
||||
'id': supplier.get('id'),
|
||||
'name': supplier.get('name', 'Unknown Supplier'),
|
||||
'supplier_code': supplier.get('supplier_code'),
|
||||
'email': supplier.get('email'),
|
||||
'phone': supplier.get('phone'),
|
||||
'contact_person': supplier.get('contact_person'),
|
||||
'address_line1': supplier.get('address_line1'),
|
||||
'city': supplier.get('city'),
|
||||
'country': supplier.get('country'),
|
||||
'supplier_type': supplier.get('supplier_type', 'raw_material'),
|
||||
'status': supplier.get('status', 'active'),
|
||||
'mobile': supplier.get('mobile'),
|
||||
'website': supplier.get('website'),
|
||||
'payment_terms': supplier.get('payment_terms', 'NET_30'),
|
||||
'standard_lead_time': supplier.get('standard_lead_time', 3),
|
||||
'quality_rating': supplier.get('quality_rating'),
|
||||
'delivery_rating': supplier.get('delivery_rating'),
|
||||
'total_orders': supplier.get('total_orders', 0),
|
||||
'total_amount': supplier.get('total_amount', 0)
|
||||
}
|
||||
|
||||
# Set the full supplier object as a dynamic attribute
|
||||
po.supplier = supplier_summary
|
||||
except Exception as e:
|
||||
logger.warning("Failed to enrich PO with supplier info", error=str(e), po_id=po.id, supplier_id=po.supplier_id)
|
||||
po.supplier_name = None
|
||||
po.supplier = None
|
||||
|
||||
def _requires_approval(self, total_amount: Decimal, priority: str) -> bool:
|
||||
"""Determine if PO requires approval"""
|
||||
|
||||
Reference in New Issue
Block a user