From 4a14e9ea4e8f131913f7a0ede725db9a7603e85a Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 17 May 2023 14:23:44 +0530 Subject: [PATCH] fix: Tests --- .../bank_transaction/auto_match_party.py | 2 +- .../bank_transaction/test_auto_match_party.py | 40 ++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/bank_transaction/auto_match_party.py b/erpnext/accounts/doctype/bank_transaction/auto_match_party.py index e43d9beb05..79d52c6565 100644 --- a/erpnext/accounts/doctype/bank_transaction/auto_match_party.py +++ b/erpnext/accounts/doctype/bank_transaction/auto_match_party.py @@ -105,7 +105,7 @@ class AutoMatchbyAccountIBAN: or_filters["iban"] = self.bank_party_iban party_result = frappe.db.get_all( - "Bank Account", or_filters=or_filters, pluck="name", limit_page_length=1 + "Bank Account", or_filters=or_filters, pluck="party", limit_page_length=1 ) if party == "Employee" and not party_result: diff --git a/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py b/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py index 86181c865d..2f94516ac2 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py +++ b/erpnext/accounts/doctype/bank_transaction/test_auto_match_party.py @@ -146,22 +146,50 @@ class TestAutoMatchParty(FrappeTestCase): self.assertEqual(doc_2.party, "Amazon") -def create_supplier_for_match(supplier_name="John Doe & Co.", account_no=None, iban=None): - if frappe.db.exists("Supplier", supplier_name): - frappe.db.set_value("Supplier", supplier_name, {"bank_account_no": account_no, "iban": iban}) +def create_supplier_for_match(supplier_name="John Doe & Co.", iban=None, account_no=None): + if frappe.db.exists("Supplier", {"supplier_name": supplier_name}): + # Update related Bank Account details + if not (iban or account_no): + return + + frappe.db.set_value( + dt="Bank Account", + dn={"party": supplier_name}, + field={"iban": iban, "bank_account_no": account_no}, + ) return - frappe.get_doc( + # Create Supplier and Bank Account for the same + supplier = frappe.get_doc( { "doctype": "Supplier", "supplier_name": supplier_name, "supplier_group": "Services", "supplier_type": "Company", - "bank_account_no": account_no, - "iban": iban, } ).insert() + if not frappe.db.exists("Bank", "TestBank"): + frappe.get_doc( + { + "doctype": "Bank", + "bank_name": "TestBank", + } + ).insert(ignore_if_duplicate=True) + + if not frappe.db.exists("Bank Account", supplier.name + " - " + "TestBank"): + frappe.get_doc( + { + "doctype": "Bank Account", + "account_name": supplier.name, + "bank": "TestBank", + "iban": iban, + "bank_account_no": account_no, + "party_type": "Supplier", + "party": supplier.name, + } + ).insert() + def create_bank_transaction( description=None,