[fix] validate party account (#11517)
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index ce049f5..3a0b2d5 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -176,29 +176,34 @@
if not company:
frappe.throw(_("Please select a Company"))
- if party:
+ if not party:
+ frappe.throw(_("Please select a Party"))
+
+ account = frappe.db.get_value("Party Account",
+ {"parenttype": party_type, "parent": party, "company": company}, "account")
+
+ if not account and party_type in ['Customer', 'Supplier']:
+ party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type"
+ group = frappe.db.get_value(party_type, party, scrub(party_group_doctype))
account = frappe.db.get_value("Party Account",
- {"parenttype": party_type, "parent": party, "company": company}, "account")
+ {"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
- if not account and party_type in ['Customer', 'Supplier']:
- party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type"
- group = frappe.db.get_value(party_type, party, scrub(party_group_doctype))
- account = frappe.db.get_value("Party Account",
- {"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
+ if not account and party_type in ['Customer', 'Supplier']:
+ default_account_name = "default_receivable_account" \
+ if party_type=="Customer" else "default_payable_account"
+ account = frappe.db.get_value("Company", company, default_account_name)
- if not account and party_type in ['Customer', 'Supplier']:
- default_account_name = "default_receivable_account" \
- if party_type=="Customer" else "default_payable_account"
- account = frappe.db.get_value("Company", company, default_account_name)
+ existing_gle_currency = get_party_gle_currency(party_type, party, company)
+ if existing_gle_currency:
+ if account:
+ account_currency = frappe.db.get_value("Account", account, "account_currency")
+ if (account and account_currency != existing_gle_currency) or not account:
+ account = get_party_gle_account(party_type, party, company)
- existing_gle_currency = get_party_gle_currency(party_type, party, company)
- if existing_gle_currency:
- if account:
- account_currency = frappe.db.get_value("Account", account, "account_currency")
- if (account and account_currency != existing_gle_currency) or not account:
- account = get_party_gle_account(party_type, party, company)
+ if not account:
+ frappe.throw(_("Party account not specified, please setup default party account in company"))
- return account
+ return account
def get_party_account_currency(party_type, party, company):
def generator():