Don't error on invalid unit price, etc.

This commit is contained in:
Yingtong Li 2022-02-28 19:14:20 +11:00
parent 5c8c4750a5
commit 98a163f63a
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -1,5 +1,5 @@
# Society Self-Service # Society Self-Service
# Copyright © 2018–2020 Yingtong Li (RunasSudo) # Copyright © 2018–2022 Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -100,15 +100,23 @@ class BudgetRevision(models.Model):
def get_revenue_total(self): def get_revenue_total(self):
total = Decimal(0) total = Decimal(0)
for item in self.revenue: for item in self.revenue:
total += Decimal(item['Unit price']) * Decimal(item['Units']) try:
if item['IWT'] and item['Unit price'] > 0: total += Decimal(item['Unit price']) * Decimal(item['Units'])
total -= (Decimal(item['Unit price']) - (Decimal(item['Unit price']) - Decimal('0.8133')) / Decimal('1.01884')) * item['Units'] if item['IWT'] and item['Unit price'] > 0:
total -= (Decimal(item['Unit price']) - (Decimal(item['Unit price']) - Decimal('0.8133')) / Decimal('1.01884')) * item['Units']
except TypeError:
# Invalid unit price, etc.
pass
return total return total
def get_expense_total(self): def get_expense_total(self):
total = Decimal(0) total = Decimal(0)
for item in self.expense: for item in self.expense:
total += Decimal(item['Unit price']) * Decimal(item['Units']) try:
total += Decimal(item['Unit price']) * Decimal(item['Units'])
except TypeError:
# Invalid unit price, etc.
pass
if not self.expense_no_emergency_fund: if not self.expense_no_emergency_fund:
total *= Decimal('1.05') total *= Decimal('1.05')
return total return total
@ -240,7 +248,11 @@ class ReimbursementClaim(models.Model):
def get_total(self): def get_total(self):
total = Decimal(0) total = Decimal(0)
for item in self.items: for item in self.items:
total += Decimal(item['Unit price']) * Decimal(item['Units']) try:
total += Decimal(item['Unit price']) * Decimal(item['Units'])
except TypeError:
# Invalid unit price, etc.
pass
return total return total
def update_state(self, user, state): def update_state(self, user, state):