retrieve storage price from db
This commit is contained in:
parent
c8c224cfb8
commit
8bb8930361
2 changed files with 45 additions and 4 deletions
|
@ -6,7 +6,7 @@
|
||||||
class PriceCalculator {
|
class PriceCalculator {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.pricingData = null;
|
this.pricingData = null;
|
||||||
this.storagePrice = 0.15; // CHF per GB per month
|
this.storagePrice = null;
|
||||||
this.currentOffering = null;
|
this.currentOffering = null;
|
||||||
this.selectedConfiguration = null;
|
this.selectedConfiguration = null;
|
||||||
this.init();
|
this.init();
|
||||||
|
@ -145,6 +145,10 @@ Please contact me with next steps for ordering this configuration.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pricingData = await response.json();
|
this.pricingData = await response.json();
|
||||||
|
|
||||||
|
// Extract storage price from the first available plan
|
||||||
|
this.extractStoragePrice();
|
||||||
|
|
||||||
this.setupEventListeners();
|
this.setupEventListeners();
|
||||||
this.populatePlanDropdown();
|
this.populatePlanDropdown();
|
||||||
this.updatePricing();
|
this.updatePricing();
|
||||||
|
@ -154,6 +158,23 @@ Please contact me with next steps for ordering this configuration.`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract storage price from pricing data
|
||||||
|
extractStoragePrice() {
|
||||||
|
if (!this.pricingData) return;
|
||||||
|
|
||||||
|
// Find the first plan with storage pricing data
|
||||||
|
for (const groupName of Object.keys(this.pricingData)) {
|
||||||
|
const group = this.pricingData[groupName];
|
||||||
|
for (const serviceLevel of Object.keys(group)) {
|
||||||
|
const plans = group[serviceLevel];
|
||||||
|
if (plans.length > 0 && plans[0].storage_price !== undefined) {
|
||||||
|
this.storagePrice = parseFloat(plans[0].storage_price);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Setup event listeners for calculator controls
|
// Setup event listeners for calculator controls
|
||||||
setupEventListeners() {
|
setupEventListeners() {
|
||||||
if (!this.cpuRange || !this.memoryRange || !this.storageRange) return;
|
if (!this.cpuRange || !this.memoryRange || !this.storageRange) return;
|
||||||
|
@ -437,11 +458,14 @@ Please contact me with next steps for ordering this configuration.`;
|
||||||
if (this.planMemory) this.planMemory.textContent = plan.ram + ' GB';
|
if (this.planMemory) this.planMemory.textContent = plan.ram + ' GB';
|
||||||
if (this.planServiceLevel) this.planServiceLevel.textContent = serviceLevel;
|
if (this.planServiceLevel) this.planServiceLevel.textContent = serviceLevel;
|
||||||
|
|
||||||
// Calculate pricing
|
// Calculate pricing using storage price from the plan data
|
||||||
const computePriceValue = parseFloat(plan.compute_plan_price);
|
const computePriceValue = parseFloat(plan.compute_plan_price);
|
||||||
const servicePriceValue = parseFloat(plan.sla_price);
|
const servicePriceValue = parseFloat(plan.sla_price);
|
||||||
const managedServicePrice = computePriceValue + servicePriceValue;
|
const managedServicePrice = computePriceValue + servicePriceValue;
|
||||||
const storagePriceValue = storage * this.storagePrice;
|
|
||||||
|
// Use storage price from plan data or fallback to instance variable
|
||||||
|
const storageUnitPrice = plan.storage_price !== undefined ? parseFloat(plan.storage_price) : this.storagePrice;
|
||||||
|
const storagePriceValue = storage * storageUnitPrice;
|
||||||
const totalPriceValue = managedServicePrice + storagePriceValue;
|
const totalPriceValue = managedServicePrice + storagePriceValue;
|
||||||
|
|
||||||
// Update pricing display
|
// Update pricing display
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
|
@ -14,6 +13,7 @@ from hub.services.models import (
|
||||||
Service,
|
Service,
|
||||||
ComputePlan,
|
ComputePlan,
|
||||||
VSHNAppCatPrice,
|
VSHNAppCatPrice,
|
||||||
|
StoragePlan,
|
||||||
)
|
)
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from markdownify import markdownify
|
from markdownify import markdownify
|
||||||
|
@ -239,6 +239,22 @@ def generate_pricing_data(offering):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Fetch storage plans for this cloud provider
|
||||||
|
storage_plans = (
|
||||||
|
StoragePlan.objects.filter(cloud_provider=offering.cloud_provider)
|
||||||
|
.prefetch_related("prices")
|
||||||
|
.order_by("name")
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get default storage pricing (use first available storage plan)
|
||||||
|
storage_price_data = {}
|
||||||
|
if storage_plans.exists():
|
||||||
|
default_storage_plan = storage_plans.first()
|
||||||
|
for currency in ["CHF", "EUR", "USD"]: # Add currencies as needed
|
||||||
|
price = default_storage_plan.get_price(currency)
|
||||||
|
if price is not None:
|
||||||
|
storage_price_data[currency] = price
|
||||||
|
|
||||||
# Fetch pricing for this specific service
|
# Fetch pricing for this specific service
|
||||||
try:
|
try:
|
||||||
appcat_price = (
|
appcat_price = (
|
||||||
|
@ -352,6 +368,7 @@ def generate_pricing_data(offering):
|
||||||
"compute_plan_price": compute_plan_price,
|
"compute_plan_price": compute_plan_price,
|
||||||
"sla_price": sla_price,
|
"sla_price": sla_price,
|
||||||
"final_price": final_price,
|
"final_price": final_price,
|
||||||
|
"storage_price": storage_price_data.get(currency, 0),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue