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,
}
)