make creation and deletion work
This commit is contained in:
parent
4ae237e10a
commit
7c7f315e52
4 changed files with 28 additions and 5 deletions
|
@ -4,7 +4,19 @@ from .views import ServiceBrokerViewSet
|
|||
|
||||
app_name = "broker"
|
||||
|
||||
router = DefaultRouter(trailing_slash=False)
|
||||
|
||||
class ServiceBrokerRouter(DefaultRouter):
|
||||
def get_method_map(self, viewset, method_map):
|
||||
result = super().get_method_map(viewset, method_map)
|
||||
|
||||
# Add PUT method for provision_instance
|
||||
if hasattr(viewset, "provision_instance"):
|
||||
result.update({"put": "provision_instance"})
|
||||
|
||||
return result
|
||||
|
||||
|
||||
router = ServiceBrokerRouter(trailing_slash=False)
|
||||
router.register("v2", ServiceBrokerViewSet, basename="broker")
|
||||
|
||||
urlpatterns = [
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import logging
|
||||
from django.urls import reverse
|
||||
from django.conf import settings
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import action
|
||||
from django.shortcuts import get_object_or_404
|
||||
from hub.services.models import ServiceOffering, Lead
|
||||
from hub.services.models import Lead
|
||||
from hub.services.odoo import OdooAPI
|
||||
from .models import ServiceInstance, ServiceBrokerUser
|
||||
from .serializers import ServiceInstanceProvisioningSerializer, CatalogSerializer
|
||||
|
@ -52,7 +54,7 @@ class ServiceBrokerViewSet(viewsets.ViewSet):
|
|||
|
||||
try:
|
||||
odoo = OdooAPI()
|
||||
lead.odoo_lead_id = odoo.create_lead(lead)
|
||||
lead.odoo_lead_id = odoo.create_lead(lead, source="osbapi")
|
||||
lead.save()
|
||||
return lead
|
||||
except Exception as e:
|
||||
|
@ -110,7 +112,10 @@ class ServiceBrokerViewSet(viewsets.ViewSet):
|
|||
|
||||
return Response(
|
||||
{
|
||||
"dashboard_url": f"/services/{offering.service.slug}",
|
||||
"dashboard_url": settings.WEBSITE_URL
|
||||
+ reverse(
|
||||
"services:offering_detail", kwargs={"slug": offering.slug}
|
||||
),
|
||||
"operation": "provision",
|
||||
},
|
||||
status=status.HTTP_201_CREATED,
|
||||
|
|
|
@ -53,7 +53,7 @@ class OdooAPI:
|
|||
logger.debug("Full error details:", exc_info=True)
|
||||
raise
|
||||
|
||||
def create_lead(self, lead):
|
||||
def create_lead(self, lead, source="form"):
|
||||
"""Create a lead in Odoo"""
|
||||
try:
|
||||
logger.info(
|
||||
|
@ -74,6 +74,11 @@ class OdooAPI:
|
|||
if lead.plan:
|
||||
service_details.append(f"Plan: {lead.plan.name}")
|
||||
|
||||
if source == "form":
|
||||
service_details.append(f"Source: Servala Website")
|
||||
elif source == "osbapi":
|
||||
service_details.append(f"Source: OSB API")
|
||||
|
||||
# Prepare lead data
|
||||
lead_data = {
|
||||
"name": f"Servala - Interest in {lead.service.name}",
|
||||
|
|
|
@ -43,6 +43,7 @@ DEBUG = env.bool("DEBUG", default=False)
|
|||
|
||||
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
|
||||
CSRF_TRUSTED_ORIGINS = [f"https://{h}" for h in ALLOWED_HOSTS]
|
||||
WEBSITE_URL = env.str("WEBSITE_URL", default="https://poc.serva.la")
|
||||
|
||||
|
||||
# Application definition
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue