From 39b8765961d560ac7ea961f8405a327c7f277e49 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 12 Nov 2018 17:19:56 +0530 Subject: [PATCH 01/21] [setup][init] setup as document records --- erpnext/regional/india/setup.py | 9 +- .../operations/install_fixtures.py | 257 +++++++++++++----- erpnext/setup/setup_wizard/setup_wizard.py | 83 +++--- 3 files changed, 241 insertions(+), 108 deletions(-) diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index 5fc06eabb7..79e414104e 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -11,14 +11,17 @@ from erpnext.accounts.utils import get_fiscal_year from frappe.utils import today def setup(company=None, patch=True): + if not patch: + update_address_template() + make_fixtures() + +# TODO: for all countries +def setup_company_independent_fixtures(): make_custom_fields() add_permissions() add_custom_roles_for_reports() frappe.enqueue('erpnext.regional.india.setup.add_hsn_sac_codes', now=frappe.flags.in_test) add_print_formats() - if not patch: - update_address_template() - make_fixtures(company) def update_address_template(): with open(os.path.join(os.path.dirname(__file__), 'address_template.html'), 'r') as f: diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index f7e2906da7..325b353e8e 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -6,6 +6,10 @@ from __future__ import unicode_literals import frappe, os, json from frappe import _ +from frappe.desk.page.setup_wizard.setup_wizard import make_records +from frappe.utils import cstr, getdate +from frappe.utils.nestedset import get_root_of +from erpnext.accounts.doctype.account.account import RootNotEditable default_lead_sources = ["Existing Customer", "Reference", "Advertisement", "Cold Calling", "Exhibition", "Supplier Reference", "Mass Mailing", @@ -15,6 +19,8 @@ default_sales_partner_type = ["Channel Partner", "Distributor", "Dealer", "Agent "Retailer", "Implementation Partner", "Reseller"] def install(country=None): + root_territory = get_root_of("Territory") + records = [ # domains { 'doctype': 'Domain', 'domain': 'Distribution'}, @@ -26,34 +32,6 @@ def install(country=None): { 'doctype': 'Domain', 'domain': 'Agriculture'}, { 'doctype': 'Domain', 'domain': 'Non Profit'}, - # Setup Progress - {'doctype': "Setup Progress", "actions": [ - {"action_name": "Add Company", "action_doctype": "Company", "min_doc_count": 1, "is_completed": 1, - "domains": '[]' }, - {"action_name": "Set Sales Target", "action_doctype": "Company", "min_doc_count": 99, - "action_document": frappe.defaults.get_defaults().get("company") or '', - "action_field": "monthly_sales_target", "is_completed": 0, - "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, - {"action_name": "Add Customers", "action_doctype": "Customer", "min_doc_count": 1, "is_completed": 0, - "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, - {"action_name": "Add Suppliers", "action_doctype": "Supplier", "min_doc_count": 1, "is_completed": 0, - "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, - {"action_name": "Add Products", "action_doctype": "Item", "min_doc_count": 1, "is_completed": 0, - "domains": '["Manufacturing", "Services", "Retail", "Distribution"]' }, - {"action_name": "Add Programs", "action_doctype": "Program", "min_doc_count": 1, "is_completed": 0, - "domains": '["Education"]' }, - {"action_name": "Add Instructors", "action_doctype": "Instructor", "min_doc_count": 1, "is_completed": 0, - "domains": '["Education"]' }, - {"action_name": "Add Courses", "action_doctype": "Course", "min_doc_count": 1, "is_completed": 0, - "domains": '["Education"]' }, - {"action_name": "Add Rooms", "action_doctype": "Room", "min_doc_count": 1, "is_completed": 0, - "domains": '["Education"]' }, - {"action_name": "Add Users", "action_doctype": "User", "min_doc_count": 4, "is_completed": 0, - "domains": '[]' }, - {"action_name": "Add Letterhead", "action_doctype": "Letter Head", "min_doc_count": 1, "is_completed": 0, - "domains": '[]' } - ]}, - # address template {'doctype':"Address Template", "country": country}, @@ -124,8 +102,10 @@ def install(country=None): {'doctype': 'Designation', 'designation_name': _('Designer')}, {'doctype': 'Designation', 'designation_name': _('Researcher')}, - # territory + # territory: with two default territories, one for home country and one named Rest of the World {'doctype': 'Territory', 'territory_name': _('All Territories'), 'is_group': 1, 'name': _('All Territories'), 'parent_territory': ''}, + {'doctype': 'Territory', 'territory_name': country.replace("'", ""), 'is_group': 0, 'parent_territory': root_territory}, + {'doctype': 'Territory', 'territory_name': _("Rest Of The World"), 'is_group': 0, 'parent_territory': root_territory}, # customer group {'doctype': 'Customer Group', 'customer_group_name': _('All Customer Groups'), 'is_group': 1, 'name': _('All Customer Groups'), 'parent_customer_group': ''}, @@ -231,7 +211,7 @@ def install(country=None): # Share Management {"doctype": "Share Type", "title": _("Equity")}, - {"doctype": "Share Type", "title": _("Preference")} + {"doctype": "Share Type", "title": _("Preference")}, ] from erpnext.setup.setup_wizard.data.industry_type import get_industry_types @@ -260,7 +240,17 @@ def install(country=None): from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import make_default_records make_default_records() - make_fixture_records(records) + make_records(records, True) + + set_more_defaults() + + path = frappe.get_app_path('erpnext', 'regional', frappe.scrub(country)) + if os.path.exists(path.encode("utf-8")): + frappe.get_attr("erpnext.regional.{0}.setup.setup_company_independent_fixtures".format(frappe.scrub(country)))() + + +def set_more_defaults(): + # Do more setup stuff that can be done here with no dependencies # set default customer group and territory selling_settings = frappe.get_doc("Selling Settings") @@ -269,6 +259,33 @@ def install(country=None): add_uom_data() + # set no copy fields of an item doctype to item variant settings + doc = frappe.get_doc('Item Variant Settings') + doc.set_default_fields() + doc.save() + + selling_settings = frappe.get_doc("Selling Settings") + selling_settings.cust_master_name = "Customer Name" + selling_settings.so_required = "No" + selling_settings.dn_required = "No" + selling_settings.allow_multiple_items = 1 + selling_settings.sales_update_frequency = "Each Transaction" + selling_settings.save() + + buying_settings = frappe.get_doc("Buying Settings") + buying_settings.supp_master_name = "Supplier Name" + buying_settings.po_required = "No" + buying_settings.pr_required = "No" + buying_settings.maintain_same_rate = 1 + buying_settings.allow_multiple_items = 1 + buying_settings.save() + + hr_settings = frappe.get_doc("HR Settings") + hr_settings.emp_created_by = "Naming Series" + hr_settings.leave_approval_notification_template = _("Leave Approval Notification") + hr_settings.leave_status_notification_template = _("Leave Status Notification") + hr_settings.save() + def add_uom_data(): # add UOMs uoms = json.loads(open(frappe.get_app_path("erpnext", "setup", "setup_wizard", "data", "uom_data.json")).read()) @@ -306,7 +323,7 @@ def add_market_segments(): {"doctype": "Market Segment", "market_segment": _("Upper Income")} ] - make_fixture_records(records) + make_records(records) def add_sale_stages(): # Sale Stages @@ -320,46 +337,154 @@ def add_sale_stages(): {"doctype": "Sales Stage", "stage_name": _("Proposal/Price Quote")}, {"doctype": "Sales Stage", "stage_name": _("Negotiation/Review")} ] - make_fixture_records(records) + make_records(records) -def make_fixture_records(records): - from frappe.modules import scrub - for r in records: - doc = frappe.new_doc(r.get("doctype")) - doc.update(r) - # ignore mandatory for root - parent_link_field = ("parent_" + scrub(doc.doctype)) - if doc.meta.get_field(parent_link_field) and not doc.get(parent_link_field): - doc.flags.ignore_mandatory = True +def install_company(args): + records = [ + # Fiscal Year + { "doctype": "Fiscal Year", 'year': get_fy_details(args.fy_start_date, args.fy_end_date), 'year_start_date': args.fy_start_date, 'year_end_date': args.fy_end_date }, - try: - doc.insert(ignore_permissions=True) - except frappe.DuplicateEntryError as e: - # pass DuplicateEntryError and continue - if e.args and e.args[0]==doc.doctype and e.args[1]==doc.name: - # make sure DuplicateEntryError is for the exact same doc and not a related doc - pass - else: - raise + # Company + { + "doctype":"Company", + 'company_name': args.company_name, 'enable_perpetual_inventory': 1, + 'abbr': args.company_abbr, 'default_currency': args.currency, 'country': args.country, + 'create_chart_of_accounts_based_on': 'Standard Template', + 'domain': args.domain + } + ] -def install_post_company_fixtures(company=None): + make_records(records, True) + + +def install_post_company_fixtures(args=None): records = [ # Department {'doctype': 'Department', 'department_name': _('All Departments'), 'is_group': 1, 'parent_department': ''}, - {'doctype': 'Department', 'department_name': _('Accounts'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Marketing'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Sales'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Purchase'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Operations'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Production'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Dispatch'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Customer Service'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Human Resources'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Management'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Quality Management'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Research & Development'), 'parent_department': _('All Departments'), 'company': company}, - {'doctype': 'Department', 'department_name': _('Legal'), 'parent_department': _('All Departments'), 'company': company}, + {'doctype': 'Department', 'department_name': _('Accounts'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Marketing'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Sales'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Purchase'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Operations'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Production'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Dispatch'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Customer Service'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Human Resources'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Management'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Quality Management'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Research & Development'), 'parent_department': _('All Departments'), 'company': args.company_name}, + {'doctype': 'Department', 'department_name': _('Legal'), 'parent_department': _('All Departments'), 'company': args.company_name}, + + # Price Lists + { "doctype": "Price List", "price_list_name": _("Standard Buying"), "enabled": 1, "buying": 1, "selling": 0, "currency": args.currency }, + { "doctype": "Price List", "price_list_name": _("Standard Selling"), "enabled": 1, "buying": 0, "selling": 1, "currency": args.currency }, + ] - make_fixture_records(records) \ No newline at end of file + make_records(records) + + # 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': get_fy_details(args.get('fy_start_date'), args.get('fy_end_date')), + 'default_currency': args.get('currency'), + 'default_company':args.get('company_name') , + "country": args.get("country"), + }) + + global_defaults.save() + + system_settings = frappe.get_doc("System Settings") + system_settings.email_footer_address = args.get("company_name") + system_settings.save() + + domain_settings = frappe.get_single('Domain Settings') + domain_settings.set_active_domains([args.domain]) + + stock_settings = frappe.get_doc("Stock Settings") + stock_settings.item_naming_by = "Item Code" + stock_settings.valuation_method = "FIFO" + stock_settings.default_warehouse = frappe.db.get_value('Warehouse', {'warehouse_name': _('Stores')}) + stock_settings.stock_uom = _("Nos") + stock_settings.auto_indent = 1 + stock_settings.auto_insert_price_list_rate_if_missing = 1 + stock_settings.automatically_set_serial_nos_based_on_fifo = 1 + stock_settings.set_qty_in_transactions_based_on_serial_no_input = 1 + stock_settings.save() + + + if args.bank_account: + company_name = args.company_name + bank_account_group = frappe.db.get_value("Account", + {"account_type": "Bank", "is_group": 1, "root_type": "Asset", + "company": company_name}) + if bank_account_group: + bank_account = frappe.get_doc({ + "doctype": "Account", + 'account_name': args.bank_account, + 'parent_account': bank_account_group, + 'is_group':0, + 'company': company_name, + "account_type": "Bank", + }) + try: + return bank_account.insert() + except RootNotEditable: + frappe.throw(_("Bank account cannot be named as {0}").format(args.bank_account)) + except frappe.DuplicateEntryError: + # bank account same as a CoA entry + pass + + + # Now, with fixtures out of the way, onto concrete stuff + records = [ + # # Bank Account + # { + # "doctype": "Account", + # "__condition": lambda: c.bank_account and frappe.db.get_value("Account", + # {"account_type": "Bank", "is_group": 1, "root_type": "Asset", + # "company": c.company_name}), + + # "__exception": { + # "exception": RootNotEditable, + # "handler": lambda: frappe.throw(_("Bank account cannot be named as {0}").format(config.get("bank_account"))) + # }, + # 'account_name': c.bank_account, + + # 'parent_account': lambda: frappe.db.get_value("Account", + # {"account_type": "Bank", "is_group": 1, "root_type": "Asset", + # "company": c.company_name}), + + # 'is_group':0, + # 'company': c.company_name, + # "account_type": "Bank", + # }, + + # # Shopping cart: needs price lists + { + "doctype": "Shopping Cart Settings", + "enabled": 1, + 'company': args.company_name, + # uh oh + 'price_list': frappe.db.get_value("Price List", {"selling": 1}), + 'default_customer_group': _("Individual"), + 'quotation_series': "QTN-", + }, + + # # TODO: Email digest, logo, website + # {} + ] + + make_records(records, True) + + +def get_fy_details(fy_start_date, fy_end_date): + start_year = getdate(fy_start_date).year + if start_year == getdate(fy_end_date).year: + fy = cstr(start_year) + else: + fy = cstr(start_year) + '-' + cstr(start_year + 1) + return fy diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index af28e4f586..d19dd185e9 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -4,8 +4,15 @@ from __future__ import unicode_literals import frappe +import json from frappe import _ -from .operations import install_fixtures, taxes_setup, defaults_setup, company_setup, sample_data + +from .operations import install_fixtures as fixtures, taxes_setup, company_setup, sample_data + +from frappe import _, _dict +from frappe.utils import cstr, getdate +from argparse import Namespace +from frappe.desk.page.setup_wizard.setup_wizard import update_global_settings, run_post_setup_complete, make_records def get_setup_stages(args=None): if frappe.db.sql("select name from tabCompany"): @@ -59,22 +66,6 @@ def get_setup_stages(args=None): 'fn': setup_post_company_fixtures, 'args': args, 'fail_msg': _("Failed to setup post company fixtures") - }, - { - 'fn': stage_three, - 'args': args, - 'fail_msg': _("Failed to set defaults") - } - ] - }, - { - 'status': _('Making website'), - 'fail_msg': _('Failed to create website'), - 'tasks': [ - { - 'fn': stage_four, - 'args': args, - 'fail_msg': _("Failed to create website") } ] }, @@ -98,38 +89,19 @@ def setup_complete(args=None): setup_company(args) setup_taxes(args) setup_post_company_fixtures(args) - stage_three(args) - stage_four(args) fin(args) def stage_fixtures(args): - install_fixtures.install(args.get("country")) - install_fixtures.add_market_segments() - install_fixtures.add_sale_stages() + fixtures.install(_dict(frappe.local.conf.setup).country) def setup_company(args): - defaults_setup.create_price_lists(args) - company_setup.create_fiscal_year_and_company(args) - company_setup.enable_shopping_cart(args) - company_setup.create_bank_account(args) + fixtures.install_company(args) def setup_taxes(args): taxes_setup.create_sales_tax(args) def setup_post_company_fixtures(args): - install_fixtures.install_post_company_fixtures(args.get("company_name")) - -def stage_three(args): - defaults_setup.create_employee_for_self(args) - defaults_setup.set_default_settings(args) - defaults_setup.create_territories() - defaults_setup.create_feed_and_todo() - defaults_setup.set_no_copy_fields_in_variant_settings() - -def stage_four(args): - company_setup.create_website(args) - company_setup.create_email_digest() - company_setup.create_logo(args) + fixtures.install_post_company_fixtures(args) def fin(args): frappe.local.message_log = [] @@ -149,3 +121,36 @@ def make_sample_data(domains): def login_as_first_user(args): if args.get("email") and hasattr(frappe.local, "login_manager"): frappe.local.login_manager.login_as(args.get("email")) + +@frappe.whitelist() +def install_fixtures(config=None): + if not config: + config = frappe.local.conf.setup or {} + + update_global_settings(_dict(config)) + + fixtures.install(_dict(config).country) + +@frappe.whitelist() +def make_setup_docs(args, config=None): + # TODO: get from not site conf + if not config: + config = frappe.local.conf.setup or {} + + args = json.loads(args) + + args.update(config) + + fixtures.install_company(_dict(args)) + fixtures.install_post_company_fixtures(_dict(args)) + + run_post_setup_complete(args) + + +def get_fy_details(fy_start_date, fy_end_date): + start_year = getdate(fy_start_date).year + if start_year == getdate(fy_end_date).year: + fy = cstr(start_year) + else: + fy = cstr(start_year) + '-' + cstr(start_year + 1) + return fy From 179d82702e6c45b35c3210606b08ecf91b09af15 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 13 Nov 2018 12:21:23 +0530 Subject: [PATCH 02/21] [setup] fetch setup config --- erpnext/setup/setup_wizard/setup_wizard.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index d19dd185e9..0856689bbc 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -13,6 +13,7 @@ from frappe import _, _dict from frappe.utils import cstr, getdate from argparse import Namespace from frappe.desk.page.setup_wizard.setup_wizard import update_global_settings, run_post_setup_complete, make_records +from journeys.journeys.config import get_journeys_config def get_setup_stages(args=None): if frappe.db.sql("select name from tabCompany"): @@ -125,7 +126,7 @@ def login_as_first_user(args): @frappe.whitelist() def install_fixtures(config=None): if not config: - config = frappe.local.conf.setup or {} + config = get_journeys_config().get('setup_config') or {} update_global_settings(_dict(config)) @@ -133,9 +134,8 @@ def install_fixtures(config=None): @frappe.whitelist() def make_setup_docs(args, config=None): - # TODO: get from not site conf if not config: - config = frappe.local.conf.setup or {} + config = get_journeys_config().get('setup_config') or {} args = json.loads(args) From b422458224eb398849c2b150dd6a17037998ea7f Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 13 Nov 2018 13:18:08 +0530 Subject: [PATCH 03/21] [setup] set the default fiscal year that was made --- erpnext/setup/setup_wizard/operations/install_fixtures.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 325b353e8e..41d529b381 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -388,8 +388,10 @@ def install_post_company_fixtures(args=None): frappe.db.set_value("Currency", args.get("currency"), "enabled", 1) global_defaults = frappe.get_doc("Global Defaults", "Global Defaults") + current_fiscal_year = frappe.get_all("Fiscal Year")[0] + global_defaults.update({ - 'current_fiscal_year': get_fy_details(args.get('fy_start_date'), args.get('fy_end_date')), + 'current_fiscal_year': current_fiscal_year.name, 'default_currency': args.get('currency'), 'default_company':args.get('company_name') , "country": args.get("country"), From dabf349599efa7f83193b9b49eda771a9752eb7b Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 13 Nov 2018 15:56:15 +0530 Subject: [PATCH 04/21] [setup] don't premake company fixtures --- erpnext/regional/india/setup.py | 3 ++- erpnext/setup/setup_wizard/operations/install_fixtures.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index 79e414104e..7813cc0fd6 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -11,9 +11,10 @@ from erpnext.accounts.utils import get_fiscal_year from frappe.utils import today def setup(company=None, patch=True): + setup_company_independent_fixtures() if not patch: update_address_template() - make_fixtures() + make_fixtures(company) # TODO: for all countries def setup_company_independent_fixtures(): diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 41d529b381..66b8766a70 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -244,9 +244,9 @@ def install(country=None): set_more_defaults() - path = frappe.get_app_path('erpnext', 'regional', frappe.scrub(country)) - if os.path.exists(path.encode("utf-8")): - frappe.get_attr("erpnext.regional.{0}.setup.setup_company_independent_fixtures".format(frappe.scrub(country)))() + # path = frappe.get_app_path('erpnext', 'regional', frappe.scrub(country)) + # if os.path.exists(path.encode("utf-8")): + # frappe.get_attr("erpnext.regional.{0}.setup.setup_company_independent_fixtures".format(frappe.scrub(country)))() def set_more_defaults(): From c1c057611e2bdc7a27555f070a8ee89f943e5a16 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 14 Nov 2018 10:26:58 +0530 Subject: [PATCH 05/21] [setup] bundle up fixtures and setup docs --- erpnext/setup/setup_wizard/setup_wizard.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 0856689bbc..3ecd00aacf 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -124,18 +124,16 @@ def login_as_first_user(args): frappe.local.login_manager.login_as(args.get("email")) @frappe.whitelist() -def install_fixtures(config=None): - if not config: - config = get_journeys_config().get('setup_config') or {} +def install_fixtures(): + config = get_journeys_config().get('setup_config') or {} update_global_settings(_dict(config)) fixtures.install(_dict(config).country) @frappe.whitelist() -def make_setup_docs(args, config=None): - if not config: - config = get_journeys_config().get('setup_config') or {} +def make_setup_docs(args): + config = get_journeys_config().get('setup_config') or {} args = json.loads(args) @@ -146,6 +144,10 @@ def make_setup_docs(args, config=None): run_post_setup_complete(args) +@frappe.whitelist() +def setup(args, config=None): + install_fixtures() + make_setup_docs(args) def get_fy_details(fy_start_date, fy_end_date): start_year = getdate(fy_start_date).year From 6bf22fa7d73d82098192ee865149cafda6afe34b Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 19 Nov 2018 15:01:25 +0530 Subject: [PATCH 06/21] [setup][fix] get newly created root Territory for children --- .../setup/setup_wizard/operations/install_fixtures.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 66b8766a70..f4689334f6 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -19,8 +19,6 @@ default_sales_partner_type = ["Channel Partner", "Distributor", "Dealer", "Agent "Retailer", "Implementation Partner", "Reseller"] def install(country=None): - root_territory = get_root_of("Territory") - records = [ # domains { 'doctype': 'Domain', 'domain': 'Distribution'}, @@ -104,8 +102,8 @@ def install(country=None): # territory: with two default territories, one for home country and one named Rest of the World {'doctype': 'Territory', 'territory_name': _('All Territories'), 'is_group': 1, 'name': _('All Territories'), 'parent_territory': ''}, - {'doctype': 'Territory', 'territory_name': country.replace("'", ""), 'is_group': 0, 'parent_territory': root_territory}, - {'doctype': 'Territory', 'territory_name': _("Rest Of The World"), 'is_group': 0, 'parent_territory': root_territory}, + {'doctype': 'Territory', 'territory_name': country.replace("'", ""), 'is_group': 0, 'parent_territory': _('All Territories')}, + {'doctype': 'Territory', 'territory_name': _("Rest Of The World"), 'is_group': 0, 'parent_territory': _('All Territories')}, # customer group {'doctype': 'Customer Group', 'customer_group_name': _('All Customer Groups'), 'is_group': 1, 'name': _('All Customer Groups'), 'parent_customer_group': ''}, @@ -417,7 +415,6 @@ def install_post_company_fixtures(args=None): stock_settings.set_qty_in_transactions_based_on_serial_no_input = 1 stock_settings.save() - if args.bank_account: company_name = args.company_name bank_account_group = frappe.db.get_value("Account", @@ -480,7 +477,8 @@ def install_post_company_fixtures(args=None): # {} ] - make_records(records, True) + # TODO: + # make_records(records, True) def get_fy_details(fy_start_date, fy_end_date): From 6f7233229e12f1076804df100ba7f29d2effc90e Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 20 Nov 2018 23:38:19 +0530 Subject: [PATCH 07/21] [setup][fix] company fixtures --- erpnext/setup/doctype/company/company.py | 2 +- .../setup_wizard/operations/install_fixtures.py | 8 ++++++-- erpnext/setup/setup_wizard/setup_wizard.py | 13 +++---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 40bbc2c15f..09ff5a83fd 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -97,7 +97,7 @@ class Company(NestedSet): if not frappe.db.get_value("Department", {"company": self.name}): from erpnext.setup.setup_wizard.operations.install_fixtures import install_post_company_fixtures - install_post_company_fixtures(self.name) + install_post_company_fixtures(frappe._dict({'company_name': self.name})) if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": self.name}): self.create_default_cost_center() diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index f4689334f6..66326486fa 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -373,11 +373,15 @@ def install_post_company_fixtures(args=None): {'doctype': 'Department', 'department_name': _('Quality Management'), 'parent_department': _('All Departments'), 'company': args.company_name}, {'doctype': 'Department', 'department_name': _('Research & Development'), 'parent_department': _('All Departments'), 'company': args.company_name}, {'doctype': 'Department', 'department_name': _('Legal'), 'parent_department': _('All Departments'), 'company': args.company_name}, + ] + make_records(records) + +def install_defaults(args=None): + records = [ # Price Lists { "doctype": "Price List", "price_list_name": _("Standard Buying"), "enabled": 1, "buying": 1, "selling": 0, "currency": args.currency }, { "doctype": "Price List", "price_list_name": _("Standard Selling"), "enabled": 1, "buying": 0, "selling": 1, "currency": args.currency }, - ] make_records(records) @@ -478,7 +482,7 @@ def install_post_company_fixtures(args=None): ] # TODO: - # make_records(records, True) + make_records(records, True) def get_fy_details(fy_start_date, fy_end_date): diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 3ecd00aacf..7642761519 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe import json +from time import time from frappe import _ from .operations import install_fixtures as fixtures, taxes_setup, company_setup, sample_data @@ -93,7 +94,7 @@ def setup_complete(args=None): fin(args) def stage_fixtures(args): - fixtures.install(_dict(frappe.local.conf.setup).country) + fixtures.install(args.get('country')) def setup_company(args): fixtures.install_company(args) @@ -140,7 +141,7 @@ def make_setup_docs(args): args.update(config) fixtures.install_company(_dict(args)) - fixtures.install_post_company_fixtures(_dict(args)) + fixtures.install_defaults(_dict(args)) run_post_setup_complete(args) @@ -148,11 +149,3 @@ def make_setup_docs(args): def setup(args, config=None): install_fixtures() make_setup_docs(args) - -def get_fy_details(fy_start_date, fy_end_date): - start_year = getdate(fy_start_date).year - if start_year == getdate(fy_end_date).year: - fy = cstr(start_year) - else: - fy = cstr(start_year) + '-' + cstr(start_year + 1) - return fy From aeb8abf1ed160f68eae361b139d651a4e1701f45 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 20 Nov 2018 23:44:13 +0530 Subject: [PATCH 08/21] [setup] add market segments and sales stages --- .../operations/install_fixtures.py | 40 +++++++------------ erpnext/setup/setup_wizard/setup_wizard.py | 1 + 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 66326486fa..2132eb5e1e 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -210,6 +210,21 @@ def install(country=None): # Share Management {"doctype": "Share Type", "title": _("Equity")}, {"doctype": "Share Type", "title": _("Preference")}, + + # Market Segments + {"doctype": "Market Segment", "market_segment": _("Lower Income")}, + {"doctype": "Market Segment", "market_segment": _("Middle Income")}, + {"doctype": "Market Segment", "market_segment": _("Upper Income")}, + + # Sales Stages + {"doctype": "Sales Stage", "stage_name": _("Prospecting")}, + {"doctype": "Sales Stage", "stage_name": _("Qualification")}, + {"doctype": "Sales Stage", "stage_name": _("Needs Analysis")}, + {"doctype": "Sales Stage", "stage_name": _("Value Proposition")}, + {"doctype": "Sales Stage", "stage_name": _("Identifying Decision Makers")}, + {"doctype": "Sales Stage", "stage_name": _("Perception Analysis")}, + {"doctype": "Sales Stage", "stage_name": _("Proposal/Price Quote")}, + {"doctype": "Sales Stage", "stage_name": _("Negotiation/Review")} ] from erpnext.setup.setup_wizard.data.industry_type import get_industry_types @@ -313,31 +328,6 @@ def add_uom_data(): "value": d.get("value") }).insert(ignore_permissions=True) -def add_market_segments(): - records = [ - # Market Segments - {"doctype": "Market Segment", "market_segment": _("Lower Income")}, - {"doctype": "Market Segment", "market_segment": _("Middle Income")}, - {"doctype": "Market Segment", "market_segment": _("Upper Income")} - ] - - make_records(records) - -def add_sale_stages(): - # Sale Stages - records = [ - {"doctype": "Sales Stage", "stage_name": _("Prospecting")}, - {"doctype": "Sales Stage", "stage_name": _("Qualification")}, - {"doctype": "Sales Stage", "stage_name": _("Needs Analysis")}, - {"doctype": "Sales Stage", "stage_name": _("Value Proposition")}, - {"doctype": "Sales Stage", "stage_name": _("Identifying Decision Makers")}, - {"doctype": "Sales Stage", "stage_name": _("Perception Analysis")}, - {"doctype": "Sales Stage", "stage_name": _("Proposal/Price Quote")}, - {"doctype": "Sales Stage", "stage_name": _("Negotiation/Review")} - ] - make_records(records) - - def install_company(args): records = [ # Fiscal Year diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 7642761519..29d6ffb128 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -142,6 +142,7 @@ def make_setup_docs(args): fixtures.install_company(_dict(args)) fixtures.install_defaults(_dict(args)) + # setup_taxes(args) run_post_setup_complete(args) From 8469b27c3ade600eeb2d03565afa1f1e5a7faf75 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 21 Nov 2018 14:25:34 +0530 Subject: [PATCH 09/21] [setup] add get_country_and_charts() --- erpnext/setup/setup_wizard/setup_wizard.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 29d6ffb128..5fc707bb4b 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -14,6 +14,7 @@ from frappe import _, _dict from frappe.utils import cstr, getdate from argparse import Namespace from frappe.desk.page.setup_wizard.setup_wizard import update_global_settings, run_post_setup_complete, make_records +from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import get_charts_for_country from journeys.journeys.config import get_journeys_config def get_setup_stages(args=None): @@ -150,3 +151,13 @@ def make_setup_docs(args): def setup(args, config=None): install_fixtures() make_setup_docs(args) + + +@frappe.whitelist() +def get_country_and_charts(): + config = get_journeys_config().get('setup_config') or {} + country = config.get('country') + return { + 'country': country, + 'charts': get_charts_for_country(country) + } From 1aee75aadcbc81c947ab38f2c4f311fa7c8cdb40 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 21 Nov 2018 14:59:27 +0530 Subject: [PATCH 10/21] [setup] separate out setup_company --- erpnext/setup/setup_wizard/setup_wizard.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 5fc707bb4b..bf1a629749 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -134,14 +134,19 @@ def install_fixtures(): fixtures.install(_dict(config).country) @frappe.whitelist() -def make_setup_docs(args): +def install_company(args): config = get_journeys_config().get('setup_config') or {} - args = json.loads(args) - args.update(config) fixtures.install_company(_dict(args)) + +@frappe.whitelist() +def setup_globals(args): + config = get_journeys_config().get('setup_config') or {} + args = json.loads(args) + args.update(config) + fixtures.install_defaults(_dict(args)) # setup_taxes(args) @@ -150,7 +155,8 @@ def make_setup_docs(args): @frappe.whitelist() def setup(args, config=None): install_fixtures() - make_setup_docs(args) + install_company(args) + setup_globals(args) @frappe.whitelist() From c0f90beb7c008e0f4a552679627763e4ca2b0f7f Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Thu, 22 Nov 2018 10:34:58 +0530 Subject: [PATCH 11/21] Rename 'Chat' to 'Gitter Chat' --- erpnext/public/js/conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/conf.js b/erpnext/public/js/conf.js index 08f8d43e50..32081550e6 100644 --- a/erpnext/public/js/conf.js +++ b/erpnext/public/js/conf.js @@ -26,8 +26,8 @@ $(document).bind('toolbar_setup', function() { $('
  • '+__('User Forum')+'
  • ').insertBefore($help_menu); - $('
  • '+__('Chat')+'
  • ').insertBefore($help_menu); + $('').insertBefore($help_menu); $('
  • '+__('Report an Issue')+'
  • ').insertBefore($help_menu); From c3a49b9cad0d95664dfa418a97b9f4062405a0d5 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Fri, 23 Nov 2018 18:49:32 +0530 Subject: [PATCH 12/21] [fix] set default_bank_account in company --- erpnext/setup/setup_wizard/operations/install_fixtures.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 2132eb5e1e..89e8e5552c 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -424,7 +424,11 @@ def install_defaults(args=None): "account_type": "Bank", }) try: - return bank_account.insert() + doc = bank_account.insert() + + frappe.db.set_value("Company", args.company_name, "default_bank_account", bank_account.name, update_modified=False) + + return doc except RootNotEditable: frappe.throw(_("Bank account cannot be named as {0}").format(args.bank_account)) except frappe.DuplicateEntryError: From 9282e08099cd2ef659adbb4c62ea4caa95e8b88d Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Fri, 23 Nov 2018 19:05:36 +0530 Subject: [PATCH 13/21] [fix] >.< call setup_taxes --- erpnext/setup/setup_wizard/setup_wizard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index bf1a629749..eced8d0a0e 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -148,7 +148,7 @@ def setup_globals(args): args.update(config) fixtures.install_defaults(_dict(args)) - # setup_taxes(args) + setup_taxes(args) run_post_setup_complete(args) From 47118ab72ab7bdfb37cb8655b6d010141d00cad4 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 26 Nov 2018 16:23:46 +0530 Subject: [PATCH 14/21] [setup] remove redundant code - [fix] domain setup from dictionary --- .../operations/install_fixtures.py | 2 +- erpnext/setup/setup_wizard/setup_wizard.py | 49 ------------------- 2 files changed, 1 insertion(+), 50 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 89e8e5552c..2c4bcb377f 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -396,7 +396,7 @@ def install_defaults(args=None): system_settings.save() domain_settings = frappe.get_single('Domain Settings') - domain_settings.set_active_domains([args.domain]) + domain_settings.set_active_domains([args.get('domain')]) stock_settings = frappe.get_doc("Stock Settings") stock_settings.item_naming_by = "Item Code" diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index eced8d0a0e..456ef926f7 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -9,13 +9,7 @@ from time import time from frappe import _ from .operations import install_fixtures as fixtures, taxes_setup, company_setup, sample_data - -from frappe import _, _dict from frappe.utils import cstr, getdate -from argparse import Namespace -from frappe.desk.page.setup_wizard.setup_wizard import update_global_settings, run_post_setup_complete, make_records -from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import get_charts_for_country -from journeys.journeys.config import get_journeys_config def get_setup_stages(args=None): if frappe.db.sql("select name from tabCompany"): @@ -124,46 +118,3 @@ def make_sample_data(domains): def login_as_first_user(args): if args.get("email") and hasattr(frappe.local, "login_manager"): frappe.local.login_manager.login_as(args.get("email")) - -@frappe.whitelist() -def install_fixtures(): - config = get_journeys_config().get('setup_config') or {} - - update_global_settings(_dict(config)) - - fixtures.install(_dict(config).country) - -@frappe.whitelist() -def install_company(args): - config = get_journeys_config().get('setup_config') or {} - args = json.loads(args) - args.update(config) - - fixtures.install_company(_dict(args)) - -@frappe.whitelist() -def setup_globals(args): - config = get_journeys_config().get('setup_config') or {} - args = json.loads(args) - args.update(config) - - fixtures.install_defaults(_dict(args)) - setup_taxes(args) - - run_post_setup_complete(args) - -@frappe.whitelist() -def setup(args, config=None): - install_fixtures() - install_company(args) - setup_globals(args) - - -@frappe.whitelist() -def get_country_and_charts(): - config = get_journeys_config().get('setup_config') or {} - country = config.get('country') - return { - 'country': country, - 'charts': get_charts_for_country(country) - } From b274f8cb2a8fa3abcc2d2b0d72c14c0b1926c3c3 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 28 Nov 2018 10:44:33 +0530 Subject: [PATCH 15/21] [fix] setup chart of accounts --- .../operations/install_fixtures.py | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 2c4bcb377f..3438f9f84f 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -336,9 +336,13 @@ def install_company(args): # Company { "doctype":"Company", - 'company_name': args.company_name, 'enable_perpetual_inventory': 1, - 'abbr': args.company_abbr, 'default_currency': args.currency, 'country': args.country, + 'company_name': args.company_name, + 'enable_perpetual_inventory': 1, + 'abbr': args.company_abbr, + 'default_currency': args.currency, + 'country': args.country, 'create_chart_of_accounts_based_on': 'Standard Template', + 'chart_of_accounts': args.chart_of_accounts, 'domain': args.domain } ] @@ -367,6 +371,7 @@ def install_post_company_fixtures(args=None): make_records(records) + def install_defaults(args=None): records = [ # Price Lists @@ -435,32 +440,10 @@ def install_defaults(args=None): # bank account same as a CoA entry pass - # Now, with fixtures out of the way, onto concrete stuff records = [ - # # Bank Account - # { - # "doctype": "Account", - # "__condition": lambda: c.bank_account and frappe.db.get_value("Account", - # {"account_type": "Bank", "is_group": 1, "root_type": "Asset", - # "company": c.company_name}), - # "__exception": { - # "exception": RootNotEditable, - # "handler": lambda: frappe.throw(_("Bank account cannot be named as {0}").format(config.get("bank_account"))) - # }, - # 'account_name': c.bank_account, - - # 'parent_account': lambda: frappe.db.get_value("Account", - # {"account_type": "Bank", "is_group": 1, "root_type": "Asset", - # "company": c.company_name}), - - # 'is_group':0, - # 'company': c.company_name, - # "account_type": "Bank", - # }, - - # # Shopping cart: needs price lists + # Shopping cart: needs price lists { "doctype": "Shopping Cart Settings", "enabled": 1, @@ -470,12 +453,8 @@ def install_defaults(args=None): 'default_customer_group': _("Individual"), 'quotation_series': "QTN-", }, - - # # TODO: Email digest, logo, website - # {} ] - # TODO: make_records(records, True) From 4da8dced949960ad83c7b9bd677eb669c45f60e1 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Tue, 11 Dec 2018 16:44:05 +0530 Subject: [PATCH 16/21] [setup] remove unused imports --- erpnext/setup/setup_wizard/operations/install_fixtures.py | 1 - erpnext/setup/setup_wizard/setup_wizard.py | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 3438f9f84f..95ff6293eb 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -8,7 +8,6 @@ import frappe, os, json from frappe import _ from frappe.desk.page.setup_wizard.setup_wizard import make_records from frappe.utils import cstr, getdate -from frappe.utils.nestedset import get_root_of from erpnext.accounts.doctype.account.account import RootNotEditable default_lead_sources = ["Existing Customer", "Reference", "Advertisement", diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 456ef926f7..ce21212843 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -4,12 +4,10 @@ from __future__ import unicode_literals import frappe -import json -from time import time from frappe import _ -from .operations import install_fixtures as fixtures, taxes_setup, company_setup, sample_data -from frappe.utils import cstr, getdate +from .operations import install_fixtures as fixtures, taxes_setup, sample_data +from frappe.utils import getdate def get_setup_stages(args=None): if frappe.db.sql("select name from tabCompany"): From d59b61cbd995e6f95b0d278e5dfb764faf565370 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 12 Dec 2018 10:50:54 +0530 Subject: [PATCH 17/21] [fixtures] re-add market_segments and sales_stages utils --- .../operations/install_fixtures.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 95ff6293eb..13365a98ef 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -327,6 +327,31 @@ def add_uom_data(): "value": d.get("value") }).insert(ignore_permissions=True) +def add_market_segments(): + records = [ + # Market Segments + {"doctype": "Market Segment", "market_segment": _("Lower Income")}, + {"doctype": "Market Segment", "market_segment": _("Middle Income")}, + {"doctype": "Market Segment", "market_segment": _("Upper Income")} + ] + + make_records(records) + +def add_sale_stages(): + # Sale Stages + records = [ + {"doctype": "Sales Stage", "stage_name": _("Prospecting")}, + {"doctype": "Sales Stage", "stage_name": _("Qualification")}, + {"doctype": "Sales Stage", "stage_name": _("Needs Analysis")}, + {"doctype": "Sales Stage", "stage_name": _("Value Proposition")}, + {"doctype": "Sales Stage", "stage_name": _("Identifying Decision Makers")}, + {"doctype": "Sales Stage", "stage_name": _("Perception Analysis")}, + {"doctype": "Sales Stage", "stage_name": _("Proposal/Price Quote")}, + {"doctype": "Sales Stage", "stage_name": _("Negotiation/Review")} + ] + + make_records(records) + def install_company(args): records = [ # Fiscal Year From 0e728972e91dcff63a3f710ae86db3180261c21a Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 12 Dec 2018 11:29:06 +0530 Subject: [PATCH 18/21] [setup][minor] remove unused import --- erpnext/setup/setup_wizard/setup_wizard.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index ce21212843..15b387f166 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -7,7 +7,6 @@ import frappe from frappe import _ from .operations import install_fixtures as fixtures, taxes_setup, sample_data -from frappe.utils import getdate def get_setup_stages(args=None): if frappe.db.sql("select name from tabCompany"): From 58db3c1c7c1c2026cdafa0bec51b394651b42c29 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 12 Dec 2018 12:48:12 +0530 Subject: [PATCH 19/21] [setup] fix install_defaults --- erpnext/setup/setup_wizard/setup_wizard.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index 15b387f166..b91c9a966d 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from .operations import install_fixtures as fixtures, taxes_setup, sample_data +from .operations import install_fixtures as fixtures, company_setup, taxes_setup, sample_data def get_setup_stages(args=None): if frappe.db.sql("select name from tabCompany"): @@ -83,6 +83,8 @@ def setup_complete(args=None): setup_company(args) setup_taxes(args) setup_post_company_fixtures(args) + fixtures.install_defaults(args) + stage_four(args) fin(args) def stage_fixtures(args): @@ -97,6 +99,11 @@ def setup_taxes(args): def setup_post_company_fixtures(args): fixtures.install_post_company_fixtures(args) +def stage_four(args): + company_setup.create_website(args) + company_setup.create_email_digest() + company_setup.create_logo(args) + def fin(args): frappe.local.message_log = [] login_as_first_user(args) From 9c5676292cc3705e89bec9c7be44b55a83ef029f Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 12 Dec 2018 13:47:43 +0530 Subject: [PATCH 20/21] [setup] add defaults stage --- erpnext/setup/setup_wizard/setup_wizard.py | 33 ++++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py index b91c9a966d..e062e280b9 100644 --- a/erpnext/setup/setup_wizard/setup_wizard.py +++ b/erpnext/setup/setup_wizard/setup_wizard.py @@ -60,6 +60,16 @@ def get_setup_stages(args=None): 'fn': setup_post_company_fixtures, 'args': args, 'fail_msg': _("Failed to setup post company fixtures") + }, + { + 'fn': setup_defaults, + 'args': args, + 'fail_msg': _("Failed to setup defaults") + }, + { + 'fn': stage_four, + 'args': args, + 'fail_msg': _("Failed to create website") } ] }, @@ -78,15 +88,6 @@ def get_setup_stages(args=None): return stages -def setup_complete(args=None): - stage_fixtures(args) - setup_company(args) - setup_taxes(args) - setup_post_company_fixtures(args) - fixtures.install_defaults(args) - stage_four(args) - fin(args) - def stage_fixtures(args): fixtures.install(args.get('country')) @@ -99,6 +100,9 @@ def setup_taxes(args): def setup_post_company_fixtures(args): fixtures.install_post_company_fixtures(args) +def setup_defaults(args): + fixtures.install_defaults(frappe._dict(args)) + def stage_four(args): company_setup.create_website(args) company_setup.create_email_digest() @@ -122,3 +126,14 @@ def make_sample_data(domains): def login_as_first_user(args): if args.get("email") and hasattr(frappe.local, "login_manager"): frappe.local.login_manager.login_as(args.get("email")) + + +# Only for programmatical use +def setup_complete(args=None): + stage_fixtures(args) + setup_company(args) + setup_taxes(args) + setup_post_company_fixtures(args) + setup_defaults(args) + stage_four(args) + fin(args) From 4ba9594b045933c475e15f7017a4db62c3342be8 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 12 Dec 2018 22:09:00 +0530 Subject: [PATCH 21/21] [setup] domain not in array --- erpnext/setup/setup_wizard/operations/install_fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 13365a98ef..c732c4b479 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -425,7 +425,7 @@ def install_defaults(args=None): system_settings.save() domain_settings = frappe.get_single('Domain Settings') - domain_settings.set_active_domains([args.get('domain')]) + domain_settings.set_active_domains(args.get('domains')) stock_settings = frappe.get_doc("Stock Settings") stock_settings.item_naming_by = "Item Code"