diff --git a/website/members/logic.py b/website/members/logic.py index 8f77cab..a6856c2 100644 --- a/website/members/logic.py +++ b/website/members/logic.py @@ -147,14 +147,15 @@ def create_recurring_payments(recurring_records, custom_fee=None): # use current category fee as custom fee (unless the user forced other one) to # ensure always *1* quota is recorded; however verify that current amount is # the same as the member's category fee and show a warning if needed - if custom_fee is None: - custom_fee = payment_info['amount'] - if custom_fee != member.category.fee: + this_custom_fee = custom_fee + if this_custom_fee is None: + this_custom_fee = payment_info['amount'] + if this_custom_fee != member.category.fee: logger.warning( "Payment with strange amount for member %s: %s", member, payment_info) create_payment( member, payment_info['timestamp'], payment_info['amount'], - strategy, custom_fee=custom_fee) + strategy, custom_fee=this_custom_fee) logger.info("Processed %d payers without new payments", count_without_new_payments) diff --git a/website/members/tests.py b/website/members/tests.py index eec8851..707ab32 100644 --- a/website/members/tests.py +++ b/website/members/tests.py @@ -38,19 +38,25 @@ DEFAULT_FEE = 100 -def create_category(): +def create_category(fee=DEFAULT_FEE): """Create a testing Category.""" - category = Category(name='testcategory', description="", fee=DEFAULT_FEE) + category = Category(name='testcategory', description="", fee=fee) category.save() return category def create_member( - first_payment_year=None, first_payment_month=None, patron=None, registration_date=None): + first_payment_year=None, + first_payment_month=None, + patron=None, + registration_date=None, + category=None, +): """Create a testing Member.""" first_payment_year = first_payment_year first_payment_month = first_payment_month - category = create_category() + if category is None: + category = create_category() return Member.objects.create( first_payment_year=first_payment_year, first_payment_month=first_payment_month, category=category, patron=patron, registration_date=registration_date) @@ -660,6 +666,34 @@ def test_strange_amount(self): (payed_fee,) = Quota.objects.all() self.assertEqual(payed_fee.payment.amount, weird_amount) + def test_multiple_different_amounts(self): + # needed objects + payer_id1 = 'test@example.com' + ps = create_payment_strategy(platform=PaymentStrategy.MERCADO_PAGO, payer_id=payer_id1) + member1 = create_member(patron=ps.patron, first_payment_year=2017, first_payment_month=5) + + payer_id2 = 'other@example.com' + category2 = create_category(DEFAULT_FEE * 2) + ps = create_payment_strategy(platform=PaymentStrategy.MERCADO_PAGO, payer_id=payer_id2) + member2 = create_member( + patron=ps.patron, first_payment_year=2017, first_payment_month=5, category=category2) + + # create the payment + tstampA = make_aware(datetime.datetime(year=2017, month=2, day=5)) + tstampB = make_aware(datetime.datetime(year=2017, month=2, day=6)) + records = [ + create_payment_record(payer_id2, timestamp=tstampB, amount=DEFAULT_FEE * 2), + create_payment_record(payer_id1, timestamp=tstampA, amount=DEFAULT_FEE * 1), + ] + logic.create_recurring_payments(records) + + # check + payed_fee_1, payed_fee_2 = Quota.objects.all() + self.assertEqual(payed_fee_1.member, member2) + self.assertEqual(payed_fee_1.payment.timestamp, tstampB) + self.assertEqual(payed_fee_2.member, member1) + self.assertEqual(payed_fee_2.payment.timestamp, tstampA) + class GetDebtStateTestCase(TestCase): """Tests for the debt state."""