Skip to content

Commit

Permalink
Fix bug of reusing custom fee.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundobatista committed Jan 7, 2024
1 parent f02d537 commit 34be116
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
9 changes: 5 additions & 4 deletions website/members/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
42 changes: 38 additions & 4 deletions website/members/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = '[email protected]'
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 = '[email protected]'
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."""
Expand Down

0 comments on commit 34be116

Please sign in to comment.