Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

csvbills: payment in future is a fatal error

Now it is checked that a payment is not in the
future. Maximum allowed payment date is today
+ 1 day. This should be ok since
 1) we wait for 14 days by default before sending
    reminders
 2) this error should never be present in the CSV
    data in the first place

This check is only a sanity check.
  • Loading branch information...
commit c6181199bc0a219a4e7d5470d05dde798e725f0e 1 parent 6544d52
@joneskoo joneskoo authored
View
2  membership/fixtures/csv-future.txt
@@ -0,0 +1,2 @@
+Kirjausp�iv�;Arvop�iv�;M��r� EUROA;Tapahtumalajikoodi;Selitys;Saaja/Maksaja;Saajan tilinumero;Viite;Viesti;Arkistotunnus;
+10.07.2030;10.07.2030;30,00;588;VIITESIIRTO;MEIK�L�INEN MATTI JOHANNES;;00000000000001110012;SEPA-MAKSU SAAJA/MOTTAG./BEN: Kapsi Internet-kKULUKOODI: SLEV ALKUP.M��R� EUR 30.00+ EUR 30.00+;203007255UTZ00002151;
View
6 membership/management/commands/csvbills.py
@@ -12,7 +12,7 @@
import csv
import os
-from datetime import datetime
+from datetime import datetime, timedelta
from decimal import Decimal
import logging
@@ -70,6 +70,7 @@ def next(self):
class RequiredFieldNotFoundException(Exception): pass
class DuplicateColumnException(Exception): pass
+class PaymentFromFutureException(Exception): pass
class OpDictReader(UnicodeDictReader):
'''Reader for Osuuspankki CSV file format
@@ -171,6 +172,9 @@ def process_csv(file_handle):
continue
if row['amount'] < 0: # Transaction is paid by us, ignored
continue
+ # Payment in future more than 1 day is a fatal error
+ if row['date'] > datetime.now() + timedelta(days=1):
+ raise PaymentFromFutureException("Payment date in future")
payment = row_to_payment(row)
# Do nothing if this payment has already been assigned or ignored
View
6 membership/tests.py
@@ -42,6 +42,7 @@
from management.commands.makebills import MembershipNotApproved
from management.commands.csvbills import process_csv
+from management.commands.csvbills import PaymentFromFutureException
__test__ = {
"tupletuple_to_dict": tupletuple_to_dict,
@@ -618,6 +619,11 @@ def test_duplicate_payment(self):
self.assertEqual(cycle.reference_number, payment.reference_number)
self.assertTrue(cycle.is_paid)
+ def test_future_payment(self):
+ error = "Should fail on payment in the future"
+ with open("../membership/fixtures/csv-future.txt", 'r') as f:
+ self.assertRaises(PaymentFromFutureException, process_csv, f)
+
class LoginRequiredTest(TestCase):
fixtures = ['membpership_fees.json', 'test_user.json']
Please sign in to comment.
Something went wrong with that request. Please try again.