diff --git a/erpnext/patches/v4_2/party_model.py b/erpnext/patches/v4_2/party_model.py index d105349245..4412ae454a 100644 --- a/erpnext/patches/v4_2/party_model.py +++ b/erpnext/patches/v4_2/party_model.py @@ -19,17 +19,20 @@ def create_receivable_payable_account(): receivable_payable_accounts = frappe._dict() def _create_account(args): - if not frappe.db.get_value("Account", - {"account_name": args["account_name"], "company": args["company"]}): + account_id = frappe.db.get_value("Account", + {"account_name": args["account_name"], "company": args["company"]}) + if not account_id: account = frappe.new_doc("Account") account.is_group = 0 account.update(args) account.insert() - + + account_id = account.name + frappe.db.set_value("Company", args["company"], ("default_receivable_account" - if args["account_type"]=="Receivable" else "default_payable_account"), account.name) + if args["account_type"]=="Receivable" else "default_payable_account"), account_id) - receivable_payable_accounts.setdefault(args["company"], {}).setdefault(args["account_type"], account.name) + receivable_payable_accounts.setdefault(args["company"], {}).setdefault(args["account_type"], account_id) for company in frappe.db.sql_list("select name from tabCompany"): _create_account({