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 #37299

Merged
merged 2 commits into from
Nov 4, 2023
Merged
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions erpnext/accounts/doctype/bank_transaction/auto_match_party.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Tuple, Union

import frappe
from frappe.core.utils import find
from frappe.utils import flt
from rapidfuzz import fuzz, process

Expand Down Expand Up @@ -112,7 +113,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,12 +133,18 @@ 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=[name.get("party_name") for name in names],
scorer=fuzz.token_set_ratio,
)
party_name, skip = self.process_fuzzy_result(result)

if not party_name:
return None, skip

# Get Party Docname from the list of dicts
party_name = find(names, lambda x: x["party_name"] == party_name).get("name")
return (
party,
party_name,
Expand Down
Loading