mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-21 02:09:58 +00:00
[enhancement] update to setup wizard, added users, employees, sample data
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe, json
|
||||
import frappe, json, copy
|
||||
|
||||
from frappe.utils import cstr, flt, getdate
|
||||
from frappe import _
|
||||
@@ -13,6 +13,7 @@ from frappe.geo.country_info import get_country_info
|
||||
from frappe.utils.nestedset import get_root_of
|
||||
from .default_website import website_maker
|
||||
import install_fixtures
|
||||
from .sample_data import make_sample_data
|
||||
|
||||
@frappe.whitelist()
|
||||
def setup_account(args=None):
|
||||
@@ -38,6 +39,9 @@ def setup_account(args=None):
|
||||
create_fiscal_year_and_company(args)
|
||||
frappe.local.message_log = []
|
||||
|
||||
create_users(args)
|
||||
frappe.local.message_log = []
|
||||
|
||||
set_defaults(args)
|
||||
frappe.local.message_log = []
|
||||
|
||||
@@ -81,6 +85,7 @@ def setup_account(args=None):
|
||||
|
||||
frappe.clear_cache()
|
||||
|
||||
make_sample_data()
|
||||
except:
|
||||
if args:
|
||||
traceback = frappe.get_traceback()
|
||||
@@ -297,21 +302,45 @@ def create_taxes(args):
|
||||
tax_group = frappe.db.get_value("Account", {"company": args.get("company_name"),
|
||||
"is_group": 1, "account_type": "Tax", "root_type": "Liability"})
|
||||
if tax_group:
|
||||
frappe.get_doc({
|
||||
"doctype":"Account",
|
||||
"company": args.get("company_name").strip(),
|
||||
"parent_account": tax_group,
|
||||
"account_name": args.get("tax_" + str(i)),
|
||||
"is_group": 0,
|
||||
"report_type": "Balance Sheet",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": flt(tax_rate) if tax_rate else None
|
||||
}).insert()
|
||||
account = make_tax_head(args, i, tax_group, tax_rate)
|
||||
make_sales_and_purchase_tax_templates(account)
|
||||
|
||||
except frappe.NameError, e:
|
||||
if e.args[2][0]==1062:
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
def make_tax_head(args, i, tax_group, tax_rate):
|
||||
return frappe.get_doc({
|
||||
"doctype":"Account",
|
||||
"company": args.get("company_name").strip(),
|
||||
"parent_account": tax_group,
|
||||
"account_name": args.get("tax_" + str(i)),
|
||||
"is_group": 0,
|
||||
"report_type": "Balance Sheet",
|
||||
"account_type": "Tax",
|
||||
"tax_rate": flt(tax_rate) if tax_rate else None
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
def make_sales_and_purchase_tax_templates(account):
|
||||
doc = {
|
||||
"doctype": "Sales Taxes and Charges Template",
|
||||
"title": account.name,
|
||||
"taxes": [{
|
||||
"category": "Valuation and Total",
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": account.name,
|
||||
"description": "{0} @ {1}".format(account.account_name, account.tax_rate),
|
||||
"rate": account.tax_rate
|
||||
}]
|
||||
}
|
||||
|
||||
# Sales
|
||||
frappe.get_doc(copy.deepcopy(doc)).insert()
|
||||
|
||||
# Purchase
|
||||
doc["doctype"] = "Purchase Taxes and Charges Template"
|
||||
frappe.get_doc(copy.deepcopy(doc)).insert()
|
||||
|
||||
def create_items(args):
|
||||
for i in xrange(1,6):
|
||||
@@ -349,9 +378,30 @@ def create_items(args):
|
||||
filename, filetype, content = item_image
|
||||
fileurl = save_file(filename, content, "Item", item, decode=True).file_url
|
||||
frappe.db.set_value("Item", item, "image", fileurl)
|
||||
|
||||
if args.get("item_price_" + str(i)):
|
||||
item_price = flt(args.get("item_price_" + str(i)))
|
||||
|
||||
if is_sales_item:
|
||||
price_list_name = frappe.db.get_value("Price List", {"selling": 1})
|
||||
make_item_price(item, price_list_name, item_price)
|
||||
|
||||
if is_purchase_item:
|
||||
price_list_name = frappe.db.get_value("Price List", {"buying": 1})
|
||||
make_item_price(item, price_list_name, item_price)
|
||||
|
||||
except frappe.NameError:
|
||||
pass
|
||||
|
||||
def make_item_price(item, price_list_name, item_price):
|
||||
frappe.get_doc({
|
||||
"doctype": "Item Price",
|
||||
"price_list": price_list_name,
|
||||
"item_code": item,
|
||||
"price_list_rate": item_price
|
||||
}).insert()
|
||||
|
||||
|
||||
def create_customers(args):
|
||||
for i in xrange(1,6):
|
||||
customer = args.get("customer_" + str(i))
|
||||
@@ -451,6 +501,60 @@ 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"))
|
||||
|
||||
def create_users(args):
|
||||
# create employee for self
|
||||
emp = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"full_name": " ".join(filter(None, [args.get("first_name"), args.get("last_name")])),
|
||||
"user_id": frappe.session.user,
|
||||
"status": "Active",
|
||||
"company": args.get("company_name")
|
||||
})
|
||||
emp.flags.ignore_mandatory = True
|
||||
emp.insert(ignore_permissions = True)
|
||||
|
||||
for i in xrange(1,5):
|
||||
email = args.get("user_email_" + str(i))
|
||||
fullname = args.get("user_fullname_" + str(i))
|
||||
if email:
|
||||
if not fullname:
|
||||
fullname = email.split("@")[0]
|
||||
|
||||
parts = fullname.split(" ", 1)
|
||||
|
||||
user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": email,
|
||||
"first_name": parts[0],
|
||||
"last_name": parts[1] if len(parts) > 1 else "",
|
||||
"enabled": 1,
|
||||
"user_type": "System User"
|
||||
})
|
||||
|
||||
# default roles
|
||||
user.append_roles("Projects User", "Stock User", "Support Team")
|
||||
|
||||
if args.get("user_sales_" + str(i)):
|
||||
user.append_roles("Sales User", "Sales Manager", "Accounts User")
|
||||
if args.get("user_purchaser_" + str(i)):
|
||||
user.append_roles("Purchase User", "Purchase Manager", "Accounts User")
|
||||
if args.get("user_accountant_" + str(i)):
|
||||
user.append_roles("Accounts Manager", "Accounts User")
|
||||
|
||||
user.flags.delay_emails = True
|
||||
user.insert(ignore_permissions=True)
|
||||
|
||||
# create employee
|
||||
emp = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"full_name": fullname,
|
||||
"user_id": user.name,
|
||||
"status": "Active",
|
||||
"company": args.get("company_name")
|
||||
})
|
||||
emp.flags.ignore_mandatory = True
|
||||
emp.insert(ignore_permissions = True)
|
||||
|
||||
@frappe.whitelist()
|
||||
def load_messages(language):
|
||||
frappe.clear_cache()
|
||||
|
||||
Reference in New Issue
Block a user