From 0f86d86e2735640586ccb8a251b5e337cdde61cf Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 10 Nov 2017 19:21:09 +0530 Subject: [PATCH] [fix] validate party account (#11517) --- erpnext/accounts/party.py | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index ce049f5d87..3a0b2d5e1e 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -176,29 +176,34 @@ def get_party_account(party_type, party, company): 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():