コード例 #1
0
ファイル: tests.py プロジェクト: bartaelterman/BIA-payment
 def setUp(self):
     school = School(name='testschool')
     school.save()
     # country = Country(name='testcountry')
     # country.save()
     child = Child(first_name='mary', surname='jones', sex='f', school=school)
     child.save()
     contributor1 = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street',
                                street_number=4, zip_code=2010, city='city', payment_frequency='every month',
                                language='nl')
     contributor1.save()
     contributor2 = Contributor(first_name='marie', surname='evers', aard_van_de_schenker='np', street='some street',
                                street_number=4, zip_code=2010, city='city', payment_frequency='every 3 months',
                                language='nl')
     contributor2.save()
     contributor3 = Contributor(first_name='havent', surname='peeyd', aard_van_de_schenker='np', street='some street',
                                street_number=4, zip_code=2010, city='city', payment_frequency='every 3 months',
                                language='nl')
     contributor3.save()
     payments = [
         {'amount': 42.4, 'contributor': contributor1, 'child': child, 'date': date(2014, 2, 20), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor1, 'child': child, 'date': date(2014, 3, 20), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor1, 'child': child, 'date': date(2014, 1, 20), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 1, 14), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 4, 15), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 7, 16), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor2, 'child': child, 'date': date(2014, 10, 17), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': contributor3, 'child': child, 'date': date(2014, 10, 17), 'entitled': 'entitled', 'ptype': 'recurrent'},
     ]
     for p in payments:
         payment = Payment(**p)
         payment.save()
コード例 #2
0
ファイル: tests.py プロジェクト: bartaelterman/BIA-payment
 def setUp(self):
     """
     This fixture data set includes:
         contributor1: pays every month and therefor, should not be included in reminders report, although his next
          expected payment is in the near future.
         contributor2: pays every 3 months, and hence should show up in the overdue report.
         contributor3: pays every year and hence should show up in the reminders report.
         contributor4: pays sporadic, and hence should not be included in one of the reports
     """
     print 'installing fixture data'
     self.reference_date = date(2015, 11, 7)
     country = Country(name='Belgium', code=150)
     country.save()
     school = School(name='testschool')
     school.save()
     child = Child(first_name='mary', surname='jones', sex='f', school=school)
     child.save()
     self.contributor1 = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street',
                                street_number=4, zip_code=2010, city='city', country=country,
                                payment_frequency='every month', language='nl')
     self.contributor1.save()
     self.contributor2 = Contributor(first_name='marie', surname='evers', aard_van_de_schenker='np',
                                     street='some street', street_number=4, zip_code=2010, city='city',
                                     country=country, payment_frequency='every 3 months', language='nl')
     self.contributor2.save()
     self.contributor3 = Contributor(first_name='harvey', surname='jones', aard_van_de_schenker='np',
                                     street='some street', street_number=4, zip_code=2010, city='city',
                                     country=country, payment_frequency='every year', language='nl')
     self.contributor3.save()
     self.contributor4 = Contributor(first_name='jeff', surname='buckley', aard_van_de_schenker='np',
                                     street='some street', street_number=4, zip_code=2010, city='city',
                                     country=country, payment_frequency='sporadic', language='nl')
     self.contributor4.save()
     payments = [
         {'amount': 45, 'contributor': self.contributor1, 'child': child, 'date': date(2015, 10, 1),
          'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 45, 'contributor': self.contributor1, 'child': child, 'date': date(2015, 12, 4),
          'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 45, 'contributor': self.contributor2, 'child': child, 'date': date(2015, 8, 15),
          'expected_date': date(2015, 8, 1), 'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 42.4, 'contributor': self.contributor3, 'child': child,
          'date': date(2014, 12, 10), 'expected_date': date(2014, 11, 21),
         'entitled': 'entitled', 'ptype': 'recurrent'},
         {'amount': 30, 'contributor': self.contributor4, 'child': child,
          'date': date(2014, 12, 1), 'entitled': 'entitled', 'ptype': 'recurrent'},
     ]
     for p in payments:
         payment = Payment(**p)
         payment.save()
コード例 #3
0
ファイル: tests.py プロジェクト: bartaelterman/BIA-payment
 def test_overdue(self):
     """
     contributor 2 is overdue and should show up in the results
     """
     overdue_rep = OverdueReport()
     res = overdue_rep.getReportingValues(allowed_overdue_days=5, _reference_date=self.reference_date)
     self.assertEqual(len(res['values']), 1)
     self.assertEqual(res['values'][0][1], 'marie evers')
     self.assertEqual(res['values'][0][7], -6) # this is the days until next expected payment. Based on previous expected date and payment frequency.
     res = overdue_rep.getReportingValues(allowed_overdue_days=7, _reference_date=self.reference_date)
     self.assertAlmostEqual(len(res['values']), 0) # contributor 2 is now excluded
     new_payment = Payment(amount=45, contributor=self.contributor2, date=self.reference_date - relativedelta(days=4), entitled='entitled', ptype='single')
     new_payment.save()
     res = overdue_rep.getReportingValues(allowed_overdue_days=5, _reference_date=self.reference_date)
     self.assertEqual(len(res['values']), 1) # new payment for contributor 2 is ignored because ptype="single". Contributor 2 is still overdue
     self.assertEqual(res['values'][0][1], 'marie evers')
