mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-19 10:14:59 +00:00
fix: Use process.extract to get the corresponding party doc name of the result
- rapidfuzz accepts an iterable or a dict. dict input gives the dict key and value in the result
(cherry picked from commit e0a03789ae)
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
from typing import Tuple, Union
|
from typing import Tuple, Union
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.core.utils import find
|
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
from rapidfuzz import fuzz, process
|
from rapidfuzz import fuzz, process
|
||||||
|
|
||||||
@@ -135,7 +134,7 @@ class AutoMatchbyPartyNameDescription:
|
|||||||
skip = False
|
skip = False
|
||||||
result = process.extract(
|
result = process.extract(
|
||||||
query=self.get(field),
|
query=self.get(field),
|
||||||
choices=[name.get("party_name") for name in names],
|
choices={row.get("name"): row.get("party_name") for row in names},
|
||||||
scorer=fuzz.token_set_ratio,
|
scorer=fuzz.token_set_ratio,
|
||||||
)
|
)
|
||||||
party_name, skip = self.process_fuzzy_result(result)
|
party_name, skip = self.process_fuzzy_result(result)
|
||||||
@@ -143,8 +142,6 @@ class AutoMatchbyPartyNameDescription:
|
|||||||
if not party_name:
|
if not party_name:
|
||||||
return None, skip
|
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 (
|
return (
|
||||||
party,
|
party,
|
||||||
party_name,
|
party_name,
|
||||||
@@ -157,14 +154,14 @@ class AutoMatchbyPartyNameDescription:
|
|||||||
|
|
||||||
Returns: Result, Skip (whether or not to discontinue matching)
|
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):
|
if not result or not len(result):
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
first_result = result[0]
|
first_result = result[0]
|
||||||
if len(result) == 1:
|
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]
|
second_result = result[1]
|
||||||
if first_result[SCORE] > CUTOFF:
|
if first_result[SCORE] > CUTOFF:
|
||||||
@@ -173,7 +170,7 @@ class AutoMatchbyPartyNameDescription:
|
|||||||
if first_result[SCORE] == second_result[SCORE]:
|
if first_result[SCORE] == second_result[SCORE]:
|
||||||
return None, True
|
return None, True
|
||||||
|
|
||||||
return first_result[PARTY], True
|
return first_result[PARTY_ID], True
|
||||||
else:
|
else:
|
||||||
return None, False
|
return None, False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user