Merge pull request #40152 from frappe/mergify/bp/version-15-hotfix/pr-40095

fix: unique GL account for plaid bank accounts (backport #40095)
This commit is contained in:
Gursheen Kaur Anand 2024-02-27 17:08:37 +05:30 committed by GitHub
commit 07fd93a6f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 14 deletions

View File

@ -10,7 +10,6 @@ from frappe.model.document import Document
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 @@ def add_bank_accounts(response, bank, company):
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 @@ def add_bank_accounts(response, bank, company):
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", ""),

View File

@ -7,7 +7,6 @@ import unittest
import frappe
from frappe.utils.response import json_handler
from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_bank_cash_account
from erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings import (
add_account_subtype,
add_account_type,
@ -72,14 +71,6 @@ class TestPlaidSettings(unittest.TestCase):
bank = json.dumps(frappe.get_doc("Bank", "Citi").as_dict(), default=json_handler)
company = frappe.db.get_single_value("Global Defaults", "default_company")
if frappe.db.get_value("Company", company, "default_bank_account") is None:
frappe.db.set_value(
"Company",
company,
"default_bank_account",
get_default_bank_cash_account(company, "Cash").get("account"),
)
add_bank_accounts(bank_accounts, bank, company)
transactions = {