osb catalog
This commit is contained in:
parent
81e55a2134
commit
ff4eb0a9ba
2 changed files with 89 additions and 1 deletions
|
@ -6,7 +6,7 @@ from django.shortcuts import get_object_or_404
|
|||
from hub.services.models import ServiceOffering, Lead
|
||||
from hub.services.odoo import OdooAPI
|
||||
from .models import ServiceInstance, ServiceBrokerUser
|
||||
from .serializers import ServiceInstanceProvisioningSerializer
|
||||
from .serializers import ServiceInstanceProvisioningSerializer, CatalogSerializer
|
||||
from .authentication import ServiceBrokerAuthentication
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -15,6 +15,26 @@ logger = logging.getLogger(__name__)
|
|||
class ServiceBrokerViewSet(viewsets.ViewSet):
|
||||
authentication_classes = [ServiceBrokerAuthentication]
|
||||
|
||||
@action(detail=False, methods=["get"], url_path="catalog")
|
||||
def get_catalog(self, request):
|
||||
"""
|
||||
Return the catalog of services available to the authenticated user.
|
||||
"""
|
||||
# Get broker user and their allowed offerings
|
||||
broker_user = get_object_or_404(ServiceBrokerUser, user=request.user)
|
||||
offerings = broker_user.allowed_offerings.prefetch_related(
|
||||
"plans",
|
||||
"plans__prices",
|
||||
"plans__prices__currency",
|
||||
"plans__prices__term",
|
||||
"service",
|
||||
"cloud_provider",
|
||||
).all()
|
||||
|
||||
# Serialize the catalog
|
||||
serializer = CatalogSerializer({"services": offerings})
|
||||
return Response(serializer.data)
|
||||
|
||||
def _create_lead_from_provision_data(self, offering, plan, parameters, context):
|
||||
"""Create a lead in Odoo from provisioning data"""
|
||||
# Get the first user from parameters as the main contact
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue