implement bill for at least 24 hours

This commit is contained in:
2020-05-16 23:21:09 -05:00
parent 4f002458b3
commit 4b169e9886
2 changed files with 7 additions and 3 deletions

View File

@ -45,7 +45,7 @@ def double_check_capsul_address(id, ipv4):
def index():
vms = get_vms()
created = request.args.get('created')
# this is here to prevent xss
if not re.match(r"^(cvm|capsul)-[a-z0-9]{10}$", created):
created = '___________'
@ -274,7 +274,10 @@ def get_account_balance(vms, payments, as_of):
vm_cost_dollars = 0.0
for vm in vms:
end_datetime = vm["deleted"] if vm["deleted"] else as_of
vm_months = ( end_datetime - vm["created"] ).days / average_number_of_days_in_a_month
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
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)) )