price comparison improved
This commit is contained in:
parent
e06105942b
commit
d987f62471
3 changed files with 68 additions and 46 deletions
|
@ -387,10 +387,9 @@ class ExternalPricePlansAdmin(ImportExportModelAdmin):
|
||||||
"plan_name",
|
"plan_name",
|
||||||
"cloud_provider",
|
"cloud_provider",
|
||||||
"service",
|
"service",
|
||||||
"currency",
|
|
||||||
"amount",
|
"amount",
|
||||||
"display_compare_to_count",
|
"display_compare_to_count",
|
||||||
"date_retrieved",
|
"replicas",
|
||||||
)
|
)
|
||||||
list_filter = ("cloud_provider", "service", "currency", "term")
|
list_filter = ("cloud_provider", "service", "currency", "term")
|
||||||
search_fields = ("plan_name", "cloud_provider__name", "service__name")
|
search_fields = ("plan_name", "cloud_provider__name", "service__name")
|
||||||
|
|
|
@ -146,6 +146,7 @@
|
||||||
<thead class="table-dark">
|
<thead class="table-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Compute Plan</th>
|
<th>Compute Plan</th>
|
||||||
|
<th>Cloud Provider</th>
|
||||||
<th>vCPUs</th>
|
<th>vCPUs</th>
|
||||||
<th>RAM (GB)</th>
|
<th>RAM (GB)</th>
|
||||||
<th>Term</th>
|
<th>Term</th>
|
||||||
|
@ -167,8 +168,9 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for row in pricing_data %}
|
{% for row in pricing_data %}
|
||||||
<tr>
|
<tr class="servala-row">
|
||||||
<td>{{ row.compute_plan }}</td>
|
<td>{{ row.compute_plan }}</td>
|
||||||
|
<td>{{ row.cloud_provider }}</td>
|
||||||
<td>{{ row.vcpus }}</td>
|
<td>{{ row.vcpus }}</td>
|
||||||
<td>{{ row.ram }}</td>
|
<td>{{ row.ram }}</td>
|
||||||
<td>{{ row.term }}</td>
|
<td>{{ row.term }}</td>
|
||||||
|
@ -207,39 +209,61 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if show_price_comparison %}
|
{% if show_price_comparison %}
|
||||||
<td>
|
<td>
|
||||||
{% if row.external_comparisons %}
|
<span class="badge">-</span>
|
||||||
<small>
|
|
||||||
{% for comparison in row.external_comparisons %}
|
|
||||||
<div class="mb-2 border-bottom pb-1">
|
|
||||||
<strong>{{ comparison.provider }}</strong>: {{ comparison.plan_name }}<br>
|
|
||||||
<span class="text-primary">{{ comparison.amount|floatformat:2 }} {{ row.currency }}</span>
|
|
||||||
{% if comparison.difference > 0 %}
|
|
||||||
<span class="badge ms-1">+{{ comparison.difference|floatformat:2 }}</span>
|
|
||||||
{% elif comparison.difference < 0 %}
|
|
||||||
<span class="badge ms-1">{{ comparison.difference|floatformat:2 }}</span>
|
|
||||||
{% endif %}
|
|
||||||
{% if comparison.ratio %}
|
|
||||||
<br><small class="text-muted">Price ratio: {{ comparison.ratio|floatformat:2 }}x</small>
|
|
||||||
{% endif %}
|
|
||||||
{% if comparison.description %}
|
|
||||||
<br><small class="text-muted">{{ comparison.description }}</small>
|
|
||||||
{% endif %}
|
|
||||||
{% if comparison.vcpus or comparison.ram %}
|
|
||||||
<br><small class="text-muted">
|
|
||||||
{% if comparison.vcpus %}{{ comparison.vcpus }} vCPU{% endif %}
|
|
||||||
{% if comparison.ram %}{{ comparison.ram }} GB RAM{% endif %}
|
|
||||||
</small>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</small>
|
|
||||||
{% else %}
|
|
||||||
<small class="text-muted">No comparisons</small>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="final-price-cell fw-bold">{{ row.final_price|floatformat:2 }}</td>
|
<td class="final-price-cell fw-bold">{{ row.final_price|floatformat:2 }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if show_price_comparison and row.external_comparisons %}
|
||||||
|
{% for comparison in row.external_comparisons %}
|
||||||
|
<tr class="table-light comparison-row">
|
||||||
|
<td class="text-muted">{{ comparison.plan_name }}</td>
|
||||||
|
<td class="text-muted">{{ comparison.provider }}</td>
|
||||||
|
<td class="text-muted">
|
||||||
|
{% if comparison.vcpus %}{{ comparison.vcpus }}{% else %}-{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="text-muted">
|
||||||
|
{% if comparison.ram %}{{ comparison.ram }}{% else %}-{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="text-muted">{{ row.term }}</td>
|
||||||
|
<td class="text-muted">{{ comparison.currency }}</td>
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
{% if show_discount_details %}
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
<td class="text-muted">-</td>
|
||||||
|
{% endif %}
|
||||||
|
<td>
|
||||||
|
<small>
|
||||||
|
<span class="badge bg-secondary">{% if comparison.source %}<span class="text-muted"><a href="{{ comparison.source }}" target="_blank">{{ comparison.provider }}</a></span>{% else %}{{ comparison.provider }}{% endif %}</span><br>
|
||||||
|
{% if comparison.description %}
|
||||||
|
<span class="text-muted">{{ comparison.description }}</span><br>
|
||||||
|
{% endif %}
|
||||||
|
{% if comparison.storage %}
|
||||||
|
<span class="text-muted">Storage: {{ comparison.storage }} GB</span><br>
|
||||||
|
{% endif %}
|
||||||
|
{% if comparison.replicas %}
|
||||||
|
<span class="text-muted">Replicas: {{ comparison.replicas }}</span><br>
|
||||||
|
{% endif %}
|
||||||
|
{% if comparison.ratio %}
|
||||||
|
<span class="text-muted">Price ratio: {{ comparison.ratio|floatformat:2 }}x</span><br>
|
||||||
|
{% endif %}
|
||||||
|
</small>
|
||||||
|
</td>
|
||||||
|
<td class="fw-bold">
|
||||||
|
{{ comparison.amount|floatformat:2 }} {{ comparison.currency }}
|
||||||
|
{% if comparison.difference > 0 %}
|
||||||
|
<span class="badge bg-danger ms-1">+{{ comparison.difference|floatformat:2 }}</span>
|
||||||
|
{% elif comparison.difference < 0 %}
|
||||||
|
<span class="badge bg-success ms-1">{{ comparison.difference|floatformat:2 }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -16,9 +16,9 @@ def natural_sort_key(name):
|
||||||
def get_external_price_comparisons(plan, appcat_price, currency, service_level):
|
def get_external_price_comparisons(plan, appcat_price, currency, service_level):
|
||||||
"""Get external price comparisons for a specific compute plan and service"""
|
"""Get external price comparisons for a specific compute plan and service"""
|
||||||
try:
|
try:
|
||||||
# Filter by service level if external price has one set
|
# Filter by service level if external price has one set, ignore currency for comparison
|
||||||
external_prices = ExternalPricePlans.objects.filter(
|
external_prices = ExternalPricePlans.objects.filter(
|
||||||
compare_to=plan, service=appcat_price.service, currency=currency
|
compare_to=plan, service=appcat_price.service
|
||||||
).select_related("cloud_provider")
|
).select_related("cloud_provider")
|
||||||
|
|
||||||
# Filter by service level if the external price has it configured
|
# Filter by service level if the external price has it configured
|
||||||
|
@ -208,29 +208,28 @@ def pricelist(request):
|
||||||
external_prices = get_external_price_comparisons(
|
external_prices = get_external_price_comparisons(
|
||||||
plan, appcat_price, currency, service_level
|
plan, appcat_price, currency, service_level
|
||||||
)
|
)
|
||||||
|
|
||||||
for ext_price in external_prices:
|
for ext_price in external_prices:
|
||||||
price_difference = float(ext_price.amount) - float(
|
# Calculate price difference using external price currency
|
||||||
final_price
|
difference = ext_price.amount - final_price
|
||||||
)
|
ratio = (
|
||||||
price_ratio = (
|
ext_price.amount / final_price if final_price > 0 else 0
|
||||||
float(ext_price.amount) / float(final_price)
|
|
||||||
if final_price > 0
|
|
||||||
else None
|
|
||||||
)
|
)
|
||||||
|
|
||||||
external_comparisons.append(
|
external_comparisons.append(
|
||||||
{
|
{
|
||||||
"provider": ext_price.cloud_provider.name,
|
|
||||||
"plan_name": ext_price.plan_name,
|
"plan_name": ext_price.plan_name,
|
||||||
"amount": ext_price.amount,
|
"provider": ext_price.cloud_provider.name,
|
||||||
"difference": price_difference,
|
|
||||||
"ratio": price_ratio,
|
|
||||||
"description": ext_price.description,
|
"description": ext_price.description,
|
||||||
|
"amount": ext_price.amount,
|
||||||
|
"currency": ext_price.currency, # Use external price currency
|
||||||
"vcpus": ext_price.vcpus,
|
"vcpus": ext_price.vcpus,
|
||||||
"ram": ext_price.ram,
|
"ram": ext_price.ram,
|
||||||
"storage": ext_price.storage,
|
"storage": ext_price.storage,
|
||||||
"replicas": ext_price.replicas,
|
"replicas": ext_price.replicas,
|
||||||
|
"difference": difference,
|
||||||
|
"ratio": ratio,
|
||||||
|
"source": ext_price.source,
|
||||||
|
"date_retrieved": ext_price.date_retrieved,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue