continued work on price model
This commit is contained in:
parent
6f41c8c344
commit
a6a15150ea
10 changed files with 500 additions and 1 deletions
72
hub/services/views/pricelist.py
Normal file
72
hub/services/views/pricelist.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
from django.shortcuts import render
|
||||
from hub.services.models import ComputePlan, VSHNAppCatPrice, VSHNAppCatUnitRate
|
||||
|
||||
|
||||
def compute_plan_price_comparison(request):
|
||||
# Get all compute plans and app catalog prices
|
||||
compute_plans = (
|
||||
ComputePlan.objects.all()
|
||||
.select_related("cloud_provider")
|
||||
.prefetch_related("prices")
|
||||
)
|
||||
appcat_prices = (
|
||||
VSHNAppCatPrice.objects.all()
|
||||
.select_related("service")
|
||||
.prefetch_related("base_fees", "unit_rates")
|
||||
)
|
||||
|
||||
plans_data = []
|
||||
|
||||
for plan in compute_plans:
|
||||
plan_data = {"plan": plan, "calculated_prices": []}
|
||||
|
||||
for price_config in appcat_prices:
|
||||
# Get all service levels for this price config
|
||||
service_levels = (
|
||||
VSHNAppCatUnitRate.objects.filter(vshn_appcat_price_config=price_config)
|
||||
.values_list("service_level", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
|
||||
# Determine number of units based on variable_unit
|
||||
if price_config.variable_unit == VSHNAppCatPrice.VariableUnit.RAM:
|
||||
units = int(plan.ram)
|
||||
elif price_config.variable_unit == VSHNAppCatPrice.VariableUnit.CPU:
|
||||
units = int(plan.vcpus)
|
||||
else:
|
||||
continue # Skip other unit type as we don't know yet how to handle them
|
||||
|
||||
# Get all currencies used in base fees
|
||||
currencies = price_config.base_fees.values_list(
|
||||
"currency", flat=True
|
||||
).distinct()
|
||||
|
||||
# Calculate prices for all combinations
|
||||
for service_level in service_levels:
|
||||
for currency in currencies:
|
||||
final_price = price_config.calculate_final_price(
|
||||
currency_code=currency,
|
||||
service_level=service_level,
|
||||
number_of_units=units,
|
||||
)
|
||||
|
||||
if final_price is not None:
|
||||
service_level_display = dict(
|
||||
VSHNAppCatPrice.ServiceLevel.choices
|
||||
)[service_level]
|
||||
|
||||
plan_data["calculated_prices"].append(
|
||||
{
|
||||
"service": price_config.service.name,
|
||||
"variable_unit": price_config.get_variable_unit_display(),
|
||||
"service_level": service_level_display,
|
||||
"units": units,
|
||||
"currency": currency,
|
||||
"price": final_price,
|
||||
}
|
||||
)
|
||||
|
||||
plans_data.append(plan_data)
|
||||
|
||||
context = {"plans_data": plans_data}
|
||||
return render(request, "services/pricelist.html", context)
|
Loading…
Add table
Add a link
Reference in a new issue