Changeset - c0de5deb271c
[Not reviewed]
Dennis Fink - 9 years ago 2015-10-27 23:10:39
dennis.fink@c3l.lu
Fix ValueError in total calculation of received donations

We use decimal to provide accuracy
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
ennstatus/donate/views.py
Show inline comments
 
@@ -11,12 +11,13 @@
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
from decimal import Decimal
 
from flask import (Blueprint, render_template, request,
 
                   redirect, url_for, current_app)
 

	
 
from ennstatus.donate.forms import DateForm
 
from ennstatus.donate.functions import load_csv, get_choices
 

	
 
@@ -104,13 +105,13 @@ def received():
 
            current_app.logger.info('Showing last date %s' % filename)
 
            year, month = filename.split('-')
 
            form.year.data = year
 
            form.month.data = '{:02d}'.format(int(month))
 
            csv_file = load_csv(filename)
 

	
 
        total = str(sum(int(row[2]) for row in csv_file))
 
        total = str(sum(Decimal(row[2].replace(',', '.')) for row in csv_file))
 
        csv_file = load_csv(filename)
 

	
 
        current_app.logger.info('Return result')
 
        return render_template('donate/received.html',
 
                               form=form, csv_file=csv_file,
 
                               year=year, month=month, total=total)
0 comments (0 inline, 0 general)