add addons to services

This commit is contained in:
Tobias Brunner 2025-06-19 16:19:59 +02:00
parent b96b186875
commit 22e527bcd9
No known key found for this signature in database
8 changed files with 1039 additions and 4 deletions

View file

@ -367,6 +367,41 @@ def generate_pricing_data(offering):
else:
sla_price = standard_sla_price
# Get addons information
addons = appcat_price.addons.filter(active=True)
mandatory_addons = []
optional_addons = []
# Calculate additional price from mandatory addons
addon_total = 0
for addon in addons:
addon_price = None
if addon.addon_type == "BF": # Base Fee
addon_price = addon.get_price(currency)
elif addon.addon_type == "UR": # Unit Rate
addon_price_per_unit = addon.get_price(currency, service_level)
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)
if addon_price:
addon_total += addon_price
sla_price += addon_price
else:
optional_addons.append(addon_info)
final_price = compute_plan_price + sla_price
service_level_display = dict(VSHNAppCatPrice.ServiceLevel.choices)[
service_level
@ -393,6 +428,8 @@ def generate_pricing_data(offering):
"storage_price": storage_price_data.get(currency, 0),
"ha_replica_min": appcat_price.ha_replica_min,
"ha_replica_max": appcat_price.ha_replica_max,
"mandatory_addons": mandatory_addons,
"optional_addons": optional_addons,
}
)

View file

@ -43,6 +43,7 @@ def pricelist(request):
"""Generate comprehensive price list grouped by compute plan groups and service levels"""
# Get filter parameters from request
show_discount_details = request.GET.get("discount_details", "").lower() == "true"
show_addon_details = request.GET.get("addon_details", "").lower() == "true"
show_price_comparison = request.GET.get("price_comparison", "").lower() == "true"
filter_cloud_provider = request.GET.get("cloud_provider", "")
filter_service = request.GET.get("service", "")
@ -202,6 +203,40 @@ def pricelist(request):
discount_savings = 0
discount_percentage = 0
# Get addon information
addons = appcat_price.addons.filter(active=True)
mandatory_addons = []
optional_addons = []
# Group addons by mandatory vs optional
for addon in addons:
addon_price = None
if addon.addon_type == "BF": # Base Fee
addon_price = addon.get_price(currency)
elif addon.addon_type == "UR": # Unit Rate
addon_price_per_unit = addon.get_price(
currency, service_level
)
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)
if addon_price:
sla_price += addon_price
else:
optional_addons.append(addon_info)
final_price = compute_plan_price + sla_price
service_level_display = dict(VSHNAppCatPrice.ServiceLevel.choices)[
service_level
@ -296,6 +331,8 @@ def pricelist(request):
and appcat_price.discount_model.active
),
"external_comparisons": external_comparisons,
"mandatory_addons": mandatory_addons,
"optional_addons": optional_addons,
}
)
@ -344,6 +381,7 @@ def pricelist(request):
context = {
"pricing_data_by_group_and_service_level": final_context_data,
"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,