fix: unique gl account for plaid bank accounts
diff --git a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py
index ec7d71e..dc5a329 100644
--- a/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py
+++ b/erpnext/erpnext_integrations/doctype/plaid_settings/plaid_settings.py
@@ -10,7 +10,6 @@
from frappe.utils import add_months, formatdate, getdate, sbool, today
from plaid.errors import ItemError
-from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_connector import PlaidConnector
@@ -90,9 +89,15 @@
bank = json.loads(bank)
result = []
- default_gl_account = get_default_bank_cash_account(company, "Bank")
- if not default_gl_account:
- frappe.throw(_("Please setup a default bank account for company {0}").format(company))
+ parent_gl_account = frappe.db.get_all(
+ "Account", {"company": company, "account_type": "Bank", "is_group": 1, "disabled": 0}
+ )
+ if not parent_gl_account:
+ frappe.throw(
+ _(
+ "Please setup and enable a group account with the Account Type - {0} for the company {1}"
+ ).format(frappe.bold("Bank"), company)
+ )
for account in response["accounts"]:
acc_type = frappe.db.get_value("Bank Account Type", account["type"])
@@ -108,11 +113,22 @@
if not existing_bank_account:
try:
+ gl_account = frappe.get_doc(
+ {
+ "doctype": "Account",
+ "account_name": account["name"] + " - " + response["institution"]["name"],
+ "parent_account": parent_gl_account[0].name,
+ "account_type": "Bank",
+ "company": company,
+ }
+ )
+ gl_account.insert(ignore_if_duplicate=True)
+
new_account = frappe.get_doc(
{
"doctype": "Bank Account",
"bank": bank["bank_name"],
- "account": default_gl_account.account,
+ "account": gl_account.name,
"account_name": account["name"],
"account_type": account.get("type", ""),
"account_subtype": account.get("subtype", ""),