diff --git a/hosting/models.py b/hosting/models.py index 49932f69..04f3ae30 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -1,7 +1,9 @@ import os import logging +from dateutil.relativedelta import relativedelta from django.db import models +from django.utils import timezone from django.utils.functional import cached_property from Crypto.PublicKey import RSA from membership.models import StripeCustomer, CustomUser @@ -172,3 +174,9 @@ class VMDetail(models.Model): ipv6 = models.TextField(default='') created_at = models.DateTimeField(auto_now_add=True) terminated_at = models.DateTimeField(null=True) + + def end_date(self): + end_date = self.terminated_at if self.terminated_at else timezone.now() + months = relativedelta(end_date, self.created_at).months or 1 + end_date = self.created_at + relativedelta(months=months, days=-1) + return end_date diff --git a/hosting/static/hosting/css/commons.css b/hosting/static/hosting/css/commons.css index 317caabc..cdf078a0 100644 --- a/hosting/static/hosting/css/commons.css +++ b/hosting/static/hosting/css/commons.css @@ -375,4 +375,12 @@ outline: none; color: #999; fill: #999; +} + +.locale_date { + opacity: 0; +} + +.locale_date.done{ + opacity: 1; } \ No newline at end of file diff --git a/hosting/templates/hosting/order_detail.html b/hosting/templates/hosting/order_detail.html index c81a893f..fe200f6e 100644 --- a/hosting/templates/hosting/order_detail.html +++ b/hosting/templates/hosting/order_detail.html @@ -32,11 +32,11 @@ {% endif %}

{% trans "Date" %}: - + {% if order %} - {{order.created_at|date:'Y-m-d H:i'}} + {{order.created_at|date:'Y-m-d h:i a'}} {% else %} - {% now "Y-m-d H:i" %} + {% now "Y-m-d h:i a" %} {% endif %}

@@ -107,7 +107,9 @@ {% if vm.created_at %}

{% trans "Period" %}: - {{ vm.created_at|date:'Y/m/d' }} - {% if vm.terminated_at %}{{ vm.terminated_at|date:'Y/m/d' }}{% else %}{% now 'Y/m/d' %}{% endif %} + + {{ vm.created_at|date:'Y-m-d h:i a' }} - {{ subscription_end_date|date:'Y-m-d h:i a' }} +

{% endif %}

@@ -194,12 +196,16 @@ {%endblock%} diff --git a/hosting/views.py b/hosting/views.py index 6b314f5b..f6d0f0eb 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -703,6 +703,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, disk_size=context['vm']['disk_size'], memory=context['vm']['memory'] ) + context['subscription_end_date'] = vm_detail.end_date() except VMDetail.DoesNotExist: try: manager = OpenNebulaManager(