account balance
This commit is contained in:
@ -152,6 +152,7 @@ def create():
|
||||
return render_template(
|
||||
"create-capsul.html",
|
||||
created_os=created_os,
|
||||
account_balance=format(account_balance, '.2f'),
|
||||
ssh_public_keys=ssh_public_keys,
|
||||
ssh_public_key_count=len(ssh_public_keys),
|
||||
no_ssh_public_keys=len(ssh_public_keys) == 0,
|
||||
@ -214,12 +215,14 @@ def get_payments():
|
||||
g.user_payments = get_model().list_payments_for_account(session["account"])
|
||||
return g.user_payments
|
||||
|
||||
|
||||
average_number_of_days_in_a_month = 30.44
|
||||
|
||||
def get_account_balance():
|
||||
average_number_of_days_in_a_month = 30.44
|
||||
|
||||
vm_cost_dollars = 0.0
|
||||
for vm in get_vms():
|
||||
end_datetime = vm["deleted"] if vm["deleted"] else datetime.now()
|
||||
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_cost_dollars += vm_months * float(vm["dollars_per_month"])
|
||||
|
||||
@ -230,11 +233,30 @@ def get_account_balance():
|
||||
@bp.route("/account-balance")
|
||||
@account_required
|
||||
def account_balance():
|
||||
errors = list()
|
||||
payments = get_payments()
|
||||
account_balance = get_account_balance()
|
||||
|
||||
vms_billed = list()
|
||||
|
||||
for vm in get_vms():
|
||||
end_datetime = vm["deleted"] if vm["deleted"] else datetime.utcnow()
|
||||
print(end_datetime)
|
||||
print(vm["created"])
|
||||
vm_months = (end_datetime - vm["created"]).days / average_number_of_days_in_a_month
|
||||
vms_billed.append(dict(
|
||||
id=vm["id"],
|
||||
dollars_per_month=vm["dollars_per_month"],
|
||||
created=vm["created"].strftime("%b %d %Y"),
|
||||
deleted=vm["deleted"].strftime("%b %d %Y") if vm["deleted"] else "N/A",
|
||||
months=format(vm_months, '.3f'),
|
||||
dollars=format(vm_months * float(vm["dollars_per_month"]), '.2f')
|
||||
))
|
||||
|
||||
return render_template(
|
||||
"account-balance.html",
|
||||
payments=payments, has_payments=len(payments)>0, account_balance=account_balance
|
||||
has_vms=len(vms_billed)>0,
|
||||
vms_billed=vms_billed,
|
||||
payments=list(map(lambda x: dict(dollars=x["dollars"], created=x["created"].strftime("%b %d %Y")), payments)),
|
||||
has_payments=len(payments)>0,
|
||||
account_balance=format(account_balance, '.2f')
|
||||
)
|
Reference in New Issue
Block a user