2015-03-03 14:55:30 +05:30
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-10-08 17:59:11 +05:30
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
|
2017-12-21 11:55:58 +05:30
|
|
|
import frappe
|
2014-04-18 16:00:41 +05:30
|
|
|
from frappe import _
|
2018-11-12 17:19:56 +05:30
|
|
|
|
2019-01-24 17:56:19 +05:30
|
|
|
from .operations import company_setup
|
|
|
|
from .operations import install_fixtures as fixtures
|
2021-09-02 16:44:59 +05:30
|
|
|
|
2013-10-08 17:59:11 +05:30
|
|
|
|
2017-12-21 11:55:58 +05:30
|
|
|
def get_setup_stages(args=None):
|
2016-09-23 20:43:23 +05:30
|
|
|
if frappe.db.sql("select name from tabCompany"):
|
2017-12-21 11:55:58 +05:30
|
|
|
stages = [
|
|
|
|
{
|
|
|
|
"status": _("Wrapping up"),
|
|
|
|
"fail_msg": _("Failed to login"),
|
|
|
|
"tasks": [{"fn": fin, "args": args, "fail_msg": _("Failed to login")}],
|
|
|
|
}
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
stages = [
|
|
|
|
{
|
|
|
|
"status": _("Installing presets"),
|
|
|
|
"fail_msg": _("Failed to install presets"),
|
|
|
|
"tasks": [{"fn": stage_fixtures, "args": args, "fail_msg": _("Failed to install presets")}],
|
|
|
|
},
|
|
|
|
{
|
2019-01-24 17:56:19 +05:30
|
|
|
"status": _("Setting up company"),
|
2017-12-21 11:55:58 +05:30
|
|
|
"fail_msg": _("Failed to setup company"),
|
|
|
|
"tasks": [{"fn": setup_company, "args": args, "fail_msg": _("Failed to setup company")}],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"status": _("Setting defaults"),
|
|
|
|
"fail_msg": "Failed to set defaults",
|
|
|
|
"tasks": [
|
2018-12-12 13:47:43 +05:30
|
|
|
{"fn": setup_defaults, "args": args, "fail_msg": _("Failed to setup defaults")},
|
|
|
|
{"fn": stage_four, "args": args, "fail_msg": _("Failed to create website")},
|
2019-09-30 13:40:02 +05:30
|
|
|
],
|
2017-12-21 11:55:58 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
"status": _("Wrapping up"),
|
|
|
|
"fail_msg": _("Failed to login"),
|
|
|
|
"tasks": [{"fn": fin, "args": args, "fail_msg": _("Failed to login")}],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
return stages
|
2016-09-23 20:43:23 +05:30
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2017-12-21 11:55:58 +05:30
|
|
|
def stage_fixtures(args):
|
2018-11-20 23:38:19 +05:30
|
|
|
fixtures.install(args.get("country"))
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2016-09-23 20:43:23 +05:30
|
|
|
|
2017-12-21 11:55:58 +05:30
|
|
|
def setup_company(args):
|
2018-11-12 17:19:56 +05:30
|
|
|
fixtures.install_company(args)
|
2016-09-23 20:43:23 +05:30
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2018-12-12 13:47:43 +05:30
|
|
|
def setup_defaults(args):
|
|
|
|
fixtures.install_defaults(frappe._dict(args))
|
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2018-12-12 12:48:12 +05:30
|
|
|
def stage_four(args):
|
|
|
|
company_setup.create_website(args)
|
|
|
|
company_setup.create_email_digest()
|
|
|
|
company_setup.create_logo(args)
|
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2017-12-21 11:55:58 +05:30
|
|
|
def fin(args):
|
|
|
|
frappe.local.message_log = []
|
2016-09-23 20:43:23 +05:30
|
|
|
login_as_first_user(args)
|
|
|
|
|
2017-09-04 11:14:04 +05:30
|
|
|
|
2015-02-17 15:55:36 +05:30
|
|
|
def login_as_first_user(args):
|
2016-10-20 15:49:39 +05:30
|
|
|
if args.get("email") and hasattr(frappe.local, "login_manager"):
|
|
|
|
frappe.local.login_manager.login_as(args.get("email"))
|
2018-12-12 13:47:43 +05:30
|
|
|
|
|
|
|
|
|
|
|
# Only for programmatical use
|
|
|
|
def setup_complete(args=None):
|
|
|
|
stage_fixtures(args)
|
|
|
|
setup_company(args)
|
|
|
|
setup_defaults(args)
|
|
|
|
stage_four(args)
|
|
|
|
fin(args)
|