Skip to content

Commit

Permalink
conveted some floats to decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayles committed Apr 8, 2021
1 parent 04393a8 commit dd17c34
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions nadine/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ class RoomForm(forms.Form):
max_capacity = forms.IntegerField(min_value=1, max_value=1000, required=True)
has_av = forms.BooleanField(required=False)
has_phone = forms.BooleanField(required=False)
default_rate = forms.FloatField(required=True, min_value=0, max_value=None)
default_rate = forms.DecimalField(required=True, min_value=0, max_value=None)
image = forms.FileField(required=False)
members_only = forms.BooleanField(required=False)

Expand Down Expand Up @@ -719,4 +719,3 @@ def save(self):
return sub_default

# Copyright 2021 Office Nomads LLC (https://officenomads.com/) Licensed under the AGPL License, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/agpl-3.0.html. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

17 changes: 9 additions & 8 deletions nadine/models/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ def __str__(self):

@property
def total_paid(self):
return self.payment_set.aggregate(paid=Coalesce(Sum('amount'), Value(0.00)))['paid']
return self.payment_set.aggregate(paid=Coalesce(Sum('amount'), Value(0.00), output_field=DecimalField()))['paid']

@property
def total_owed(self):
return self.total - self.total_paid

@property
def amount(self):
return self.line_items.aggregate(amount=Coalesce(Sum('amount'), Value(0.00)))['amount']
return self.line_items.aggregate(amount=Coalesce(Sum('amount'), Value(0.00), output_field=DecimalField()))['amount']

@property
def tax_amount(self):
Expand All @@ -334,7 +334,7 @@ def payment_date(self):
@property
def monthly_rate(self):
''' Add up all rates for all the subscriptions. '''
return self.subscriptions().aggregate(rate=Coalesce(Sum('monthly_rate'), Value(0.00)))['rate']
return self.subscriptions().aggregate(rate=Coalesce(Sum('monthly_rate'), Value(0.00), output_field=DecimalField()))['rate']

@property
def overage_amount(self):
Expand Down Expand Up @@ -393,7 +393,8 @@ def get_admin_url(self):

def resource_allowance(self, resource):
''' Look at the subscriptions added to this bill to determine the allowance for the given resource. '''
return self.subscriptions().filter(resource=resource).aggregate(sum=Coalesce(Sum('allowance'), Value(0.00)))['sum']
query = self.subscriptions().filter(resource=resource)
return query.aggregate(sum=Coalesce(Sum('allowance'), Value(0.00), output_field=DecimalField()))['sum']

def resource_overage_rate(self, resource):
''' Look at the subscriptions added to this bill and determin the overage rate for the given resource. '''
Expand Down Expand Up @@ -577,10 +578,10 @@ def calculate_event_charge(self, event):
raise Exception("Event must have room specified or a specific charge set.")

if self.user.membership.active_subscriptions():
total_hours = self.event_hours_used + event.hours
total_hours = Decimal(self.event_hours_used + event.hours)
overage = total_hours - self.event_hour_allowance
if overage < 0:
overage = 0.00
overage = Decimal(0.00)

# Member only rooms get charged depending on subscriptions
if event.room.members_only:
Expand All @@ -591,7 +592,8 @@ def calculate_event_charge(self, event):
return event.room.default_rate
else:
# If there is an allowance, they are an active member and get a discount
return float(event.room.default_rate) * getattr(settings, "MEMBER_DISCOUNT_EVENTS", 1.0) * overage
discount = Decimal(getattr(settings, "MEMBER_DISCOUNT_EVENTS", 1.0))
return Decimal(event.room.default_rate) * discount * overage

def calculate_event_description(self, event):
day = str(event.start_ts.date())
Expand Down Expand Up @@ -894,4 +896,3 @@ def calculate_tax_rate(self):


# Copyright 2021 Office Nomads LLC (https://officenomads.com/) Licensed under the AGPL License, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/agpl-3.0.html. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

5 changes: 3 additions & 2 deletions nadine/models/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.db import models, IntegrityError, transaction
from django.db.models import F, Q, Count, Sum, Value
from django.db.models.functions import Coalesce
from django.db.models.fields import DecimalField
from django.contrib import admin
from django.core.files.base import ContentFile
from django.contrib.auth.models import User
Expand Down Expand Up @@ -444,7 +445,8 @@ def in_future(self, target_date=None):
return self in Membership.objects.future_memberships(target_date)

def monthly_rate(self, target_date=None):
return self.active_subscriptions(target_date).aggregate(rate=Coalesce(Sum('monthly_rate'), Value(0.00)))['rate']
query = self.active_subscriptions(target_date)
return query.aggregate(rate=Coalesce(Sum('monthly_rate'), Value(0.00), output_field=DecimalField()))['rate']

def get_period(self, target_date=None):
''' Get period associated with a certain date.
Expand Down Expand Up @@ -684,4 +686,3 @@ class SecurityDeposit(models.Model):


# Copyright 2021 Office Nomads LLC (https://officenomads.com/) Licensed under the AGPL License, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.gnu.org/licenses/agpl-3.0.html. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

0 comments on commit dd17c34

Please sign in to comment.