<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, json

from frappe.utils import cstr, flt, getdate
from frappe import _
from frappe.utils.file_manager import save_file
from frappe.translate import set_default_language, get_dict, get_lang_dict
from frappe.country_info import get_country_info
from frappe.utils.nestedset import get_root_of
from default_website import website_maker
import install_fixtures

@frappe.whitelist()
def setup_account(args=None):

	if frappe.db.sql("select name from tabCompany"):
		frappe.throw(_("Setup Already Complete!!"))

	if not args:
		args = frappe.local.form_dict
	if isinstance(args, basestring):
		args = json.loads(args)
	args = frappe._dict(args)

	if args.language != "english":
		set_default_language(args.language)

	install_fixtures.install(args.get("country"))

	update_user_name(args)
	frappe.local.message_log = []

	create_fiscal_year_and_company(args)
	frappe.local.message_log = []

	create_naming_series(args)
	frappe.local.message_log = []

	set_defaults(args)
	frappe.local.message_log = []

	create_territories()
	frappe.local.message_log = []

	create_price_lists(args)
	frappe.local.message_log = []

	create_feed_and_todo()
	frappe.local.message_log = []

	create_email_digest()
	frappe.local.message_log = []

	create_letter_head(args)
	frappe.local.message_log = []

	create_taxes(args)
	frappe.local.message_log = []

	create_items(args)
	frappe.local.message_log = []

	create_customers(args)
	frappe.local.message_log = []

	create_suppliers(args)
	frappe.local.message_log = []

	frappe.db.set_default('desktop:home_page', 'desktop')

	website_maker(args.company_name, args.company_tagline, args.name)
	create_logo(args)

	frappe.clear_cache()
	frappe.db.commit()


def update_user_name(args):
	if args.get("email"):
		args['name'] = args.get("email")
		frappe.flags.mute_emails = True
		frappe.get_doc({
			"doctype":"User",
			"email": args.get("email"),
			"first_name": args.get("first_name"),
			"last_name": args.get("last_name")
		}).insert()
		frappe.flags.mute_emails = False
		from frappe.auth import _update_password
		_update_password(args.get("email"), args.get("password"))

	else:
		args['name'] = frappe.session.user

		# Update User
		if not args.get('last_name') or args.get('last_name')=='None':
				args['last_name'] = None
		frappe.db.sql("""update `tabUser` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""", args)

	if args.get("attach_user"):
		filename, filetype, content = args.get("attach_user").split(",")
		fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
		frappe.db.set_value("User", args.get("name"), "user_image", fileurl)

	add_all_roles_to(args.get("name"))

def create_fiscal_year_and_company(args):
	curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
	frappe.get_doc({
		"doctype":"Fiscal Year",
		'year': curr_fiscal_year,
		'year_start_date': args.get('fy_start_date'),
		'year_end_date': args.get('fy_end_date'),
	}).insert()

	# Company
	frappe.get_doc({
		"doctype":"Company",
		'domain': args.get("industry"),
		'company_name':args.get('company_name'),
		'abbr':args.get('company_abbr'),
		'default_currency':args.get('currency'),
		'country': args.get('country'),
		'chart_of_accounts': args.get(('chart_of_accounts')),
	}).insert()

	args["curr_fiscal_year"] = curr_fiscal_year

def create_naming_series(args):
	for doctype in ("Production Order", "Supplier Quotation", "Purchase Order",
		"Purchase Invoice", "Purchase Receipt", "Opportunity", "Quotation",
		"Sales Order", "Sales Invoice", "Delivery Note", "Installation Note",
		"Customer Issue", "Journal Voucher"):

		naming_series = frappe.get_doc("Naming Series")
		naming_series.select_doc_for_series = doctype

		# append fiscal year name to existing series
		existing_series = frappe.get_meta(doctype).get_field("naming_series").options.split("\n")
		naming_series.set_options = "\n".join(existing_series + ["{}{}-".format(existing_series[0], args["curr_fiscal_year"])])

		naming_series.update_series()

def create_price_lists(args):
	for pl_type in ["Selling", "Buying"]:
		frappe.get_doc({
			"doctype": "Price List",
			"price_list_name": "Standard " + pl_type,
			"enabled": 1,
			"buying": 1 if pl_type == "Buying" else 0,
			"selling": 1 if pl_type == "Selling" else 0,
			"currency": args["currency"],
			"valid_for_territories": [{
				"territory": get_root_of("Territory")
			}]
		}).insert()

def set_defaults(args):
	# enable default currency
	frappe.db.set_value("Currency", args.get("currency"), "enabled", 1)

	global_defaults = frappe.get_doc("Global Defaults", "Global Defaults")
	global_defaults.update({
		'current_fiscal_year': args.curr_fiscal_year,
		'default_currency': args.get('currency'),
		'default_company':args.get('company_name'),
		"country": args.get("country"),
	})
