forked from 3wordchant/capsul-flask
correctly display vm_months
This commit is contained in:
parent
4b169e9886
commit
684128361c
@ -269,15 +269,18 @@ def get_payments():
|
|||||||
|
|
||||||
average_number_of_days_in_a_month = 30.44
|
average_number_of_days_in_a_month = 30.44
|
||||||
|
|
||||||
def get_account_balance(vms, payments, as_of):
|
def get_vm_months_float(vm, as_of):
|
||||||
|
|
||||||
vm_cost_dollars = 0.0
|
|
||||||
for vm in vms:
|
|
||||||
end_datetime = vm["deleted"] if vm["deleted"] else as_of
|
end_datetime = vm["deleted"] if vm["deleted"] else as_of
|
||||||
days = float((end_datetime - vm["created"]).total_seconds())/float(60*60*24)
|
days = float((end_datetime - vm["created"]).total_seconds())/float(60*60*24)
|
||||||
if days < 1:
|
if days < 1:
|
||||||
days = float(1)
|
days = float(1)
|
||||||
vm_months = days / average_number_of_days_in_a_month
|
return days / average_number_of_days_in_a_month
|
||||||
|
|
||||||
|
def get_account_balance(vms, payments, as_of):
|
||||||
|
|
||||||
|
vm_cost_dollars = 0.0
|
||||||
|
for vm in vms:
|
||||||
|
vm_months = get_vm_months_float(vm, as_of)
|
||||||
vm_cost_dollars += vm_months * float(vm["dollars_per_month"])
|
vm_cost_dollars += vm_months * float(vm["dollars_per_month"])
|
||||||
|
|
||||||
payment_dollars_total = float( sum(map(lambda x: 0 if x["invalidated"] else x["dollars"], payments)) )
|
payment_dollars_total = float( sum(map(lambda x: 0 if x["invalidated"] else x["dollars"], payments)) )
|
||||||
@ -314,9 +317,7 @@ def account_balance():
|
|||||||
vms_billed = list()
|
vms_billed = list()
|
||||||
|
|
||||||
for vm in get_vms():
|
for vm in get_vms():
|
||||||
end_datetime = vm["deleted"] if vm["deleted"] else datetime.utcnow()
|
vm_months = get_vm_months_float(vm, datetime.utcnow())
|
||||||
|
|
||||||
vm_months = (end_datetime - vm["created"]).days / average_number_of_days_in_a_month
|
|
||||||
vms_billed.append(dict(
|
vms_billed.append(dict(
|
||||||
id=vm["id"],
|
id=vm["id"],
|
||||||
dollars_per_month=vm["dollars_per_month"],
|
dollars_per_month=vm["dollars_per_month"],
|
||||||
|
Loading…
Reference in New Issue
Block a user