improved behaviour

This commit is contained in:
Tobias Brunner 2025-06-20 08:57:05 +02:00
parent 9d423ce61e
commit 3f3b9da992
No known key found for this signature in database
2 changed files with 164 additions and 40 deletions

View file

@ -203,13 +203,56 @@ def pricelist(request):
discount_savings = 0
discount_percentage = 0
# Get addon information
addons = appcat_price.addons.filter(active=True)
# 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)
# Apply discount if available
discount_breakdown = None
if (
appcat_price.discount_model
and appcat_price.discount_model.active
):
discounted_price = (
appcat_price.discount_model.calculate_discount(
unit_rate, total_units
)
)
sla_price = base_fee + discounted_price
discount_savings = base_sla_price - sla_price
discount_percentage = (
(discount_savings / base_sla_price) * 100
if base_sla_price > 0
else 0
)
discount_breakdown = (
appcat_price.discount_model.get_discount_breakdown(
unit_rate, total_units
)
)
else:
sla_price = base_sla_price
discounted_price = total_units * unit_rate
discount_savings = 0
discount_percentage = 0
# Extract addon information from the calculation
mandatory_addons = []
optional_addons = []
# Group addons by mandatory vs optional
for addon in addons:
# Get all addons to separate mandatory from optional
all_addons = appcat_price.addons.filter(active=True)
for addon in all_addons:
addon_price = None
if addon.addon_type == "BF": # Base Fee
@ -232,12 +275,12 @@ def pricelist(request):
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
# Use the calculated total price which includes mandatory addons
service_price_with_addons = price_calculation["total_price"]
final_price = compute_plan_price + service_price_with_addons
service_level_display = dict(VSHNAppCatPrice.ServiceLevel.choices)[
service_level
]
@ -309,8 +352,8 @@ def pricelist(request):
"service_level": service_level_display,
"sla_base": base_fee,
"sla_per_unit": unit_rate,
"sla_price": sla_price,
"standard_sla_price": standard_sla_price,
"sla_price": service_price_with_addons,
"standard_sla_price": base_sla_price,
"discounted_sla_price": (
base_fee + discounted_price
if appcat_price.discount_model