[fix] validate party account (#11517)

This commit is contained in:
Saurabh 2017-11-10 19:21:09 +05:30 committed by Nabin Hait
parent 731b66b788
commit 0f86d86e27

View File

@ -176,29 +176,34 @@ def get_party_account(party_type, party, company):
if not company: if not company:
frappe.throw(_("Please select a 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", 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']: if not account and party_type in ['Customer', 'Supplier']:
party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type" default_account_name = "default_receivable_account" \
group = frappe.db.get_value(party_type, party, scrub(party_group_doctype)) if party_type=="Customer" else "default_payable_account"
account = frappe.db.get_value("Party Account", account = frappe.db.get_value("Company", company, default_account_name)
{"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
if not account and party_type in ['Customer', 'Supplier']: existing_gle_currency = get_party_gle_currency(party_type, party, company)
default_account_name = "default_receivable_account" \ if existing_gle_currency:
if party_type=="Customer" else "default_payable_account" if account:
account = frappe.db.get_value("Company", company, default_account_name) 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 not account:
if existing_gle_currency: frappe.throw(_("Party account not specified, please setup default party account in company"))
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)
return account return account
def get_party_account_currency(party_type, party, company): def get_party_account_currency(party_type, party, company):
def generator(): def generator():