2025-05-23 15:56:11 +02:00
|
|
|
import re
|
2025-05-27 17:07:55 +02:00
|
|
|
|
|
|
|
from django.shortcuts import render
|
2025-05-23 15:56:11 +02:00
|
|
|
from collections import defaultdict
|
2025-07-07 14:30:05 +02:00
|
|
|
from hub.services.models.pricing import (
|
|
|
|
ComputePlan,
|
|
|
|
StoragePlan,
|
|
|
|
ExternalPricePlans,
|
|
|
|
VSHNAppCatPrice,
|
|
|
|
)
|
2025-05-26 15:03:39 +02:00
|
|
|
from django.contrib.admin.views.decorators import staff_member_required
|
2025-05-27 17:07:55 +02:00
|
|
|
from django.db import models
|
2025-05-23 15:56:11 +02:00
|
|
|
|
|
|
|
|
2025-06-20 16:20:04 +02:00
|
|
|
def natural_sort_key(obj):
|
|
|
|
"""Extract numeric parts for natural sorting (works for any plan name)"""
|
2025-07-07 14:30:05 +02:00
|
|
|
name = obj.name if hasattr(obj, "name") else str(obj)
|
2025-06-20 16:20:04 +02:00
|
|
|
parts = re.split(r"(\d+)", name)
|
|
|
|
return [int(part) if part.isdigit() else part for part in parts]
|
2025-05-22 16:34:15 +02:00
|
|
|
|
|
|
|
|
2025-05-27 17:07:55 +02:00
|
|
|
def get_external_price_comparisons(plan, appcat_price, currency, service_level):
|
|
|
|
"""Get external price comparisons for a specific compute plan and service"""
|
|
|
|
try:
|
2025-05-30 13:36:09 +02:00
|
|
|
# Filter by service level if external price has one set, ignore currency for comparison
|
2025-05-27 17:07:55 +02:00
|
|
|
external_prices = ExternalPricePlans.objects.filter(
|
2025-05-30 13:36:09 +02:00
|
|
|
compare_to=plan, service=appcat_price.service
|
2025-05-27 17:07:55 +02:00
|
|
|
).select_related("cloud_provider")
|
|
|
|
|
|
|
|
# Filter by service level if the external price has it configured
|
|
|
|
if service_level:
|
|
|
|
external_prices = external_prices.filter(
|
|
|
|
models.Q(service_level=service_level)
|
|
|
|
| models.Q(service_level__isnull=True)
|
|
|
|
)
|
|
|
|
|
|
|
|
return external_prices
|
|
|
|
except Exception:
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2025-06-20 14:20:28 +02:00
|
|
|
def get_internal_cloud_provider_comparisons(
|
|
|
|
plan, appcat_price, currency, service_level
|
|
|
|
):
|
|
|
|
"""Get internal comparisons with other cloud provider plans from the database"""
|
|
|
|
try:
|
|
|
|
# Get similar compute plans from other cloud providers with same specs
|
|
|
|
similar_plans = (
|
|
|
|
ComputePlan.objects.filter(
|
|
|
|
active=True,
|
|
|
|
vcpus=plan.vcpus,
|
|
|
|
ram=plan.ram,
|
|
|
|
)
|
|
|
|
.exclude(cloud_provider=plan.cloud_provider) # Exclude same cloud provider
|
|
|
|
.select_related("cloud_provider")
|
|
|
|
.prefetch_related("prices")
|
|
|
|
)
|
|
|
|
|
|
|
|
internal_comparisons = []
|
|
|
|
|
|
|
|
for similar_plan in similar_plans:
|
|
|
|
# Get pricing components for comparison plan
|
|
|
|
compare_plan_price = similar_plan.get_price(currency)
|
2025-06-20 15:39:26 +02:00
|
|
|
compare_base_fee = appcat_price.get_base_fee(currency, service_level)
|
2025-06-20 14:20:28 +02:00
|
|
|
compare_unit_rate = appcat_price.get_unit_rate(currency, service_level)
|
|
|
|
|
|
|
|
# Skip if any pricing component is missing
|
|
|
|
if any(
|
|
|
|
price is None
|
|
|
|
for price in [compare_plan_price, compare_base_fee, compare_unit_rate]
|
|
|
|
):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Calculate units based on variable unit type
|
|
|
|
if appcat_price.variable_unit == VSHNAppCatPrice.VariableUnit.RAM:
|
|
|
|
units = int(similar_plan.ram)
|
|
|
|
elif appcat_price.variable_unit == VSHNAppCatPrice.VariableUnit.CPU:
|
|
|
|
units = int(similar_plan.vcpus)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Calculate replica enforcement based on service level
|
|
|
|
if service_level == VSHNAppCatPrice.ServiceLevel.GUARANTEED:
|
|
|
|
replica_enforce = appcat_price.ha_replica_min
|
|
|
|
else:
|
|
|
|
replica_enforce = 1
|
|
|
|
|
|
|
|
total_units = units * replica_enforce
|
|
|
|
|
|
|
|
# Calculate final price using the same logic as the main plan
|
|
|
|
price_calculation = appcat_price.calculate_final_price(
|
|
|
|
currency_code=currency,
|
|
|
|
service_level=service_level,
|
|
|
|
number_of_units=total_units,
|
|
|
|
addon_ids=None, # Include only mandatory addons
|
|
|
|
)
|
|
|
|
|
|
|
|
if price_calculation is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
service_price_with_addons = price_calculation["total_price"]
|
|
|
|
compare_final_price = compare_plan_price + service_price_with_addons
|
|
|
|
|
|
|
|
internal_comparisons.append(
|
|
|
|
{
|
|
|
|
"plan_name": similar_plan.name,
|
|
|
|
"provider": similar_plan.cloud_provider.name,
|
|
|
|
"compute_plan_price": compare_plan_price,
|
|
|
|
"service_price": service_price_with_addons,
|
|
|
|
"final_price": compare_final_price,
|
|
|
|
"currency": currency,
|
|
|
|
"vcpus": similar_plan.vcpus,
|
|
|
|
"ram": similar_plan.ram,
|
|
|
|
"group_name": (
|
|
|
|
similar_plan.group.name if similar_plan.group else "No Group"
|
|
|
|
),
|
|
|
|
"is_internal": True, # Flag to distinguish from external comparisons
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return internal_comparisons
|
|
|
|
except Exception:
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2025-05-26 15:03:39 +02:00
|
|
|
@staff_member_required
|
2025-05-23 08:49:08 +02:00
|
|
|
def pricelist(request):
|
2025-06-20 15:53:57 +02:00
|
|
|
"""Generate comprehensive price list grouped by compute plan groups and service levels (optimized)"""
|
2025-05-26 15:36:20 +02:00
|
|
|
# Get filter parameters from request
|
2025-05-23 17:12:05 +02:00
|
|
|
show_discount_details = request.GET.get("discount_details", "").lower() == "true"
|
2025-06-19 16:19:59 +02:00
|
|
|
show_addon_details = request.GET.get("addon_details", "").lower() == "true"
|
2025-05-27 17:07:55 +02:00
|
|
|
show_price_comparison = request.GET.get("price_comparison", "").lower() == "true"
|
2025-05-26 15:36:20 +02:00
|
|
|
filter_cloud_provider = request.GET.get("cloud_provider", "")
|
|
|
|
filter_service = request.GET.get("service", "")
|
|
|
|
filter_compute_plan_group = request.GET.get("compute_plan_group", "")
|
|
|
|
filter_service_level = request.GET.get("service_level", "")
|
2025-05-23 17:12:05 +02:00
|
|
|
|
2025-07-07 14:30:05 +02:00
|
|
|
# Get filter options for dropdowns first (needed for initial page load)
|
|
|
|
all_cloud_providers = (
|
|
|
|
ComputePlan.objects.all()
|
|
|
|
.values_list("cloud_provider__name", flat=True)
|
|
|
|
.distinct()
|
|
|
|
.order_by("cloud_provider__name")
|
|
|
|
)
|
|
|
|
all_services = (
|
|
|
|
VSHNAppCatPrice.objects.values_list("service__name", flat=True)
|
|
|
|
.distinct()
|
|
|
|
.order_by("service__name")
|
|
|
|
)
|
|
|
|
all_compute_plan_groups = list(
|
|
|
|
ComputePlan.objects.filter(group__isnull=False)
|
|
|
|
.values_list("group__name", flat=True)
|
|
|
|
.distinct()
|
|
|
|
.order_by("group__name")
|
|
|
|
)
|
|
|
|
all_compute_plan_groups.append("No Group") # Add option for plans without groups
|
|
|
|
all_service_levels = [choice[1] for choice in VSHNAppCatPrice.ServiceLevel.choices]
|
|
|
|
|
|
|
|
# Only process pricing data if both cloud provider and service are selected
|
|
|
|
if not filter_cloud_provider or not filter_service:
|
|
|
|
context = {
|
|
|
|
"pricing_data_by_group_and_service_level": {},
|
|
|
|
"show_discount_details": show_discount_details,
|
|
|
|
"show_addon_details": show_addon_details,
|
|
|
|
"show_price_comparison": show_price_comparison,
|
|
|
|
"filter_cloud_provider": filter_cloud_provider,
|
|
|
|
"filter_service": filter_service,
|
|
|
|
"filter_compute_plan_group": filter_compute_plan_group,
|
|
|
|
"filter_service_level": filter_service_level,
|
|
|
|
"all_cloud_providers": all_cloud_providers,
|
|
|
|
"all_services": all_services,
|
|
|
|
"all_compute_plan_groups": all_compute_plan_groups,
|
|
|
|
"all_service_levels": all_service_levels,
|
|
|
|
"show_empty_state": True, # Flag to show empty state message
|
|
|
|
}
|
|
|
|
return render(request, "services/pricelist.html", context)
|
|
|
|
|
2025-06-20 15:59:16 +02:00
|
|
|
# Fetch all compute plans (active and inactive) with related data
|
|
|
|
compute_plans_qs = ComputePlan.objects.all()
|
2025-05-26 15:36:20 +02:00
|
|
|
if filter_cloud_provider:
|
2025-07-07 14:30:05 +02:00
|
|
|
compute_plans_qs = compute_plans_qs.filter(
|
|
|
|
cloud_provider__name=filter_cloud_provider
|
|
|
|
)
|
2025-05-26 15:36:20 +02:00
|
|
|
if filter_compute_plan_group:
|
|
|
|
if filter_compute_plan_group == "No Group":
|
2025-06-20 15:53:57 +02:00
|
|
|
compute_plans_qs = compute_plans_qs.filter(group__isnull=True)
|
2025-05-26 15:36:20 +02:00
|
|
|
else:
|
2025-07-07 14:30:05 +02:00
|
|
|
compute_plans_qs = compute_plans_qs.filter(
|
|
|
|
group__name=filter_compute_plan_group
|
|
|
|
)
|
2025-06-20 15:53:57 +02:00
|
|
|
compute_plans = list(
|
2025-07-07 14:30:05 +02:00
|
|
|
compute_plans_qs.select_related("cloud_provider", "group")
|
2025-06-20 15:53:57 +02:00
|
|
|
.prefetch_related("prices")
|
|
|
|
.order_by("group__order", "group__name", "cloud_provider__name", "name")
|
2025-05-22 16:34:15 +02:00
|
|
|
)
|
2025-06-20 16:04:27 +02:00
|
|
|
# Restore natural sorting of compute plan names
|
|
|
|
compute_plans = sorted(
|
|
|
|
compute_plans,
|
|
|
|
key=lambda p: (
|
|
|
|
p.group.order if p.group else 999,
|
|
|
|
p.group.name if p.group else "ZZZ",
|
2025-06-20 16:20:04 +02:00
|
|
|
natural_sort_key(p),
|
2025-06-20 16:04:27 +02:00
|
|
|
),
|
|
|
|
)
|
2025-05-23 15:56:11 +02:00
|
|
|
|
2025-06-20 15:53:57 +02:00
|
|
|
# Fetch all appcat price configurations (prefetch addons)
|
|
|
|
appcat_prices_qs = (
|
2025-05-22 16:34:15 +02:00
|
|
|
VSHNAppCatPrice.objects.all()
|
2025-05-23 08:49:08 +02:00
|
|
|
.select_related("service", "discount_model")
|
2025-06-20 15:53:57 +02:00
|
|
|
.prefetch_related("base_fees", "unit_rates", "discount_model__tiers", "addons")
|
2025-05-23 15:56:11 +02:00
|
|
|
.order_by("service__name")
|
2025-05-22 16:34:15 +02:00
|
|
|
)
|
2025-05-26 15:36:20 +02:00
|
|
|
if filter_service:
|
2025-06-20 15:53:57 +02:00
|
|
|
appcat_prices_qs = appcat_prices_qs.filter(service__name=filter_service)
|
|
|
|
appcat_prices = list(appcat_prices_qs)
|
|
|
|
|
|
|
|
# Prefetch all storage plans for all cloud providers and build a lookup
|
|
|
|
all_storage_plans = StoragePlan.objects.all().prefetch_related("prices")
|
|
|
|
storage_plans_by_provider = defaultdict(list)
|
|
|
|
for sp in all_storage_plans:
|
|
|
|
storage_plans_by_provider[sp.cloud_provider_id].append(sp)
|
2025-05-26 15:36:20 +02:00
|
|
|
|
2025-05-23 17:09:02 +02:00
|
|
|
pricing_data_by_group_and_service_level = defaultdict(lambda: defaultdict(list))
|
2025-05-23 15:56:11 +02:00
|
|
|
processed_combinations = set()
|
2025-05-22 16:34:15 +02:00
|
|
|
|
2025-05-23 17:09:02 +02:00
|
|
|
# Generate pricing combinations for each compute plan and service
|
2025-05-22 16:34:15 +02:00
|
|
|
for plan in compute_plans:
|
2025-05-23 15:56:11 +02:00
|
|
|
plan_currencies = set(plan.prices.values_list("currency", flat=True))
|
|
|
|
for appcat_price in appcat_prices:
|
2025-05-23 17:09:02 +02:00
|
|
|
# Determine units based on variable unit type
|
2025-05-23 15:56:11 +02:00
|
|
|
if appcat_price.variable_unit == VSHNAppCatPrice.VariableUnit.RAM:
|
2025-05-22 16:34:15 +02:00
|
|
|
units = int(plan.ram)
|
2025-05-23 15:56:11 +02:00
|
|
|
elif appcat_price.variable_unit == VSHNAppCatPrice.VariableUnit.CPU:
|
2025-05-22 16:34:15 +02:00
|
|
|
units = int(plan.vcpus)
|
|
|
|
else:
|
2025-05-23 15:56:11 +02:00
|
|
|
continue
|
2025-07-07 14:30:05 +02:00
|
|
|
base_fee_currencies = set(
|
|
|
|
appcat_price.base_fees.values_list("currency", flat=True)
|
|
|
|
)
|
|
|
|
service_levels = appcat_price.unit_rates.values_list(
|
|
|
|
"service_level", flat=True
|
|
|
|
).distinct()
|
2025-05-26 15:36:20 +02:00
|
|
|
# Apply service level filter
|
|
|
|
if filter_service_level:
|
|
|
|
service_levels = [
|
2025-07-07 14:30:05 +02:00
|
|
|
sl
|
|
|
|
for sl in service_levels
|
|
|
|
if dict(VSHNAppCatPrice.ServiceLevel.choices)[sl]
|
|
|
|
== filter_service_level
|
2025-05-26 15:36:20 +02:00
|
|
|
]
|
2025-05-22 16:34:15 +02:00
|
|
|
for service_level in service_levels:
|
2025-05-23 15:56:11 +02:00
|
|
|
unit_rate_currencies = set(
|
2025-07-07 14:30:05 +02:00
|
|
|
appcat_price.unit_rates.filter(
|
|
|
|
service_level=service_level
|
|
|
|
).values_list("currency", flat=True)
|
2025-05-23 15:56:11 +02:00
|
|
|
)
|
2025-05-23 17:09:02 +02:00
|
|
|
# Find currencies that exist across all pricing components
|
2025-07-07 14:30:05 +02:00
|
|
|
matching_currencies = plan_currencies.intersection(
|
|
|
|
base_fee_currencies
|
|
|
|
).intersection(unit_rate_currencies)
|
2025-05-23 15:56:11 +02:00
|
|
|
if not matching_currencies:
|
|
|
|
continue
|
|
|
|
for currency in matching_currencies:
|
|
|
|
combination_key = (
|
|
|
|
plan.cloud_provider.name,
|
|
|
|
plan.name,
|
|
|
|
appcat_price.service.name,
|
|
|
|
service_level,
|
|
|
|
currency,
|
2025-05-22 16:34:15 +02:00
|
|
|
)
|
2025-05-23 15:56:11 +02:00
|
|
|
if combination_key in processed_combinations:
|
|
|
|
continue
|
|
|
|
processed_combinations.add(combination_key)
|
2025-05-23 17:09:02 +02:00
|
|
|
# Get pricing components
|
2025-05-23 15:56:11 +02:00
|
|
|
compute_plan_price = plan.get_price(currency)
|
2025-06-20 15:39:26 +02:00
|
|
|
base_fee = appcat_price.get_base_fee(currency, service_level)
|
2025-05-23 15:56:11 +02:00
|
|
|
unit_rate = appcat_price.get_unit_rate(currency, service_level)
|
2025-07-07 14:30:05 +02:00
|
|
|
if any(
|
|
|
|
price is None
|
|
|
|
for price in [compute_plan_price, base_fee, unit_rate]
|
|
|
|
):
|
2025-05-23 15:56:11 +02:00
|
|
|
continue
|
2025-05-23 17:09:02 +02:00
|
|
|
# Calculate replica enforcement based on service level
|
2025-05-23 15:56:11 +02:00
|
|
|
if service_level == VSHNAppCatPrice.ServiceLevel.GUARANTEED:
|
|
|
|
replica_enforce = appcat_price.ha_replica_min
|
|
|
|
else:
|
|
|
|
replica_enforce = 1
|
|
|
|
total_units = units * replica_enforce
|
2025-05-23 16:37:03 +02:00
|
|
|
standard_sla_price = base_fee + (total_units * unit_rate)
|
2025-05-23 17:09:02 +02:00
|
|
|
# Apply discount if available
|
2025-05-23 16:37:03 +02:00
|
|
|
discount_breakdown = None
|
2025-07-07 14:30:05 +02:00
|
|
|
if (
|
|
|
|
appcat_price.discount_model
|
|
|
|
and appcat_price.discount_model.active
|
|
|
|
):
|
|
|
|
discounted_price = (
|
|
|
|
appcat_price.discount_model.calculate_discount(
|
|
|
|
unit_rate, total_units
|
|
|
|
)
|
|
|
|
)
|
2025-05-23 15:56:11 +02:00
|
|
|
sla_price = base_fee + discounted_price
|
2025-05-23 16:37:03 +02:00
|
|
|
discount_savings = standard_sla_price - sla_price
|
2025-07-07 14:30:05 +02:00
|
|
|
discount_percentage = (
|
|
|
|
(discount_savings / standard_sla_price) * 100
|
|
|
|
if standard_sla_price > 0
|
|
|
|
else 0
|
|
|
|
)
|
|
|
|
discount_breakdown = (
|
|
|
|
appcat_price.discount_model.get_discount_breakdown(
|
|
|
|
unit_rate, total_units
|
|
|
|
)
|
|
|
|
)
|
2025-05-23 15:56:11 +02:00
|
|
|
else:
|
2025-05-23 16:37:03 +02:00
|
|
|
sla_price = standard_sla_price
|
|
|
|
discounted_price = total_units * unit_rate
|
|
|
|
discount_savings = 0
|
|
|
|
discount_percentage = 0
|
2025-06-20 08:57:05 +02:00
|
|
|
# Calculate final price using the model method to ensure consistency
|
|
|
|
price_calculation = appcat_price.calculate_final_price(
|
|
|
|
currency_code=currency,
|
|
|
|
service_level=service_level,
|
|
|
|
number_of_units=total_units,
|
|
|
|
addon_ids=None, # This will include only mandatory addons
|
|
|
|
)
|
|
|
|
if price_calculation is None:
|
|
|
|
continue
|
|
|
|
# Calculate base service price (without addons) for display purposes
|
|
|
|
base_sla_price = base_fee + (total_units * unit_rate)
|
2025-06-20 15:53:57 +02:00
|
|
|
# Extract addon information from the calculation (use prefetched addons)
|
2025-06-19 16:19:59 +02:00
|
|
|
mandatory_addons = []
|
|
|
|
optional_addons = []
|
2025-06-20 15:53:57 +02:00
|
|
|
all_addons = [a for a in appcat_price.addons.all() if a.active]
|
2025-06-20 08:57:05 +02:00
|
|
|
for addon in all_addons:
|
2025-06-19 16:19:59 +02:00
|
|
|
addon_price = None
|
|
|
|
if addon.addon_type == "BF": # Base Fee
|
2025-06-20 15:39:26 +02:00
|
|
|
addon_price = addon.get_price(currency, service_level)
|
2025-06-19 16:19:59 +02:00
|
|
|
elif addon.addon_type == "UR": # Unit Rate
|
2025-07-07 14:30:05 +02:00
|
|
|
addon_price_per_unit = addon.get_price(
|
|
|
|
currency, service_level
|
|
|
|
)
|
2025-06-19 16:19:59 +02:00
|
|
|
if addon_price_per_unit:
|
|
|
|
addon_price = addon_price_per_unit * total_units
|
|
|
|
addon_info = {
|
|
|
|
"id": addon.id,
|
|
|
|
"name": addon.name,
|
|
|
|
"description": addon.description,
|
|
|
|
"commercial_description": addon.commercial_description,
|
|
|
|
"addon_type": addon.get_addon_type_display(),
|
|
|
|
"price": addon_price,
|
|
|
|
}
|
|
|
|
if addon.mandatory:
|
|
|
|
mandatory_addons.append(addon_info)
|
|
|
|
else:
|
|
|
|
optional_addons.append(addon_info)
|
2025-06-20 08:57:05 +02:00
|
|
|
service_price_with_addons = price_calculation["total_price"]
|
|
|
|
final_price = compute_plan_price + service_price_with_addons
|
2025-07-07 14:30:05 +02:00
|
|
|
service_level_display = dict(
|
|
|
|
VSHNAppCatPrice.ServiceLevel.choices
|
|
|
|
).get(service_level, service_level)
|
2025-06-20 15:53:57 +02:00
|
|
|
# Get external/internal price comparisons if enabled (unchanged, but could be optimized further)
|
2025-05-27 17:07:55 +02:00
|
|
|
external_comparisons = []
|
2025-06-20 14:20:28 +02:00
|
|
|
internal_comparisons = []
|
2025-05-27 17:07:55 +02:00
|
|
|
if show_price_comparison:
|
2025-07-07 14:30:05 +02:00
|
|
|
external_prices = get_external_price_comparisons(
|
|
|
|
plan, appcat_price, currency, service_level
|
|
|
|
)
|
2025-05-27 17:07:55 +02:00
|
|
|
for ext_price in external_prices:
|
2025-05-30 13:36:09 +02:00
|
|
|
difference = ext_price.amount - final_price
|
2025-07-07 14:30:05 +02:00
|
|
|
ratio = (
|
|
|
|
ext_price.amount / final_price if final_price > 0 else 0
|
|
|
|
)
|
|
|
|
external_comparisons.append(
|
|
|
|
{
|
|
|
|
"plan_name": ext_price.plan_name,
|
|
|
|
"provider": ext_price.cloud_provider.name,
|
|
|
|
"description": ext_price.description,
|
|
|
|
"amount": ext_price.amount,
|
|
|
|
"currency": ext_price.currency,
|
|
|
|
"vcpus": ext_price.vcpus,
|
|
|
|
"ram": ext_price.ram,
|
|
|
|
"storage": ext_price.storage,
|
|
|
|
"replicas": ext_price.replicas,
|
|
|
|
"difference": difference,
|
|
|
|
"ratio": ratio,
|
|
|
|
"source": ext_price.source,
|
|
|
|
"date_retrieved": ext_price.date_retrieved,
|
|
|
|
"is_internal": False,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
internal_price_comparisons = (
|
|
|
|
get_internal_cloud_provider_comparisons(
|
|
|
|
plan, appcat_price, currency, service_level
|
|
|
|
)
|
|
|
|
)
|
2025-06-20 14:20:28 +02:00
|
|
|
for int_price in internal_price_comparisons:
|
|
|
|
difference = int_price["final_price"] - final_price
|
2025-07-07 14:30:05 +02:00
|
|
|
ratio = (
|
|
|
|
int_price["final_price"] / final_price
|
|
|
|
if final_price > 0
|
|
|
|
else 0
|
|
|
|
)
|
|
|
|
internal_comparisons.append(
|
|
|
|
{
|
|
|
|
"plan_name": int_price["plan_name"],
|
|
|
|
"provider": int_price["provider"],
|
|
|
|
"description": f"Same specs with {int_price['provider']}",
|
|
|
|
"amount": int_price["final_price"],
|
|
|
|
"currency": int_price["currency"],
|
|
|
|
"vcpus": int_price["vcpus"],
|
|
|
|
"ram": int_price["ram"],
|
|
|
|
"group_name": int_price["group_name"],
|
|
|
|
"compute_plan_price": int_price[
|
|
|
|
"compute_plan_price"
|
|
|
|
],
|
|
|
|
"service_price": int_price["service_price"],
|
|
|
|
"difference": difference,
|
|
|
|
"ratio": ratio,
|
|
|
|
"is_internal": True,
|
|
|
|
}
|
|
|
|
)
|
2025-05-23 17:09:02 +02:00
|
|
|
group_name = plan.group.name if plan.group else "No Group"
|
2025-06-20 15:53:57 +02:00
|
|
|
# Use prefetched storage plans
|
2025-07-07 14:30:05 +02:00
|
|
|
storage_plans = storage_plans_by_provider.get(
|
|
|
|
plan.cloud_provider_id, []
|
|
|
|
)
|
|
|
|
pricing_data_by_group_and_service_level[group_name][
|
|
|
|
service_level_display
|
|
|
|
].append(
|
|
|
|
{
|
|
|
|
"cloud_provider": plan.cloud_provider.name,
|
|
|
|
"service": appcat_price.service.name,
|
|
|
|
"compute_plan": plan.name,
|
|
|
|
"compute_plan_group": group_name,
|
|
|
|
"compute_plan_group_description": (
|
|
|
|
plan.group.description if plan.group else ""
|
|
|
|
),
|
|
|
|
"compute_plan_group_node_label": (
|
|
|
|
plan.group.node_label if plan.group else ""
|
|
|
|
),
|
|
|
|
"storage_plans": storage_plans,
|
|
|
|
"vcpus": plan.vcpus,
|
|
|
|
"ram": plan.ram,
|
|
|
|
"cpu_mem_ratio": plan.cpu_mem_ratio,
|
|
|
|
"term": plan.get_term_display(),
|
|
|
|
"currency": currency,
|
|
|
|
"compute_plan_price": compute_plan_price,
|
|
|
|
"variable_unit": appcat_price.get_variable_unit_display(),
|
|
|
|
"units": units,
|
|
|
|
"replica_enforce": replica_enforce,
|
|
|
|
"total_units": total_units,
|
|
|
|
"service_level": service_level_display,
|
|
|
|
"sla_base": base_fee,
|
|
|
|
"sla_per_unit": unit_rate,
|
|
|
|
"sla_price": service_price_with_addons,
|
|
|
|
"standard_sla_price": base_sla_price,
|
|
|
|
"discounted_sla_price": (
|
|
|
|
base_fee + discounted_price
|
|
|
|
if appcat_price.discount_model
|
|
|
|
and appcat_price.discount_model.active
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
"discount_savings": discount_savings,
|
|
|
|
"discount_percentage": discount_percentage,
|
|
|
|
"discount_breakdown": discount_breakdown,
|
|
|
|
"final_price": final_price,
|
|
|
|
"discount_model": (
|
|
|
|
appcat_price.discount_model.name
|
|
|
|
if appcat_price.discount_model
|
|
|
|
else None
|
|
|
|
),
|
|
|
|
"has_discount": bool(
|
|
|
|
appcat_price.discount_model
|
|
|
|
and appcat_price.discount_model.active
|
|
|
|
),
|
|
|
|
"external_comparisons": external_comparisons,
|
|
|
|
"internal_comparisons": internal_comparisons,
|
|
|
|
"mandatory_addons": mandatory_addons,
|
|
|
|
"optional_addons": optional_addons,
|
|
|
|
"is_active": plan.active,
|
|
|
|
}
|
|
|
|
)
|
2025-05-23 17:09:02 +02:00
|
|
|
# Order groups correctly, placing "No Group" last
|
|
|
|
ordered_groups_intermediate = {}
|
|
|
|
all_group_names = list(pricing_data_by_group_and_service_level.keys())
|
|
|
|
if "No Group" in all_group_names:
|
|
|
|
all_group_names.remove("No Group")
|
|
|
|
all_group_names.append("No Group")
|
|
|
|
for group_name_key in all_group_names:
|
2025-07-07 14:30:05 +02:00
|
|
|
ordered_groups_intermediate[group_name_key] = (
|
|
|
|
pricing_data_by_group_and_service_level[group_name_key]
|
|
|
|
)
|
2025-05-23 17:09:02 +02:00
|
|
|
# Convert defaultdicts to regular dicts for the template
|
|
|
|
final_context_data = {}
|
|
|
|
for group_key, service_levels_dict in ordered_groups_intermediate.items():
|
|
|
|
final_context_data[group_key] = {
|
|
|
|
sl_key: list(plans_list)
|
|
|
|
for sl_key, plans_list in service_levels_dict.items()
|
|
|
|
}
|
2025-06-20 15:59:16 +02:00
|
|
|
# Get filter options for dropdowns (include all providers/groups from all plans, not just active)
|
2025-05-26 15:36:20 +02:00
|
|
|
all_cloud_providers = (
|
2025-06-20 15:59:16 +02:00
|
|
|
ComputePlan.objects.all()
|
2025-05-26 15:36:20 +02:00
|
|
|
.values_list("cloud_provider__name", flat=True)
|
|
|
|
.distinct()
|
|
|
|
.order_by("cloud_provider__name")
|
|
|
|
)
|
|
|
|
all_services = (
|
|
|
|
VSHNAppCatPrice.objects.values_list("service__name", flat=True)
|
|
|
|
.distinct()
|
|
|
|
.order_by("service__name")
|
|
|
|
)
|
|
|
|
all_compute_plan_groups = list(
|
2025-06-20 15:59:16 +02:00
|
|
|
ComputePlan.objects.filter(group__isnull=False)
|
2025-05-26 15:36:20 +02:00
|
|
|
.values_list("group__name", flat=True)
|
|
|
|
.distinct()
|
|
|
|
.order_by("group__name")
|
|
|
|
)
|
|
|
|
all_compute_plan_groups.append("No Group") # Add option for plans without groups
|
|
|
|
all_service_levels = [choice[1] for choice in VSHNAppCatPrice.ServiceLevel.choices]
|
2025-07-07 14:30:05 +02:00
|
|
|
|
2025-05-23 17:12:05 +02:00
|
|
|
context = {
|
|
|
|
"pricing_data_by_group_and_service_level": final_context_data,
|
|
|
|
"show_discount_details": show_discount_details,
|
2025-06-19 16:19:59 +02:00
|
|
|
"show_addon_details": show_addon_details,
|
2025-05-27 17:07:55 +02:00
|
|
|
"show_price_comparison": show_price_comparison,
|
2025-05-26 15:36:20 +02:00
|
|
|
"filter_cloud_provider": filter_cloud_provider,
|
|
|
|
"filter_service": filter_service,
|
|
|
|
"filter_compute_plan_group": filter_compute_plan_group,
|
|
|
|
"filter_service_level": filter_service_level,
|
|
|
|
"all_cloud_providers": all_cloud_providers,
|
|
|
|
"all_services": all_services,
|
|
|
|
"all_compute_plan_groups": all_compute_plan_groups,
|
|
|
|
"all_service_levels": all_service_levels,
|
2025-05-23 17:12:05 +02:00
|
|
|
}
|
2025-05-22 16:34:15 +02:00
|
|
|
return render(request, "services/pricelist.html", context)
|