Skip to content

Commit 3b098bd

Browse files
committed
Match transaction by name - case insensitive
1 parent 140af9d commit 3b098bd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

thebook/bookkeeping/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def find_match_for(self, receivable_fee):
132132
self.filter(
133133
category__name="Contribuição Associativa",
134134
amount=receivable_fee.amount,
135-
description__regex=rule.pattern,
135+
description__iregex=rule.pattern,
136136
date__gte=receivable_fee.membership.start_date,
137137
)
138138
.exclude(

thebook/bookkeeping/tests/managers/test_transaction__find_match_for.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def membership_fee_category(db):
2222
def membership(db):
2323
return baker.make(
2424
Membership,
25+
member__name="Guybrush Threepwood",
2526
start_date=datetime.date(2025, 1, 1),
2627
membership_fee_amount=Decimal("100.0"),
2728
)
@@ -63,6 +64,29 @@ def test_find_exact_transaction_match(db, unpaid_rf, membership_fee_category):
6364
assert matched_transaction == transaction
6465

6566

67+
@pytest.mark.parametrize(
68+
"name", ["Guybrush Threepwood", "guybrush threepwood", "GUYBRUSH THREEPWOOD"]
69+
)
70+
def test_match_transaction_by_name_with_case_insensitive_search(
71+
db, unpaid_rf, membership_fee_category, name
72+
):
73+
transaction = baker.make(
74+
Transaction,
75+
date=datetime.date(2025, 7, 10),
76+
amount=Decimal("100.0"),
77+
category=membership_fee_category,
78+
description=f"Payment of membership for {name} fee",
79+
)
80+
rf_match_rule = ReceivableFeeTransactionMatchRule.objects.create(
81+
pattern=".*guybrush threepwood.*",
82+
membership=unpaid_rf.membership,
83+
)
84+
85+
matched_transaction = Transaction.objects.find_match_for(unpaid_rf)
86+
87+
assert matched_transaction == transaction
88+
89+
6690
def test_ignore_if_transaction_not_in_right_category(
6791
db, unpaid_rf, membership_fee_category
6892
):

0 commit comments

Comments
 (0)