<commit_msg>Revert "Autocreate naming series options based on Fiscal Year"<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, json

from frappe.utils import cstr, flt, getdate
from frappe import _
from frappe.utils.file_manager import save_file
from frappe.translate import set_default_language, get_dict, get_lang_dict
from frappe.country_info import get_country_info
from frappe.utils.nestedset import get_root_of
from default_website import website_maker
import install_fixtures

@frappe.whitelist()
def setup_account(args=None):

	if frappe.db.sql("select name from tabCompany"):
		frappe.throw(_("Setup Already Complete!!"))

	if not args:
		args = frappe.local.form_dict
	if isinstance(args, basestring):
		args = json.loads(args)
	args = frappe._dict(args)

	if args.language != "english":
		set_default_language(args.language)

	install_fixtures.install(args.get("country"))

	update_user_name(args)
	frappe.local.message_log = []

	create_fiscal_year_and_company(args)
	frappe.local.message_log = []

	set_defaults(args)
	frappe.local.message_log = []

	create_territories()
	frappe.local.message_log = []

	create_price_lists(args)
	frappe.local.message_log = []

	create_feed_and_todo()
	frappe.local.message_log = []

	create_email_digest()
	frappe.local.message_log = []

	create_letter_head(args)
	frappe.local.message_log = []

	create_taxes(args)
	frappe.local.message_log = []

	create_items(args)
	frappe.local.message_log = []

	create_customers(args)
	frappe.local.message_log = []

	create_suppliers(args)
	frappe.local.message_log = []

	frappe.db.set_default('desktop:home_page', 'desktop')

	website_maker(args.company_name, args.company_tagline, args.name)
	create_logo(args)

	frappe.clear_cache()
	frappe.db.commit()


def update_user_name(args):
	if args.get("email"):
		args['name'] = args.get("email")
		frappe.flags.mute_emails = True
		frappe.get_doc({
			"doctype":"User",
			"email": args.get("email"),
			"first_name": args.get("first_name"),
			"last_name": args.get("last_name")
		}).insert()
		frappe.flags.mute_emails = False
		from frappe.auth import _update_password
		_update_password(args.get("email"), args.get("password"))

	else:
		args['name'] = frappe.session.user

		# Update User
		if not args.get('last_name') or args.get('last_name')=='None':
				args['last_name'] = None
		frappe.db.sql("""update `tabUser` SET first_name=%(first_name)s,
			last_name=%(last_name)s WHERE name=%(name)s""", args)

	if args.get("attach_user"):
		filename, filetype, content = args.get("attach_user").split(",")
		fileurl = save_file(filename, content, "User", args.get("name"), decode=True).file_url
		frappe.db.set_value("User", args.get("name"), "user_image", fileurl)

	add_all_roles_to(args.get("name"))

def create_fiscal_year_and_company(args):
	curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
	frappe.get_doc({
		"doctype":"Fiscal Year",
		'year': curr_fiscal_year,
		'year_start_date': args.get('fy_start_date'),
		'year_end_date': args.get('fy_end_date'),
	}).insert()

	# Company
	frappe.get_doc({
		"doctype":"Company",
		'domain': args.get("industry"),
		'company_name':args.get('company_name'),
		'abbr':args.get('company_abbr'),
		'default_currency':args.get('currency'),
		'country': args.get('country'),
		'chart_of_accounts': args.get(('chart_of_accounts')),
	}).insert()

	args["curr_fiscal_year"] = curr_fiscal_year

def create_price_lists(args):
	for pl_type in ["Selling", "Buying"]:
		frappe.get_doc({
			"doctype": "Price List",
			"price_list_name": "Standard " + pl_type,
			"enabled": 1,
			"buying": 1 if pl_type == "Buying" else 0,
			"selling": 1 if pl_type == "Selling" else 0,
			"currency": args["currency"],
			"valid_for_territories": [{
				"territory": get_root_of("Territory")
			}]
		}).insert()

def set_defaults(args):
	# enable default currency
	frappe.db.set_value("Currency", args.get("currency"), "enabled", 1)

	global_defaults = frappe.get_doc("Global Defaults", "Global Defaults")
	global_defaults.update({
		'current_fiscal_year': args.curr_fiscal_year,
		'default_currency': args.get('currency'),
		'default_company':args.get('company_name'),
		"country": args.get("country"),
	})

{'fraction_non_alphanumeric': 0.15117891816920942, 'fraction_numerical': 0.0024538568227888617, 'mean_word_length': 5.842335766423358, 'pattern_counts': {'":': 32, '<': 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': '3862830', 'n_tokens_mistral': 3600, 'n_tokens_neox': 3440, 'n_words': 596}