chore: Single query with or filter to search Party Mapper by name/desc
This commit is contained in:
parent
e7745033df
commit
3a898289b0
@ -1,4 +1,5 @@
|
|||||||
import frappe
|
import frappe
|
||||||
|
from frappe.utils import flt
|
||||||
from rapidfuzz import fuzz, process
|
from rapidfuzz import fuzz, process
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ class AutoMatchbyAccountIBAN:
|
|||||||
result = None
|
result = None
|
||||||
|
|
||||||
parties = ["Supplier", "Employee", "Customer"] # most -> least likely to receive
|
parties = ["Supplier", "Employee", "Customer"] # most -> least likely to receive
|
||||||
if self.deposit > 0:
|
if flt(self.deposit) > 0:
|
||||||
parties = ["Customer", "Supplier", "Employee"] # most -> least likely to pay
|
parties = ["Customer", "Supplier", "Employee"] # most -> least likely to pay
|
||||||
|
|
||||||
for party in parties:
|
for party in parties:
|
||||||
@ -103,22 +104,27 @@ class AutoMatchbyPartyDescription:
|
|||||||
def match_party_name_desc_in_bank_party_mapper(self):
|
def match_party_name_desc_in_bank_party_mapper(self):
|
||||||
"""Check if match exists for party name or description in Bank Party Mapper"""
|
"""Check if match exists for party name or description in Bank Party Mapper"""
|
||||||
result = None
|
result = None
|
||||||
# TODO: or filters
|
or_filters = []
|
||||||
|
|
||||||
if self.bank_party_name:
|
if self.bank_party_name:
|
||||||
result = frappe.db.get_value(
|
or_filters.append(["bank_party_name_desc", self.bank_party_name])
|
||||||
"Bank Party Mapper",
|
|
||||||
filters={"bank_party_name_desc": self.bank_party_name},
|
|
||||||
fieldname=["party_type", "party"],
|
|
||||||
)
|
|
||||||
|
|
||||||
if not result and self.description:
|
if self.description:
|
||||||
result = frappe.db.get_value(
|
or_filters.append(["bank_party_name_desc", self.description])
|
||||||
"Bank Party Mapper",
|
|
||||||
filters={"bank_party_name_desc": self.description},
|
|
||||||
fieldname=["party_type", "party"],
|
|
||||||
)
|
|
||||||
|
|
||||||
result = result + (None,) if result else result
|
mapper_res = frappe.get_all(
|
||||||
|
"Bank Party Mapper",
|
||||||
|
or_filters=or_filters,
|
||||||
|
fields=["party_type", "party"],
|
||||||
|
limit_page_length=1,
|
||||||
|
)
|
||||||
|
if mapper_res:
|
||||||
|
mapper_res = mapper_res[0]
|
||||||
|
result = (
|
||||||
|
mapper_res["party_type"],
|
||||||
|
mapper_res["party"],
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -127,7 +133,7 @@ class AutoMatchbyPartyDescription:
|
|||||||
result = None
|
result = None
|
||||||
|
|
||||||
parties = ["Supplier", "Employee", "Customer"] # most-least likely to receive
|
parties = ["Supplier", "Employee", "Customer"] # most-least likely to receive
|
||||||
if frappe.utils.flt(self.deposit) > 0.0:
|
if flt(self.deposit) > 0.0:
|
||||||
parties = ["Customer", "Supplier", "Employee"] # most-least likely to pay
|
parties = ["Customer", "Supplier", "Employee"] # most-least likely to pay
|
||||||
|
|
||||||
for party in parties:
|
for party in parties:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user