retrieve storage price from db

This commit is contained in:
Tobias Brunner 2025-06-04 17:06:32 +02:00
parent c8c224cfb8
commit 8bb8930361
No known key found for this signature in database
2 changed files with 45 additions and 4 deletions

View file

@ -1,6 +1,5 @@
import re
import yaml
import json
from decimal import Decimal
from django.shortcuts import render, get_object_or_404
@ -14,6 +13,7 @@ from hub.services.models import (
Service,
ComputePlan,
VSHNAppCatPrice,
StoragePlan,
)
from collections import defaultdict
from markdownify import markdownify
@ -239,6 +239,22 @@ def generate_pricing_data(offering):
),
)
# Fetch storage plans for this cloud provider
storage_plans = (
StoragePlan.objects.filter(cloud_provider=offering.cloud_provider)
.prefetch_related("prices")
.order_by("name")
)
# Get default storage pricing (use first available storage plan)
storage_price_data = {}
if storage_plans.exists():
default_storage_plan = storage_plans.first()
for currency in ["CHF", "EUR", "USD"]: # Add currencies as needed
price = default_storage_plan.get_price(currency)
if price is not None:
storage_price_data[currency] = price
# Fetch pricing for this specific service
try:
appcat_price = (
@ -352,6 +368,7 @@ def generate_pricing_data(offering):
"compute_plan_price": compute_plan_price,
"sla_price": sla_price,
"final_price": final_price,
"storage_price": storage_price_data.get(currency, 0),
}
)