Improve the frontend 2
This commit is contained in:
@@ -13,7 +13,8 @@ from app.repositories.supplier_repository import SupplierRepository
|
||||
from app.models.suppliers import Supplier, SupplierStatus, SupplierType
|
||||
from app.schemas.suppliers import (
|
||||
SupplierCreate, SupplierUpdate, SupplierResponse,
|
||||
SupplierSearchParams, SupplierStatistics
|
||||
SupplierSearchParams, SupplierStatistics,
|
||||
SupplierPriceListCreate, SupplierPriceListUpdate, SupplierPriceListResponse
|
||||
)
|
||||
from app.core.config import settings
|
||||
|
||||
@@ -378,3 +379,132 @@ class SupplierService:
|
||||
errors['minimum_order_amount'] = "Minimum order amount cannot be negative"
|
||||
|
||||
return errors
|
||||
|
||||
async def get_supplier_price_lists(
|
||||
self,
|
||||
supplier_id: UUID,
|
||||
tenant_id: UUID,
|
||||
is_active: bool = True
|
||||
) -> List[Any]:
|
||||
"""Get all price list items for a supplier"""
|
||||
logger.info(
|
||||
"Getting supplier price lists",
|
||||
supplier_id=str(supplier_id),
|
||||
tenant_id=str(tenant_id),
|
||||
is_active=is_active
|
||||
)
|
||||
|
||||
return await self.repository.get_supplier_price_lists(
|
||||
supplier_id=supplier_id,
|
||||
tenant_id=tenant_id,
|
||||
is_active=is_active
|
||||
)
|
||||
|
||||
async def get_supplier_price_list(
|
||||
self,
|
||||
price_list_id: UUID,
|
||||
tenant_id: UUID
|
||||
) -> Optional[Any]:
|
||||
"""Get specific price list item"""
|
||||
logger.info(
|
||||
"Getting supplier price list item",
|
||||
price_list_id=str(price_list_id),
|
||||
tenant_id=str(tenant_id)
|
||||
)
|
||||
|
||||
return await self.repository.get_supplier_price_list(
|
||||
price_list_id=price_list_id,
|
||||
tenant_id=tenant_id
|
||||
)
|
||||
|
||||
async def create_supplier_price_list(
|
||||
self,
|
||||
supplier_id: UUID,
|
||||
price_list_data: SupplierPriceListCreate,
|
||||
tenant_id: UUID,
|
||||
created_by: UUID
|
||||
) -> Any:
|
||||
"""Create a new price list item for a supplier"""
|
||||
logger.info(
|
||||
"Creating supplier price list item",
|
||||
supplier_id=str(supplier_id),
|
||||
tenant_id=str(tenant_id)
|
||||
)
|
||||
|
||||
# Prepare creation data
|
||||
create_data = price_list_data.model_dump(exclude_unset=True)
|
||||
create_data.update({
|
||||
'tenant_id': tenant_id,
|
||||
'supplier_id': supplier_id,
|
||||
'created_by': created_by,
|
||||
'updated_by': created_by,
|
||||
})
|
||||
|
||||
# Calculate price_per_unit if not provided
|
||||
if 'price_per_unit' not in create_data or create_data['price_per_unit'] is None:
|
||||
create_data['price_per_unit'] = create_data['unit_price']
|
||||
|
||||
price_list = await self.repository.create_supplier_price_list(create_data)
|
||||
|
||||
logger.info(
|
||||
"Supplier price list item created successfully",
|
||||
price_list_id=str(price_list.id),
|
||||
supplier_id=str(supplier_id)
|
||||
)
|
||||
|
||||
return price_list
|
||||
|
||||
async def update_supplier_price_list(
|
||||
self,
|
||||
price_list_id: UUID,
|
||||
price_list_data: SupplierPriceListUpdate,
|
||||
tenant_id: UUID,
|
||||
updated_by: UUID
|
||||
) -> Any:
|
||||
"""Update a price list item"""
|
||||
logger.info(
|
||||
"Updating supplier price list item",
|
||||
price_list_id=str(price_list_id),
|
||||
tenant_id=str(tenant_id)
|
||||
)
|
||||
|
||||
# Prepare update data
|
||||
update_data = price_list_data.model_dump(exclude_unset=True)
|
||||
update_data['updated_by'] = updated_by
|
||||
update_data['updated_at'] = datetime.now()
|
||||
|
||||
price_list = await self.repository.update_supplier_price_list(
|
||||
price_list_id=price_list_id,
|
||||
update_data=update_data
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Supplier price list item updated successfully",
|
||||
price_list_id=str(price_list_id)
|
||||
)
|
||||
|
||||
return price_list
|
||||
|
||||
async def delete_supplier_price_list(
|
||||
self,
|
||||
price_list_id: UUID,
|
||||
tenant_id: UUID
|
||||
) -> bool:
|
||||
"""Delete a price list item"""
|
||||
logger.info(
|
||||
"Deleting supplier price list item",
|
||||
price_list_id=str(price_list_id),
|
||||
tenant_id=str(tenant_id)
|
||||
)
|
||||
|
||||
success = await self.repository.delete_supplier_price_list(
|
||||
price_list_id=price_list_id
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Supplier price list item deletion completed",
|
||||
price_list_id=str(price_list_id),
|
||||
success=success
|
||||
)
|
||||
|
||||
return success
|
||||
|
||||
Reference in New Issue
Block a user