<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe

def execute():
	frappe.reload_doc("accounts", "doctype", "account")
	frappe.reload_doc("setup", "doctype", "company")
	frappe.reload_doc("accounts", "doctype", "gl_entry")
	frappe.reload_doc("accounts", "doctype", "journal_entry_account")
	receivable_payable_accounts = create_receivable_payable_account()
	if receivable_payable_accounts:
		set_party_in_jv_and_gl_entry(receivable_payable_accounts)
		delete_individual_party_account()
		remove_customer_supplier_account_report()

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 = frappe.new_doc("Account")
			account.is_group = 0
			account.update(args)
			account.insert()

			frappe.db.set_value("Company", args["company"], ("default_receivable_account"
				if args["account_type"]=="Receivable" else "default_payable_account"), account.name)

			receivable_payable_accounts.setdefault(args["company"], {}).setdefault(args["account_type"], account.name)

	for company in frappe.db.sql_list("select name from tabCompany"):
		_create_account({
				"account_name": "Debtors",
				"account_type": "Receivable",
				"company": company,
				"parent_account": get_parent_account(company, "Customer")
			})

		_create_account({
			"account_name": "Creditors",
			"account_type": "Payable",
			"company": company,
			"parent_account": get_parent_account(company, "Supplier")
		})

	return receivable_payable_accounts

def get_parent_account(company, master_type):
	parent_account = None
	
	if "receivables_group" in frappe.db.get_table_columns("Company"):
		parent_account = frappe.db.get_value("Company", company,
			"receivables_group" if master_type=="Customer" else "payables_group")
	if not parent_account:
		parent_account = frappe.db.get_value("Account", {"company": company,
			"account_name": "Accounts Receivable" if master_type=="Customer" else "Accounts Payable"})
<commit_msg>party model patch fix<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe

def execute():
	frappe.reload_doc("accounts", "doctype", "account")
	frappe.reload_doc("setup", "doctype", "company")
	frappe.reload_doc("accounts", "doctype", "gl_entry")
	frappe.reload_doc("accounts", "doctype", "journal_entry_account")
	receivable_payable_accounts = create_receivable_payable_account()
	if receivable_payable_accounts:
		set_party_in_jv_and_gl_entry(receivable_payable_accounts)
		delete_individual_party_account()
		remove_customer_supplier_account_report()

def create_receivable_payable_account():
	receivable_payable_accounts = frappe._dict()

	def _create_account(args):
		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_id)

		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({
				"account_name": "Debtors",
				"account_type": "Receivable",
				"company": company,
				"parent_account": get_parent_account(company, "Customer")
			})

		_create_account({
			"account_name": "Creditors",
			"account_type": "Payable",
			"company": company,
			"parent_account": get_parent_account(company, "Supplier")
		})

	return receivable_payable_accounts

def get_parent_account(company, master_type):
	parent_account = None
	
	if "receivables_group" in frappe.db.get_table_columns("Company"):
		parent_account = frappe.db.get_value("Company", company,
			"receivables_group" if master_type=="Customer" else "payables_group")
	if not parent_account:
		parent_account = frappe.db.get_value("Account", {"company": company,
			"account_name": "Accounts Receivable" if master_type=="Customer" else "Accounts Payable"})

{'fraction_non_alphanumeric': 0.12702283307470627, 'fraction_numerical': 0.002660164043449346, 'mean_word_length': 6.726027397260274, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1062554', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1513, 'n_words': 279}