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
|
||||
|
||||
def get_account_balance(vms, payments, as_of):
|
||||
|
||||
vm_cost_dollars = 0.0
|
||||
for vm in vms:
|
||||
def get_vm_months_float(vm, as_of):
|
||||
end_datetime = vm["deleted"] if vm["deleted"] else as_of
|
||||
days = float((end_datetime - vm["created"]).total_seconds())/float(60*60*24)
|
||||
if days < 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"])
|
||||
|
||||
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()
|
||||
|
||||
for vm in get_vms():
|
||||
end_datetime = vm["deleted"] if vm["deleted"] else datetime.utcnow()
|
||||
|
||||
vm_months = (end_datetime - vm["created"]).days / average_number_of_days_in_a_month
|
||||
vm_months = get_vm_months_float(vm, datetime.utcnow())
|
||||
vms_billed.append(dict(
|
||||
id=vm["id"],
|
||||
dollars_per_month=vm["dollars_per_month"],
|
||||
|
Loading…
Reference in New Issue
Block a user