fix rounding bugs in accounting
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Fri, 27 Feb 2009 11:36:58 +0100
changeset 8 b9f1006b4c00
parent 7 768d024d363f
child 9 86496d6389f4
fix rounding bugs in accounting
views/accounting.py
--- a/views/accounting.py	Fri Jan 30 15:33:29 2009 +0100
+++ b/views/accounting.py	Fri Feb 27 11:36:58 2009 +0100
@@ -44,17 +44,17 @@
         entity = self.complete_entity(row, col)
         self.w(u'  <ecriture date="%s">\n' % entity.diem.strftime('%Y-%m-%d'))
         self.w(u'    <libelle>%s</libelle>\n' % html_escape(entity.dc_long_title()))
-        amount = int(entity.euro_amount()*100) / 100.0
-        taxes = int(entity.taxes*100) / 100.0
+        amount = round(entity.euro_amount(), 2)
+        taxes = round(entity.taxes, 2)
         self.w(u'    <credit compte="%s" montant="%.2f" />\n' % (
             entity.paid_by[0].account, amount))
         if entity.taxes:
             # XXX hardcoded account for VAT
             self.w(u'    <debit compte="44566" montant="%.2f" />\n' % entity.taxes)
-        taxfree = amount - taxes
+        taxfree = int(round((amount - taxes) * 100))
         accounts = list(entity.paid_for)
-        debit_quotient = int(taxfree*100) / len(accounts)
-        debit_remainder = int(taxfree*100) % len(accounts)
+        debit_quotient = taxfree / len(accounts)
+        debit_remainder = taxfree % len(accounts)
         for account in accounts:
             if debit_remainder > 0:
                 debit = (debit_quotient + 1) / 100.0