コード例 #4
0
ファイル: tests.py プロジェクト: bartaelterman/BIA-payment
def create_fixture():
    country = Country(name='Belgium', code=150)
    country.save()
    school = School(name='testschool')
    school.save()
    child = Child(first_name='mary', surname='jones', sex='f', school=school)
    child.save()
    contributor = Contributor(first_name='john', surname='doe', aard_van_de_schenker='np', street='some street',
                               street_number=4, zip_code=2010, city='city', country=country,
                               payment_frequency='every month', language='nl')
    contributor.save()

    payments = [
        {'amount': 48, 'contributor': contributor, 'child': child, 'date': date(2015, 10, 1),
         'entitled': 'entitled', 'ptype': 'recurrent'},
        {'amount': 49, 'contributor': contributor, 'child': child, 'date': date(2015, 12, 4),
         'entitled': 'entitled', 'ptype': 'recurrent'},
        {'amount': 49.5, 'contributor': contributor, 'child': child, 'date': date(2015, 12, 16),
         'entitled': 'entitled', 'ptype': 'single'}
    ]
    for p in payments:
        payment = Payment(**p)
        payment.save()
コード例 #5
0
ファイル: tests.py プロジェクト: bartaelterman/BIA-payment
 def test_expected_date_autofill(self):
     payment = Payment(amount=50, contributor=self.contributor, child=self.child, date=date(2016, 1, 20),
                       entitled='entitled', ptype='recurrent')
     payment.save()
     self.assertEqual(payment.expected_date, date(2015, 12, 1))
コード例 #6
0
    def _load_payments(self):
        """
        LOAD PAYMENTS
        :return: nothing. Happens in place
        """
        # change amount format
        def clean_format(x):
            x = x.replace('€', '')
            x = x.strip()
            return x

        # parse date format
        def dateparse(x):
            if pandas.isnull(x):
                return None
            return pandas.datetime.strptime(x, '%d/%m/%y %H:%M:%S')

        # lookup child method
        def lookup_child(child_id):
            if child_id:
                return self.children_lookup[int(child_id)]

        # lookup contributor method
        def lookup_contributor(contributor_id):
            if contributor_id in self.contributor_lookup.keys():
                return self.contributor_lookup[contributor_id]
            self.stdout.write('Contributor with number {0} not found.'.format(contributor_id))

        self.stdout.write('\nloading payments')

        self.payments_data['amount'] = self.payments_data['amount'].astype(str).apply(clean_format)
        self.payments_data['amount'].astype(float)

        # fill empty strings
        self.payments_data['comment'].fillna('', inplace=True)
        self.payments_data['child_id'].fillna('', inplace=True)
        self.payments_data['date'].fillna('01/01/71 00:00:00', inplace=True)

        self.payments_data['date'] = self.payments_data['date'].apply(dateparse)

        # add default columns
        self.payments_data['currency'] = self.payments_data['sappayment'].apply(lambda x: 'zar' if int(x) is 1 else 'euro')
        self.payments_data['ptype'] = 'recurrent'
        self.payments_data['entitled'] = 'entitled'


        # drop payments with empty contributor
        self.payments_data = self.payments_data[pandas.notnull(self.payments_data['contributor_id'])]

        # lookup contributors
        self.payments_data['contributor'] = self.payments_data['contributor_id'].apply(lookup_contributor)

        # lookup children
        self.payments_data['child'] = self.payments_data['child_id'].apply(lookup_child)

        # drop unneeded columns
        self.payments_data.drop('child_id', axis=1, inplace=True)
        self.payments_data.drop('contributor_id', axis=1, inplace=True)
        self.payments_data.drop('sappayment', axis=1, inplace=True)

        # load payments
        failing_payments = {}
        ok_payments = []
        for payment_data in self.payments_data.to_dict(orient='records'):
            self.stdout.write('.', ending="")
            self.stdout.flush()
            try:
                payment = Payment(**payment_data)
                payment.full_clean()
                payment.save()
                ok_payments.append(payment_data)
            except Exception as e:
                failing_payments[str(payment_data)] = e
        if failing_payments:
            print('Payments failed validation:\n{0}'.format(pprint.pformat(failing_payments, indent=4)))