Merge pull request #509 from tiwariav/task/3828/invoice_period

task/3828 invoice period
This commit is contained in:
Arvind Tiwari 2017-10-15 01:27:02 +05:30 committed by GitHub
commit 1c50eb45e9
4 changed files with 32 additions and 9 deletions

View file

@ -1,7 +1,9 @@
import os import os
import logging import logging
from dateutil.relativedelta import relativedelta
from django.db import models from django.db import models
from django.utils import timezone
from django.utils.functional import cached_property from django.utils.functional import cached_property
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from membership.models import StripeCustomer, CustomUser from membership.models import StripeCustomer, CustomUser
@ -172,3 +174,9 @@ class VMDetail(models.Model):
ipv6 = models.TextField(default='') ipv6 = models.TextField(default='')
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
terminated_at = models.DateTimeField(null=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

View file

@ -376,3 +376,11 @@
color: #999; color: #999;
fill: #999; fill: #999;
} }
.locale_date {
opacity: 0;
}
.locale_date.done{
opacity: 1;
}

View file

@ -32,11 +32,11 @@
{% endif %} {% endif %}
<p> <p>
<strong>{% trans "Date" %}:</strong> <strong>{% trans "Date" %}:</strong>
<span id="order-created_at"> <span class="locale_date">
{% if order %} {% if order %}
{{order.created_at|date:'Y-m-d H:i'}} {{order.created_at|date:'Y-m-d h:i a'}}
{% else %} {% else %}
{% now "Y-m-d H:i" %} {% now "Y-m-d h:i a" %}
{% endif %} {% endif %}
</span> </span>
</p> </p>
@ -107,7 +107,9 @@
{% if vm.created_at %} {% if vm.created_at %}
<p> <p>
<span>{% trans "Period" %}: </span> <span>{% trans "Period" %}: </span>
<span>{{ vm.created_at|date:'Y/m/d' }} - {% if vm.terminated_at %}{{ vm.terminated_at|date:'Y/m/d' }}{% else %}{% now 'Y/m/d' %}{% endif %}</span> <span>
<span class="locale_date" data-format="YYYY/MM/DD">{{ vm.created_at|date:'Y-m-d h:i a' }}</span> - <span class="locale_date" data-format="YYYY/MM/DD">{{ subscription_end_date|date:'Y-m-d h:i a' }}</span>
</span>
</p> </p>
{% endif %} {% endif %}
<p> <p>
@ -194,12 +196,16 @@
<script type="text/javascript"> <script type="text/javascript">
{% trans "Some problem encountered. Please try again later." as err_msg %} {% trans "Some problem encountered. Please try again later." as err_msg %}
var create_vm_error_message = '{{err_msg|safe}}'; var create_vm_error_message = '{{err_msg|safe}}';
window.onload = function () { window.onload = function () {
var locale_date = moment.utc(document.getElementById("order-created_at").textContent, 'YYYY-MM-DD HH:mm').toDate(); var locale_dates = document.getElementsByClassName("locale_date");
locale_date = moment(locale_date).format("YYYY-MM-DD h:mm:ss a"); var formats = ['YYYY-MM-DD hh:mm a']
document.getElementById('order-created_at').innerHTML = locale_date; var i;
for (i = 0; i < locale_dates.length; i++) {
var oldDate = moment.utc(locale_dates[i].textContent, formats);
var outputFormat = locale_dates[i].getAttribute('data-format') || oldDate._f;
locale_dates[i].innerHTML = oldDate.local().format(outputFormat);
locale_dates[i].className += ' done';
}
}; };
</script> </script>
{%endblock%} {%endblock%}

View file

@ -703,6 +703,7 @@ class OrdersHostingDetailView(LoginRequiredMixin,
disk_size=context['vm']['disk_size'], disk_size=context['vm']['disk_size'],
memory=context['vm']['memory'] memory=context['vm']['memory']
) )
context['subscription_end_date'] = vm_detail.end_date()
except VMDetail.DoesNotExist: except VMDetail.DoesNotExist:
try: try:
manager = OpenNebulaManager( manager = OpenNebulaManager(