fix: unique gl account for plaid bank accounts
This commit is contained in:
parent
7cb07425b1
commit
bf6e32a960
@ -10,7 +10,6 @@ from frappe.model.document import Document
|
|||||||
from frappe.utils import add_months, formatdate, getdate, sbool, today
|
from frappe.utils import add_months, formatdate, getdate, sbool, today
|
||||||
from plaid.errors import ItemError
|
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
|
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)
|
bank = json.loads(bank)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
default_gl_account = get_default_bank_cash_account(company, "Bank")
|
parent_gl_account = frappe.db.get_all(
|
||||||
if not default_gl_account:
|
"Account", {"company": company, "account_type": "Bank", "is_group": 1, "disabled": 0}
|
||||||
frappe.throw(_("Please setup a default bank account for company {0}").format(company))
|
)
|
||||||
|
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"]:
|
for account in response["accounts"]:
|
||||||
acc_type = frappe.db.get_value("Bank Account Type", account["type"])
|
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:
|
if not existing_bank_account:
|
||||||
try:
|
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(
|
new_account = frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Bank Account",
|
"doctype": "Bank Account",
|
||||||
"bank": bank["bank_name"],
|
"bank": bank["bank_name"],
|
||||||
"account": default_gl_account.account,
|
"account": gl_account.name,
|
||||||
"account_name": account["name"],
|
"account_name": account["name"],
|
||||||
"account_type": account.get("type", ""),
|
"account_type": account.get("type", ""),
|
||||||
"account_subtype": account.get("subtype", ""),
|
"account_subtype": account.get("subtype", ""),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user