Commit 74e7fb9a by Kálmán Viktor

dashboard: lease form fix year inaccuracy

parent c48f9e72
......@@ -321,7 +321,7 @@ class LeaseForm(forms.ModelForm):
if count != 0:
break
re = {'%s' % name: count}
if i + 1 < len(chunks):
if i + 1 < len(chunks) and i > 0:
seconds2, name2 = chunks[i + 1]
count2 = (delta_seconds - (seconds * count)) // seconds2
if count2 != 0:
......@@ -348,25 +348,17 @@ class LeaseForm(forms.ModelForm):
def save(self, commit=True):
data = self.cleaned_data
# 12 months are only 360 days and not 365
data['suspend_years'] = data['delete_years'] = 0
while data['suspend_months'] >= 12:
data['suspend_years'] += 1
data['suspend_months'] -= 12
while data['delete_months'] >= 12:
data['delete_years'] += 1
data['delete_months'] -= 12
suspend_seconds = timedelta(
hours=data['suspend_hours'],
days=(data['suspend_days'] + data['suspend_months'] * 30 +
data['suspend_years'] * 365),
days=(data['suspend_days'] + data['suspend_months'] % 12 * 30 +
data['suspend_months'] / 12 * 365),
weeks=data['suspend_weeks'],
)
delete_seconds = timedelta(
hours=data['delete_hours'],
days=(data['delete_days'] + data['delete_months'] * 30 +
data['delete_years'] * 365),
days=(data['delete_days'] + data['delete_months'] % 12 * 30 +
data['delete_months'] / 12 * 365),
weeks=data['delete_weeks'],
)
self.instance.delete_interval = delete_seconds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment