Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set right party name in bank transaction (backport #37299) #37913

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions erpnext/accounts/doctype/bank_transaction/auto_match_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def match_party_name_desc_in_party(self) -> Union[Tuple, None]:

for party in parties:
filters = {"status": "Active"} if party == "Employee" else {"disabled": 0}
names = frappe.get_all(party, filters=filters, pluck=party.lower() + "_name")
field = party.lower() + "_name"
names = frappe.get_all(party, filters=filters, fields=[f"{field} as party_name", "name"])

for field in ["bank_party_name", "description"]:
if not self.get(field):
Expand All @@ -131,7 +132,11 @@ def match_party_name_desc_in_party(self) -> Union[Tuple, None]:

def fuzzy_search_and_return_result(self, party, names, field) -> Union[Tuple, None]:
skip = False
result = process.extract(query=self.get(field), choices=names, scorer=fuzz.token_set_ratio)
result = process.extract(
query=self.get(field),
choices={row.get("name"): row.get("party_name") for row in names},
scorer=fuzz.token_set_ratio,
)
party_name, skip = self.process_fuzzy_result(result)

if not party_name:
Expand All @@ -149,14 +154,14 @@ def process_fuzzy_result(self, result: Union[list, None]):

Returns: Result, Skip (whether or not to discontinue matching)
"""
PARTY, SCORE, CUTOFF = 0, 1, 80
SCORE, PARTY_ID, CUTOFF = 1, 2, 80

if not result or not len(result):
return None, False

first_result = result[0]
if len(result) == 1:
return (first_result[PARTY] if first_result[SCORE] > CUTOFF else None), True
return (first_result[PARTY_ID] if first_result[SCORE] > CUTOFF else None), True

second_result = result[1]
if first_result[SCORE] > CUTOFF:
Expand All @@ -165,7 +170,7 @@ def process_fuzzy_result(self, result: Union[list, None]):
if first_result[SCORE] == second_result[SCORE]:
return None, True

return first_result[PARTY], True
return first_result[PARTY_ID], True
else:
return None, False

Expand Down
Loading