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

from __future__ import unicode_literals
import frappe
import erpnext

def execute():
	"""Create domain documents"""
	frappe.reload_doctype("Domain")

	for domain in ("Distribution", "Manufacturing", "Retail", "Services", "Education"):
		if not frappe.db.exists({'doctype': 'Domain', 'domain': domain}):
			doc = frappe.new_doc("Domain")
			doc.domain = domain
			doc.save()


	# set domain in domain settings based on company domain

	domains = []
	condition = ""
	company = erpnext.get_default_company()
	if company:
		condition = " and name='{0}'".format(company)

	domains = frappe.db.sql_list("select distinct domain from `tabCompany` where domain != 'Other' {0}".format(condition))

	if not domains:
		return

	domain_settings = frappe.get_doc("Domain Settings", "Domain Settings")
	checked_domains = [row.domain for row in domain_settings.active_domains]

	for domain in domains:
		# check and ignore if the domains is already checked in domain settings
		if domain in checked_domains:
			continue

		row = domain_settings.append("active_domains", dict(domain=domain))

	domain_settings.save(ignore_permissions=True)<commit_msg>[minor] use reload_doc instead of reload_doctype<commit_after># Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe
import erpnext

def execute():
	"""Create domain documents"""
	frappe.reload_doc("core", "doctype", "domain")
	frappe.reload_doc("core", "doctype", "domain_settings")
	frappe.reload_doc("core", "doctype", "has_domain")

	for domain in ("Distribution", "Manufacturing", "Retail", "Services", "Education"):
		if not frappe.db.exists({"doctype": "Domain", "domain": domain}):
			create_domain(domain)

	# set domain in domain settings based on company domain

	domains = []
	condition = ""
	company = erpnext.get_default_company()
	if company:
		condition = " and name='{0}'".format(company)

	domains = frappe.db.sql_list("select distinct domain from `tabCompany` where domain != 'Other' {0}".format(condition))

	if not domains:
		return

	domain_settings = frappe.get_doc("Domain Settings", "Domain Settings")
	checked_domains = [row.domain for row in domain_settings.active_domains]

	for domain in domains:
		# check and ignore if the domains is already checked in domain settings
		if domain in checked_domains:
			continue

		if not frappe.db.get_value("Domain", domain):
			# user added custom domain in companies domain field
			create_domain(domain)

		row = domain_settings.append("active_domains", dict(domain=domain))

	domain_settings.save(ignore_permissions=True)

def create_domain(domain):
	# create new domain

	doc = frappe.new_doc("Domain")
	doc.domain = domain
	doc.db_update()
{'fraction_non_alphanumeric': 0.11464750171115674, 'fraction_numerical': 0.004791238877481177, 'mean_word_length': 5.340563991323211, 'pattern_counts': {'":': 2, '<': 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': '357863', 'n_tokens_mistral': 948, 'n_tokens_neox': 872, 'n_words': 271}