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
|
||||
from frappe.utils import flt
|
||||
from rapidfuzz import fuzz, process
|
||||
|
||||
|
||||
@ -65,7 +66,7 @@ class AutoMatchbyAccountIBAN:
|
||||
result = None
|
||||
|
||||
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
|
||||
|
||||
for party in parties:
|
||||
@ -103,22 +104,27 @@ class AutoMatchbyPartyDescription:
|
||||
def match_party_name_desc_in_bank_party_mapper(self):
|
||||
"""Check if match exists for party name or description in Bank Party Mapper"""
|
||||
result = None
|
||||
# TODO: or filters
|
||||
or_filters = []
|
||||
|
||||
if self.bank_party_name:
|
||||
result = frappe.db.get_value(
|
||||
"Bank Party Mapper",
|
||||
filters={"bank_party_name_desc": self.bank_party_name},
|
||||
fieldname=["party_type", "party"],
|
||||
)
|
||||
or_filters.append(["bank_party_name_desc", self.bank_party_name])
|
||||
|
||||
if not result and self.description:
|
||||
result = frappe.db.get_value(
|
||||
"Bank Party Mapper",
|
||||
filters={"bank_party_name_desc": self.description},
|
||||
fieldname=["party_type", "party"],
|
||||
)
|
||||
if self.description:
|
||||
or_filters.append(["bank_party_name_desc", self.description])
|
||||
|
||||
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
|
||||
|
||||
@ -127,7 +133,7 @@ class AutoMatchbyPartyDescription:
|
||||
result = None
|
||||
|
||||
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
|
||||
|
||||
for party in parties:
|
||||
|
Loading…
x
Reference in New Issue
Block a user