|
|
|
|
@@ -83,7 +83,7 @@ def get_linked_payments(bank_transaction):
|
|
|
|
|
amount_matching = check_matching_amount(bank_account[0].account, bank_account[0].company, transaction)
|
|
|
|
|
|
|
|
|
|
# Get some data from payment entries linked to a corresponding bank transaction
|
|
|
|
|
description_matching = get_matching_descriptions_data(bank_account[0].account, transaction)
|
|
|
|
|
description_matching = get_matching_descriptions_data(bank_account[0].company, transaction)
|
|
|
|
|
|
|
|
|
|
if amount_matching:
|
|
|
|
|
return check_amount_vs_description(amount_matching, description_matching)
|
|
|
|
|
@@ -207,7 +207,7 @@ def check_matching_amount(bank_account, company, transaction):
|
|
|
|
|
|
|
|
|
|
return payments
|
|
|
|
|
|
|
|
|
|
def get_matching_descriptions_data(bank_account, transaction):
|
|
|
|
|
def get_matching_descriptions_data(company, transaction):
|
|
|
|
|
if not transaction.description :
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
@@ -243,17 +243,23 @@ def get_matching_descriptions_data(bank_account, transaction):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = []
|
|
|
|
|
company_currency = get_company_currency(company)
|
|
|
|
|
for key, value in iteritems(links):
|
|
|
|
|
if key == "Payment Entry":
|
|
|
|
|
data.extend(frappe.get_all("Payment Entry", filters=[["name", "in", value]], fields=["'Payment Entry' as doctype", "posting_date", "party", "reference_no", "reference_date", "paid_amount"]))
|
|
|
|
|
data.extend(frappe.get_all("Payment Entry", filters=[["name", "in", value]], fields=["'Payment Entry' as doctype", "posting_date", "party", "reference_no", "reference_date", "paid_amount", "paid_to_account_currency as currency"]))
|
|
|
|
|
if key == "Journal Entry":
|
|
|
|
|
data.extend(frappe.get_all("Journal Entry", filters=[["name", "in", value]], fields=["'Journal Entry' as doctype", "posting_date", "paid_to_recd_from as party", "cheque_no as reference_no", "cheque_date as reference_date"]))
|
|
|
|
|
journal_entries = frappe.get_all("Journal Entry", filters=[["name", "in", value]], fields=["name", "'Journal Entry' as doctype", "posting_date", "paid_to_recd_from as party", "cheque_no as reference_no", "cheque_date as reference_date", "total_credit as paid_amount"])
|
|
|
|
|
for journal_entry in journal_entries:
|
|
|
|
|
journal_entry_accounts = frappe.get_all("Journal Entry Account", filters={"parenttype": journal_entry["doctype"], "parent": journal_entry["name"]}, fields=["account_currency"])
|
|
|
|
|
journal_entry["currency"] = journal_entry_accounts[0]["account_currency"] if journal_entry_accounts else company_currency
|
|
|
|
|
data.extend(journal_entries)
|
|
|
|
|
if key == "Sales Invoice":
|
|
|
|
|
data.extend(frappe.get_all("Sales Invoice", filters=[["name", "in", value]], fields=["'Sales Invoice' as doctype", "posting_date", "customer_name as party"]))
|
|
|
|
|
data.extend(frappe.get_all("Sales Invoice", filters=[["name", "in", value]], fields=["'Sales Invoice' as doctype", "posting_date", "customer_name as party", "paid_amount", "currency"]))
|
|
|
|
|
if key == "Purchase Invoice":
|
|
|
|
|
data.append(frappe.get_all("Purchase Invoice", filters=[["name", "in", value]], fields=["'Purchase Invoice' as doctype", "posting_date", "supplier_name as party"]))
|
|
|
|
|
if key == "Purchase Invoice":
|
|
|
|
|
data.append(frappe.get_all("Expense Claim", filters=[["name", "in", value]], fields=["'Expense Claim' as doctype", "posting_date", "employee_name as party"]))
|
|
|
|
|
data.extend(frappe.get_all("Purchase Invoice", filters=[["name", "in", value]], fields=["'Purchase Invoice' as doctype", "posting_date", "supplier_name as party", "paid_amount", "currency"]))
|
|
|
|
|
if key == "Expense Claim":
|
|
|
|
|
expense_claims = frappe.get_all("Expense Claim", filters=[["name", "in", value]], fields=["'Expense Claim' as doctype", "posting_date", "employee_name as party", "total_amount_reimbursed as paid_amount"])
|
|
|
|
|
data.extend([dict(x,**{"currency": company_currency}) for x in expense_claims])
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
@@ -269,7 +275,7 @@ def check_amount_vs_description(amount_matching, description_matching):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if hasattr(am_match, "reference_no") and hasattr(des_match, "reference_no"):
|
|
|
|
|
if difflib.SequenceMatcher(lambda x: x == " ", am_match["reference_no"], des_match["reference_no"]) > 70:
|
|
|
|
|
if difflib.SequenceMatcher(lambda x: x == " ", am_match["reference_no"], des_match["reference_no"]).ratio() > 70:
|
|
|
|
|
if am_match not in result:
|
|
|
|
|
result.append(am_match)
|
|
|
|
|
if result:
|
|
|
|
|
|