pricelist internal plans comparison
This commit is contained in:
parent
4b515702e3
commit
15869ca542
2 changed files with 260 additions and 15 deletions
|
@ -38,6 +38,90 @@ def get_external_price_comparisons(plan, appcat_price, currency, service_level):
|
|||
return []
|
||||
|
||||
|
||||
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)
|
||||
compare_base_fee = appcat_price.get_base_fee(currency)
|
||||
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 []
|
||||
|
||||
|
||||
@staff_member_required
|
||||
def pricelist(request):
|
||||
"""Generate comprehensive price list grouped by compute plan groups and service levels"""
|
||||
|
@ -287,7 +371,9 @@ def pricelist(request):
|
|||
|
||||
# Get external price comparisons if enabled
|
||||
external_comparisons = []
|
||||
internal_comparisons = []
|
||||
if show_price_comparison:
|
||||
# Get external price comparisons
|
||||
external_prices = get_external_price_comparisons(
|
||||
plan, appcat_price, currency, service_level
|
||||
)
|
||||
|
@ -313,6 +399,42 @@ def pricelist(request):
|
|||
"ratio": ratio,
|
||||
"source": ext_price.source,
|
||||
"date_retrieved": ext_price.date_retrieved,
|
||||
"is_internal": False,
|
||||
}
|
||||
)
|
||||
|
||||
# Get internal cloud provider comparisons
|
||||
internal_price_comparisons = (
|
||||
get_internal_cloud_provider_comparisons(
|
||||
plan, appcat_price, currency, service_level
|
||||
)
|
||||
)
|
||||
for int_price in internal_price_comparisons:
|
||||
# Calculate price difference
|
||||
difference = int_price["final_price"] - final_price
|
||||
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,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -374,6 +496,7 @@ def pricelist(request):
|
|||
and appcat_price.discount_model.active
|
||||
),
|
||||
"external_comparisons": external_comparisons,
|
||||
"internal_comparisons": internal_comparisons,
|
||||
"mandatory_addons": mandatory_addons,
|
||||
"optional_addons": optional_addons,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue