mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-06 23:10:26 +00:00
style: bulk format code with black
v13 port because otherwise backports will result in conflicts always
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import json
|
||||
|
||||
import frappe
|
||||
@@ -14,6 +13,7 @@ def get_company_for_dashboards():
|
||||
return company_list[0].name
|
||||
return None
|
||||
|
||||
|
||||
def get_default_dashboards():
|
||||
company = frappe.get_doc("Company", get_company_for_dashboards())
|
||||
income_account = company.default_income_account or get_account("Income Account", company.name)
|
||||
@@ -26,20 +26,18 @@ def get_default_dashboards():
|
||||
"doctype": "Dashboard",
|
||||
"dashboard_name": "Accounts",
|
||||
"charts": [
|
||||
{ "chart": "Outgoing Bills (Sales Invoice)" },
|
||||
{ "chart": "Incoming Bills (Purchase Invoice)" },
|
||||
{ "chart": "Bank Balance" },
|
||||
{ "chart": "Income" },
|
||||
{ "chart": "Expenses" },
|
||||
{ "chart": "Patient Appointments" }
|
||||
]
|
||||
{"chart": "Outgoing Bills (Sales Invoice)"},
|
||||
{"chart": "Incoming Bills (Purchase Invoice)"},
|
||||
{"chart": "Bank Balance"},
|
||||
{"chart": "Income"},
|
||||
{"chart": "Expenses"},
|
||||
{"chart": "Patient Appointments"},
|
||||
],
|
||||
},
|
||||
{
|
||||
"doctype": "Dashboard",
|
||||
"dashboard_name": "Project",
|
||||
"charts": [
|
||||
{ "chart": "Project Summary", "width": "Full" }
|
||||
]
|
||||
"charts": [{"chart": "Project Summary", "width": "Full"}],
|
||||
},
|
||||
],
|
||||
"Charts": [
|
||||
@@ -55,7 +53,7 @@ def get_default_dashboards():
|
||||
"timeseries": 1,
|
||||
"owner": "Administrator",
|
||||
"type": "Line",
|
||||
"width": "Half"
|
||||
"width": "Half",
|
||||
},
|
||||
{
|
||||
"doctype": "Dashboard Chart",
|
||||
@@ -69,7 +67,7 @@ def get_default_dashboards():
|
||||
"timeseries": 1,
|
||||
"owner": "Administrator",
|
||||
"type": "Line",
|
||||
"width": "Half"
|
||||
"width": "Half",
|
||||
},
|
||||
{
|
||||
"doctype": "Dashboard Chart",
|
||||
@@ -83,7 +81,7 @@ def get_default_dashboards():
|
||||
"timeseries": 1,
|
||||
"owner": "Administrator",
|
||||
"type": "Line",
|
||||
"width": "Half"
|
||||
"width": "Half",
|
||||
},
|
||||
{
|
||||
"doctype": "Dashboard Chart",
|
||||
@@ -99,7 +97,7 @@ def get_default_dashboards():
|
||||
"owner": "Administrator",
|
||||
"document_type": "Purchase Invoice",
|
||||
"type": "Bar",
|
||||
"width": "Half"
|
||||
"width": "Half",
|
||||
},
|
||||
{
|
||||
"doctype": "Dashboard Chart",
|
||||
@@ -115,18 +113,18 @@ def get_default_dashboards():
|
||||
"owner": "Administrator",
|
||||
"document_type": "Sales Invoice",
|
||||
"type": "Bar",
|
||||
"width": "Half"
|
||||
"width": "Half",
|
||||
},
|
||||
{
|
||||
'doctype': 'Dashboard Chart',
|
||||
'name': 'Project Summary',
|
||||
'chart_name': 'Project Summary',
|
||||
'chart_type': 'Report',
|
||||
'report_name': 'Project Summary',
|
||||
'is_public': 1,
|
||||
'filters_json': json.dumps({"company": company.name, "status": "Open"}),
|
||||
'type': 'Bar',
|
||||
'custom_options': '{"type": "bar", "colors": ["#fc4f51", "#78d6ff", "#7575ff"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}',
|
||||
"doctype": "Dashboard Chart",
|
||||
"name": "Project Summary",
|
||||
"chart_name": "Project Summary",
|
||||
"chart_type": "Report",
|
||||
"report_name": "Project Summary",
|
||||
"is_public": 1,
|
||||
"filters_json": json.dumps({"company": company.name, "status": "Open"}),
|
||||
"type": "Bar",
|
||||
"custom_options": '{"type": "bar", "colors": ["#fc4f51", "#78d6ff", "#7575ff"], "axisOptions": { "shortenYAxisNumbers": 1}, "barOptions": { "stacked": 1 }}',
|
||||
},
|
||||
{
|
||||
"doctype": "Dashboard Chart",
|
||||
@@ -141,11 +139,12 @@ def get_default_dashboards():
|
||||
"owner": "Administrator",
|
||||
"document_type": "Patient Appointment",
|
||||
"type": "Line",
|
||||
"width": "Half"
|
||||
}
|
||||
]
|
||||
"width": "Half",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def get_account(account_type, company):
|
||||
accounts = frappe.get_list("Account", filters={"account_type": account_type, "company": company})
|
||||
if accounts:
|
||||
|
||||
@@ -1,58 +1,57 @@
|
||||
|
||||
from frappe import _
|
||||
|
||||
|
||||
def get_industry_types():
|
||||
return [
|
||||
_('Accounting'),
|
||||
_('Advertising'),
|
||||
_('Aerospace'),
|
||||
_('Agriculture'),
|
||||
_('Airline'),
|
||||
_('Apparel & Accessories'),
|
||||
_('Automotive'),
|
||||
_('Banking'),
|
||||
_('Biotechnology'),
|
||||
_('Broadcasting'),
|
||||
_('Brokerage'),
|
||||
_('Chemical'),
|
||||
_('Computer'),
|
||||
_('Consulting'),
|
||||
_('Consumer Products'),
|
||||
_('Cosmetics'),
|
||||
_('Defense'),
|
||||
_('Department Stores'),
|
||||
_('Education'),
|
||||
_('Electronics'),
|
||||
_('Energy'),
|
||||
_('Entertainment & Leisure'),
|
||||
_('Executive Search'),
|
||||
_('Financial Services'),
|
||||
_('Food, Beverage & Tobacco'),
|
||||
_('Grocery'),
|
||||
_('Health Care'),
|
||||
_('Internet Publishing'),
|
||||
_('Investment Banking'),
|
||||
_('Legal'),
|
||||
_('Manufacturing'),
|
||||
_('Motion Picture & Video'),
|
||||
_('Music'),
|
||||
_('Newspaper Publishers'),
|
||||
_('Online Auctions'),
|
||||
_('Pension Funds'),
|
||||
_('Pharmaceuticals'),
|
||||
_('Private Equity'),
|
||||
_('Publishing'),
|
||||
_('Real Estate'),
|
||||
_('Retail & Wholesale'),
|
||||
_('Securities & Commodity Exchanges'),
|
||||
_('Service'),
|
||||
_('Soap & Detergent'),
|
||||
_('Software'),
|
||||
_('Sports'),
|
||||
_('Technology'),
|
||||
_('Telecommunications'),
|
||||
_('Television'),
|
||||
_('Transportation'),
|
||||
_('Venture Capital')
|
||||
_("Accounting"),
|
||||
_("Advertising"),
|
||||
_("Aerospace"),
|
||||
_("Agriculture"),
|
||||
_("Airline"),
|
||||
_("Apparel & Accessories"),
|
||||
_("Automotive"),
|
||||
_("Banking"),
|
||||
_("Biotechnology"),
|
||||
_("Broadcasting"),
|
||||
_("Brokerage"),
|
||||
_("Chemical"),
|
||||
_("Computer"),
|
||||
_("Consulting"),
|
||||
_("Consumer Products"),
|
||||
_("Cosmetics"),
|
||||
_("Defense"),
|
||||
_("Department Stores"),
|
||||
_("Education"),
|
||||
_("Electronics"),
|
||||
_("Energy"),
|
||||
_("Entertainment & Leisure"),
|
||||
_("Executive Search"),
|
||||
_("Financial Services"),
|
||||
_("Food, Beverage & Tobacco"),
|
||||
_("Grocery"),
|
||||
_("Health Care"),
|
||||
_("Internet Publishing"),
|
||||
_("Investment Banking"),
|
||||
_("Legal"),
|
||||
_("Manufacturing"),
|
||||
_("Motion Picture & Video"),
|
||||
_("Music"),
|
||||
_("Newspaper Publishers"),
|
||||
_("Online Auctions"),
|
||||
_("Pension Funds"),
|
||||
_("Pharmaceuticals"),
|
||||
_("Private Equity"),
|
||||
_("Publishing"),
|
||||
_("Real Estate"),
|
||||
_("Retail & Wholesale"),
|
||||
_("Securities & Commodity Exchanges"),
|
||||
_("Service"),
|
||||
_("Soap & Detergent"),
|
||||
_("Software"),
|
||||
_("Sports"),
|
||||
_("Technology"),
|
||||
_("Telecommunications"),
|
||||
_("Television"),
|
||||
_("Transportation"),
|
||||
_("Venture Capital"),
|
||||
]
|
||||
|
||||
@@ -10,41 +10,50 @@ from .default_website import website_maker
|
||||
|
||||
|
||||
def create_fiscal_year_and_company(args):
|
||||
if (args.get('fy_start_date')):
|
||||
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()
|
||||
if args.get("fy_start_date"):
|
||||
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()
|
||||
|
||||
if args.get("company_name"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Company",
|
||||
"company_name": args.get("company_name"),
|
||||
"enable_perpetual_inventory": 1,
|
||||
"abbr": args.get("company_abbr"),
|
||||
"default_currency": args.get("currency"),
|
||||
"country": args.get("country"),
|
||||
"create_chart_of_accounts_based_on": "Standard Template",
|
||||
"chart_of_accounts": args.get("chart_of_accounts"),
|
||||
"domain": args.get("domains")[0],
|
||||
}
|
||||
).insert()
|
||||
|
||||
if (args.get('company_name')):
|
||||
frappe.get_doc({
|
||||
"doctype":"Company",
|
||||
'company_name':args.get('company_name'),
|
||||
'enable_perpetual_inventory': 1,
|
||||
'abbr':args.get('company_abbr'),
|
||||
'default_currency':args.get('currency'),
|
||||
'country': args.get('country'),
|
||||
'create_chart_of_accounts_based_on': 'Standard Template',
|
||||
'chart_of_accounts': args.get('chart_of_accounts'),
|
||||
'domain': args.get('domains')[0]
|
||||
}).insert()
|
||||
|
||||
def enable_shopping_cart(args):
|
||||
# Needs price_lists
|
||||
frappe.get_doc({
|
||||
"doctype": "E Commerce Settings",
|
||||
"enabled": 1,
|
||||
'company': args.get('company_name') ,
|
||||
'price_list': frappe.db.get_value("Price List", {"selling": 1}),
|
||||
'default_customer_group': _("Individual"),
|
||||
'quotation_series': "QTN-",
|
||||
}).insert()
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "E Commerce Settings",
|
||||
"enabled": 1,
|
||||
"company": args.get("company_name"),
|
||||
"price_list": frappe.db.get_value("Price List", {"selling": 1}),
|
||||
"default_customer_group": _("Individual"),
|
||||
"quotation_series": "QTN-",
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
def create_email_digest():
|
||||
from frappe.utils.user import get_system_managers
|
||||
|
||||
system_managers = get_system_managers(only_name=True)
|
||||
|
||||
if not system_managers:
|
||||
@@ -52,20 +61,20 @@ def create_email_digest():
|
||||
|
||||
recipients = []
|
||||
for d in system_managers:
|
||||
recipients.append({
|
||||
'recipient': d
|
||||
})
|
||||
recipients.append({"recipient": d})
|
||||
|
||||
companies = frappe.db.sql_list("select name FROM `tabCompany`")
|
||||
for company in companies:
|
||||
if not frappe.db.exists("Email Digest", "Default Weekly Digest - " + company):
|
||||
edigest = frappe.get_doc({
|
||||
"doctype": "Email Digest",
|
||||
"name": "Default Weekly Digest - " + company,
|
||||
"company": company,
|
||||
"frequency": "Weekly",
|
||||
"recipients": recipients
|
||||
})
|
||||
edigest = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Email Digest",
|
||||
"name": "Default Weekly Digest - " + company,
|
||||
"company": company,
|
||||
"frequency": "Weekly",
|
||||
"recipients": recipients,
|
||||
}
|
||||
)
|
||||
|
||||
for df in edigest.meta.get("fields", {"fieldtype": "Check"}):
|
||||
if df.fieldname != "scheduler_errors":
|
||||
@@ -76,39 +85,53 @@ def create_email_digest():
|
||||
# scheduler errors digest
|
||||
if companies:
|
||||
edigest = frappe.new_doc("Email Digest")
|
||||
edigest.update({
|
||||
"name": "Scheduler Errors",
|
||||
"company": companies[0],
|
||||
"frequency": "Daily",
|
||||
"recipients": recipients,
|
||||
"scheduler_errors": 1,
|
||||
"enabled": 1
|
||||
})
|
||||
edigest.update(
|
||||
{
|
||||
"name": "Scheduler Errors",
|
||||
"company": companies[0],
|
||||
"frequency": "Daily",
|
||||
"recipients": recipients,
|
||||
"scheduler_errors": 1,
|
||||
"enabled": 1,
|
||||
}
|
||||
)
|
||||
edigest.insert()
|
||||
|
||||
|
||||
def create_logo(args):
|
||||
if args.get("attach_logo"):
|
||||
attach_logo = args.get("attach_logo").split(",")
|
||||
if len(attach_logo)==3:
|
||||
if len(attach_logo) == 3:
|
||||
filename, filetype, content = attach_logo
|
||||
_file = frappe.get_doc({
|
||||
"doctype": "File",
|
||||
"file_name": filename,
|
||||
"attached_to_doctype": "Website Settings",
|
||||
"attached_to_name": "Website Settings",
|
||||
"decode": True})
|
||||
_file = frappe.get_doc(
|
||||
{
|
||||
"doctype": "File",
|
||||
"file_name": filename,
|
||||
"attached_to_doctype": "Website Settings",
|
||||
"attached_to_name": "Website Settings",
|
||||
"decode": True,
|
||||
}
|
||||
)
|
||||
_file.save()
|
||||
fileurl = _file.file_url
|
||||
frappe.db.set_value("Website Settings", "Website Settings", "brand_html",
|
||||
"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(fileurl, args.get("company_name")))
|
||||
frappe.db.set_value(
|
||||
"Website Settings",
|
||||
"Website Settings",
|
||||
"brand_html",
|
||||
"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(
|
||||
fileurl, args.get("company_name")
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def create_website(args):
|
||||
website_maker(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)
|
||||
fy = cstr(start_year) + "-" + cstr(start_year + 1)
|
||||
return fy
|
||||
|
||||
@@ -12,14 +12,14 @@ class website_maker(object):
|
||||
self.args = args
|
||||
self.company = args.company_name
|
||||
self.tagline = args.company_tagline
|
||||
self.user = args.get('email')
|
||||
self.user = args.get("email")
|
||||
self.make_web_page()
|
||||
self.make_website_settings()
|
||||
self.make_blog()
|
||||
|
||||
def make_web_page(self):
|
||||
# home page
|
||||
homepage = frappe.get_doc('Homepage', 'Homepage')
|
||||
homepage = frappe.get_doc("Homepage", "Homepage")
|
||||
homepage.company = self.company
|
||||
homepage.tag_line = self.tagline
|
||||
homepage.setup_items()
|
||||
@@ -28,34 +28,25 @@ class website_maker(object):
|
||||
def make_website_settings(self):
|
||||
# update in home page in settings
|
||||
website_settings = frappe.get_doc("Website Settings", "Website Settings")
|
||||
website_settings.home_page = 'home'
|
||||
website_settings.home_page = "home"
|
||||
website_settings.brand_html = self.company
|
||||
website_settings.copyright = self.company
|
||||
website_settings.top_bar_items = []
|
||||
website_settings.append("top_bar_items", {
|
||||
"doctype": "Top Bar Item",
|
||||
"label":"Contact",
|
||||
"url": "/contact"
|
||||
})
|
||||
website_settings.append("top_bar_items", {
|
||||
"doctype": "Top Bar Item",
|
||||
"label":"Blog",
|
||||
"url": "/blog"
|
||||
})
|
||||
website_settings.append("top_bar_items", {
|
||||
"doctype": "Top Bar Item",
|
||||
"label": _("Products"),
|
||||
"url": "/all-products"
|
||||
})
|
||||
website_settings.append(
|
||||
"top_bar_items", {"doctype": "Top Bar Item", "label": "Contact", "url": "/contact"}
|
||||
)
|
||||
website_settings.append(
|
||||
"top_bar_items", {"doctype": "Top Bar Item", "label": "Blog", "url": "/blog"}
|
||||
)
|
||||
website_settings.append(
|
||||
"top_bar_items", {"doctype": "Top Bar Item", "label": _("Products"), "url": "/all-products"}
|
||||
)
|
||||
website_settings.save()
|
||||
|
||||
def make_blog(self):
|
||||
blog_category = frappe.get_doc({
|
||||
"doctype": "Blog Category",
|
||||
"category_name": "general",
|
||||
"published": 1,
|
||||
"title": _("General")
|
||||
}).insert()
|
||||
blog_category = frappe.get_doc(
|
||||
{"doctype": "Blog Category", "category_name": "general", "published": 1, "title": _("General")}
|
||||
).insert()
|
||||
|
||||
if not self.user:
|
||||
# Admin setup
|
||||
@@ -69,21 +60,30 @@ class website_maker(object):
|
||||
blogger.avatar = user.user_image
|
||||
blogger.insert()
|
||||
|
||||
frappe.get_doc({
|
||||
"doctype": "Blog Post",
|
||||
"title": "Welcome",
|
||||
"published": 1,
|
||||
"published_on": nowdate(),
|
||||
"blogger": blogger.name,
|
||||
"blog_category": blog_category.name,
|
||||
"blog_intro": "My First Blog",
|
||||
"content": frappe.get_template("setup/setup_wizard/data/sample_blog_post.html").render(),
|
||||
}).insert()
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Blog Post",
|
||||
"title": "Welcome",
|
||||
"published": 1,
|
||||
"published_on": nowdate(),
|
||||
"blogger": blogger.name,
|
||||
"blog_category": blog_category.name,
|
||||
"blog_intro": "My First Blog",
|
||||
"content": frappe.get_template("setup/setup_wizard/data/sample_blog_post.html").render(),
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
def test():
|
||||
frappe.delete_doc("Web Page", "test-company")
|
||||
frappe.delete_doc("Blog Post", "welcome")
|
||||
frappe.delete_doc("Blogger", "administrator")
|
||||
frappe.delete_doc("Blog Category", "general")
|
||||
website_maker({'company':"Test Company", 'company_tagline': "Better Tools for Everyone", 'name': "Administrator"})
|
||||
website_maker(
|
||||
{
|
||||
"company": "Test Company",
|
||||
"company_tagline": "Better Tools for Everyone",
|
||||
"name": "Administrator",
|
||||
}
|
||||
)
|
||||
frappe.db.commit()
|
||||
|
||||
@@ -12,12 +12,14 @@ def set_default_settings(args):
|
||||
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.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()
|
||||
|
||||
@@ -25,13 +27,15 @@ def set_default_settings(args):
|
||||
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.get('domains'))
|
||||
domain_settings = frappe.get_single("Domain Settings")
|
||||
domain_settings.set_active_domains(args.get("domains"))
|
||||
|
||||
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.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
|
||||
@@ -72,61 +76,74 @@ def set_default_settings(args):
|
||||
hr_settings.feedback_reminder_notification_template = _("Interview Feedback Reminder")
|
||||
hr_settings.save()
|
||||
|
||||
|
||||
def set_no_copy_fields_in_variant_settings():
|
||||
# set no copy fields of an item doctype to item variant settings
|
||||
doc = frappe.get_doc('Item Variant Settings')
|
||||
doc = frappe.get_doc("Item Variant Settings")
|
||||
doc.set_default_fields()
|
||||
doc.save()
|
||||
|
||||
|
||||
def create_price_lists(args):
|
||||
for pl_type, pl_name in (("Selling", _("Standard Selling")), ("Buying", _("Standard Buying"))):
|
||||
frappe.get_doc({
|
||||
"doctype": "Price List",
|
||||
"price_list_name": pl_name,
|
||||
"enabled": 1,
|
||||
"buying": 1 if pl_type == "Buying" else 0,
|
||||
"selling": 1 if pl_type == "Selling" else 0,
|
||||
"currency": args["currency"]
|
||||
}).insert()
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Price List",
|
||||
"price_list_name": pl_name,
|
||||
"enabled": 1,
|
||||
"buying": 1 if pl_type == "Buying" else 0,
|
||||
"selling": 1 if pl_type == "Selling" else 0,
|
||||
"currency": args["currency"],
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
def create_employee_for_self(args):
|
||||
if frappe.session.user == 'Administrator':
|
||||
if frappe.session.user == "Administrator":
|
||||
return
|
||||
|
||||
# create employee for self
|
||||
emp = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"employee_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 = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Employee",
|
||||
"employee_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)
|
||||
emp.insert(ignore_permissions=True)
|
||||
|
||||
|
||||
def create_territories():
|
||||
"""create two default territories, one for home country and one named Rest of the World"""
|
||||
from frappe.utils.nestedset import get_root_of
|
||||
|
||||
country = frappe.db.get_default("country")
|
||||
root_territory = get_root_of("Territory")
|
||||
|
||||
for name in (country, _("Rest Of The World")):
|
||||
if name and not frappe.db.exists("Territory", name):
|
||||
frappe.get_doc({
|
||||
"doctype": "Territory",
|
||||
"territory_name": name.replace("'", ""),
|
||||
"parent_territory": root_territory,
|
||||
"is_group": "No"
|
||||
}).insert()
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Territory",
|
||||
"territory_name": name.replace("'", ""),
|
||||
"parent_territory": root_territory,
|
||||
"is_group": "No",
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
def create_feed_and_todo():
|
||||
"""update Activity feed and create todo for creation of item, customer, vendor"""
|
||||
return
|
||||
|
||||
|
||||
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)
|
||||
fy = cstr(start_year) + "-" + cstr(start_year + 1)
|
||||
return fy
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,12 +12,12 @@ from frappe import _
|
||||
from frappe.utils.make_random import add_random_children
|
||||
|
||||
|
||||
def make_sample_data(domains, make_dependent = False):
|
||||
def make_sample_data(domains, make_dependent=False):
|
||||
"""Create a few opportunities, quotes, material requests, issues, todos, projects
|
||||
to help the user get started"""
|
||||
|
||||
if make_dependent:
|
||||
items = frappe.get_all("Item", {'is_sales_item': 1})
|
||||
items = frappe.get_all("Item", {"is_sales_item": 1})
|
||||
customers = frappe.get_all("Customer")
|
||||
warehouses = frappe.get_all("Warehouse")
|
||||
|
||||
@@ -33,91 +33,109 @@ def make_sample_data(domains, make_dependent = False):
|
||||
make_projects(domains)
|
||||
import_notification()
|
||||
|
||||
def make_opportunity(items, customer):
|
||||
b = frappe.get_doc({
|
||||
"doctype": "Opportunity",
|
||||
"opportunity_from": "Customer",
|
||||
"customer": customer,
|
||||
"opportunity_type": _("Sales"),
|
||||
"with_items": 1
|
||||
})
|
||||
|
||||
add_random_children(b, "items", rows=len(items), randomize = {
|
||||
"qty": (1, 5),
|
||||
"item_code": ["Item"]
|
||||
}, unique="item_code")
|
||||
def make_opportunity(items, customer):
|
||||
b = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Opportunity",
|
||||
"opportunity_from": "Customer",
|
||||
"customer": customer,
|
||||
"opportunity_type": _("Sales"),
|
||||
"with_items": 1,
|
||||
}
|
||||
)
|
||||
|
||||
add_random_children(
|
||||
b, "items", rows=len(items), randomize={"qty": (1, 5), "item_code": ["Item"]}, unique="item_code"
|
||||
)
|
||||
|
||||
b.insert(ignore_permissions=True)
|
||||
|
||||
b.add_comment('Comment', text="This is a dummy record")
|
||||
b.add_comment("Comment", text="This is a dummy record")
|
||||
|
||||
|
||||
def make_quote(items, customer):
|
||||
qtn = frappe.get_doc({
|
||||
"doctype": "Quotation",
|
||||
"quotation_to": "Customer",
|
||||
"party_name": customer,
|
||||
"order_type": "Sales"
|
||||
})
|
||||
qtn = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Quotation",
|
||||
"quotation_to": "Customer",
|
||||
"party_name": customer,
|
||||
"order_type": "Sales",
|
||||
}
|
||||
)
|
||||
|
||||
add_random_children(qtn, "items", rows=len(items), randomize = {
|
||||
"qty": (1, 5),
|
||||
"item_code": ["Item"]
|
||||
}, unique="item_code")
|
||||
add_random_children(
|
||||
qtn,
|
||||
"items",
|
||||
rows=len(items),
|
||||
randomize={"qty": (1, 5), "item_code": ["Item"]},
|
||||
unique="item_code",
|
||||
)
|
||||
|
||||
qtn.insert(ignore_permissions=True)
|
||||
|
||||
qtn.add_comment('Comment', text="This is a dummy record")
|
||||
qtn.add_comment("Comment", text="This is a dummy record")
|
||||
|
||||
|
||||
def make_material_request(items):
|
||||
for i in items:
|
||||
mr = frappe.get_doc({
|
||||
"doctype": "Material Request",
|
||||
"material_request_type": "Purchase",
|
||||
"schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7),
|
||||
"items": [{
|
||||
mr = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Material Request",
|
||||
"material_request_type": "Purchase",
|
||||
"schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7),
|
||||
"item_code": i.name,
|
||||
"qty": 10
|
||||
}]
|
||||
})
|
||||
"items": [
|
||||
{
|
||||
"schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7),
|
||||
"item_code": i.name,
|
||||
"qty": 10,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
mr.insert()
|
||||
mr.submit()
|
||||
|
||||
mr.add_comment('Comment', text="This is a dummy record")
|
||||
mr.add_comment("Comment", text="This is a dummy record")
|
||||
|
||||
|
||||
def make_issue():
|
||||
pass
|
||||
|
||||
|
||||
def make_projects(domains):
|
||||
current_date = frappe.utils.nowdate()
|
||||
project = frappe.get_doc({
|
||||
"doctype": "Project",
|
||||
"project_name": "ERPNext Implementation",
|
||||
})
|
||||
project = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Project",
|
||||
"project_name": "ERPNext Implementation",
|
||||
}
|
||||
)
|
||||
|
||||
tasks = [
|
||||
{
|
||||
"title": "Explore ERPNext",
|
||||
"start_date": current_date,
|
||||
"end_date": current_date,
|
||||
"file": "explore.md"
|
||||
}]
|
||||
"file": "explore.md",
|
||||
}
|
||||
]
|
||||
|
||||
if 'Education' in domains:
|
||||
if "Education" in domains:
|
||||
tasks += [
|
||||
{
|
||||
"title": _("Setup your Institute in ERPNext"),
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 1),
|
||||
"file": "education_masters.md"
|
||||
"file": "education_masters.md",
|
||||
},
|
||||
{
|
||||
"title": "Setup Master Data",
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 1),
|
||||
"file": "education_masters.md"
|
||||
}]
|
||||
"file": "education_masters.md",
|
||||
},
|
||||
]
|
||||
|
||||
else:
|
||||
tasks += [
|
||||
@@ -125,55 +143,59 @@ def make_projects(domains):
|
||||
"title": "Setup Your Company",
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 1),
|
||||
"file": "masters.md"
|
||||
"file": "masters.md",
|
||||
},
|
||||
{
|
||||
"title": "Start Tracking your Sales",
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 2),
|
||||
"file": "sales.md"
|
||||
"file": "sales.md",
|
||||
},
|
||||
{
|
||||
"title": "Start Managing Purchases",
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 3),
|
||||
"file": "purchase.md"
|
||||
"file": "purchase.md",
|
||||
},
|
||||
{
|
||||
"title": "Import Data",
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 4),
|
||||
"file": "import_data.md"
|
||||
"file": "import_data.md",
|
||||
},
|
||||
{
|
||||
"title": "Go Live!",
|
||||
"start_date": current_date,
|
||||
"end_date": frappe.utils.add_days(current_date, 5),
|
||||
"file": "go_live.md"
|
||||
}]
|
||||
"file": "go_live.md",
|
||||
},
|
||||
]
|
||||
|
||||
for t in tasks:
|
||||
with open (os.path.join(os.path.dirname(__file__), "tasks", t['file'])) as f:
|
||||
t['description'] = frappe.utils.md_to_html(f.read())
|
||||
del t['file']
|
||||
with open(os.path.join(os.path.dirname(__file__), "tasks", t["file"])) as f:
|
||||
t["description"] = frappe.utils.md_to_html(f.read())
|
||||
del t["file"]
|
||||
|
||||
project.append('tasks', t)
|
||||
project.append("tasks", t)
|
||||
|
||||
project.insert(ignore_permissions=True)
|
||||
|
||||
|
||||
def import_notification():
|
||||
'''Import notification for task start'''
|
||||
with open (os.path.join(os.path.dirname(__file__), "tasks/task_alert.json")) as f:
|
||||
"""Import notification for task start"""
|
||||
with open(os.path.join(os.path.dirname(__file__), "tasks/task_alert.json")) as f:
|
||||
notification = frappe.get_doc(json.loads(f.read())[0])
|
||||
notification.insert()
|
||||
|
||||
# trigger the first message!
|
||||
from frappe.email.doctype.notification.notification import trigger_daily_alerts
|
||||
|
||||
trigger_daily_alerts()
|
||||
|
||||
|
||||
def test_sample():
|
||||
frappe.db.sql('delete from `tabNotification`')
|
||||
frappe.db.sql('delete from tabProject')
|
||||
frappe.db.sql('delete from tabTask')
|
||||
make_projects('Education')
|
||||
frappe.db.sql("delete from `tabNotification`")
|
||||
frappe.db.sql("delete from tabProject")
|
||||
frappe.db.sql("delete from tabTask")
|
||||
make_projects("Education")
|
||||
import_notification()
|
||||
|
||||
@@ -10,11 +10,11 @@ from frappe import _
|
||||
|
||||
|
||||
def setup_taxes_and_charges(company_name: str, country: str):
|
||||
if not frappe.db.exists('Company', company_name):
|
||||
frappe.throw(_('Company {} does not exist yet. Taxes setup aborted.').format(company_name))
|
||||
if not frappe.db.exists("Company", company_name):
|
||||
frappe.throw(_("Company {} does not exist yet. Taxes setup aborted.").format(company_name))
|
||||
|
||||
file_path = os.path.join(os.path.dirname(__file__), '..', 'data', 'country_wise_tax.json')
|
||||
with open(file_path, 'r') as json_file:
|
||||
file_path = os.path.join(os.path.dirname(__file__), "..", "data", "country_wise_tax.json")
|
||||
with open(file_path, "r") as json_file:
|
||||
tax_data = json.load(json_file)
|
||||
|
||||
country_wise_tax = tax_data.get(country)
|
||||
@@ -22,7 +22,7 @@ def setup_taxes_and_charges(company_name: str, country: str):
|
||||
if not country_wise_tax:
|
||||
return
|
||||
|
||||
if 'chart_of_accounts' not in country_wise_tax:
|
||||
if "chart_of_accounts" not in country_wise_tax:
|
||||
country_wise_tax = simple_to_detailed(country_wise_tax)
|
||||
|
||||
from_detailed_data(company_name, country_wise_tax)
|
||||
@@ -36,39 +36,44 @@ def simple_to_detailed(templates):
|
||||
Example input:
|
||||
|
||||
{
|
||||
"France VAT 20%": {
|
||||
"account_name": "VAT 20%",
|
||||
"tax_rate": 20,
|
||||
"default": 1
|
||||
},
|
||||
"France VAT 10%": {
|
||||
"account_name": "VAT 10%",
|
||||
"tax_rate": 10
|
||||
}
|
||||
"France VAT 20%": {
|
||||
"account_name": "VAT 20%",
|
||||
"tax_rate": 20,
|
||||
"default": 1
|
||||
},
|
||||
"France VAT 10%": {
|
||||
"account_name": "VAT 10%",
|
||||
"tax_rate": 10
|
||||
}
|
||||
}
|
||||
"""
|
||||
return {
|
||||
'chart_of_accounts': {
|
||||
'*': {
|
||||
'item_tax_templates': [{
|
||||
'title': title,
|
||||
'taxes': [{
|
||||
'tax_type': {
|
||||
'account_name': data.get('account_name'),
|
||||
'tax_rate': data.get('tax_rate')
|
||||
}
|
||||
}]
|
||||
} for title, data in templates.items()],
|
||||
'*': [{
|
||||
'title': title,
|
||||
'is_default': data.get('default', 0),
|
||||
'taxes': [{
|
||||
'account_head': {
|
||||
'account_name': data.get('account_name'),
|
||||
'tax_rate': data.get('tax_rate')
|
||||
}
|
||||
}]
|
||||
} for title, data in templates.items()]
|
||||
"chart_of_accounts": {
|
||||
"*": {
|
||||
"item_tax_templates": [
|
||||
{
|
||||
"title": title,
|
||||
"taxes": [
|
||||
{"tax_type": {"account_name": data.get("account_name"), "tax_rate": data.get("tax_rate")}}
|
||||
],
|
||||
}
|
||||
for title, data in templates.items()
|
||||
],
|
||||
"*": [
|
||||
{
|
||||
"title": title,
|
||||
"is_default": data.get("default", 0),
|
||||
"taxes": [
|
||||
{
|
||||
"account_head": {
|
||||
"account_name": data.get("account_name"),
|
||||
"tax_rate": data.get("tax_rate"),
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
for title, data in templates.items()
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,13 +81,13 @@ def simple_to_detailed(templates):
|
||||
|
||||
def from_detailed_data(company_name, data):
|
||||
"""Create Taxes and Charges Templates from detailed data."""
|
||||
coa_name = frappe.db.get_value('Company', company_name, 'chart_of_accounts')
|
||||
coa_data = data.get('chart_of_accounts', {})
|
||||
tax_templates = coa_data.get(coa_name) or coa_data.get('*', {})
|
||||
tax_categories = data.get('tax_categories')
|
||||
sales_tax_templates = tax_templates.get('sales_tax_templates') or tax_templates.get('*', {})
|
||||
purchase_tax_templates = tax_templates.get('purchase_tax_templates') or tax_templates.get('*', {})
|
||||
item_tax_templates = tax_templates.get('item_tax_templates') or tax_templates.get('*', {})
|
||||
coa_name = frappe.db.get_value("Company", company_name, "chart_of_accounts")
|
||||
coa_data = data.get("chart_of_accounts", {})
|
||||
tax_templates = coa_data.get(coa_name) or coa_data.get("*", {})
|
||||
tax_categories = data.get("tax_categories")
|
||||
sales_tax_templates = tax_templates.get("sales_tax_templates") or tax_templates.get("*", {})
|
||||
purchase_tax_templates = tax_templates.get("purchase_tax_templates") or tax_templates.get("*", {})
|
||||
item_tax_templates = tax_templates.get("item_tax_templates") or tax_templates.get("*", {})
|
||||
|
||||
if tax_categories:
|
||||
for tax_category in tax_categories:
|
||||
@@ -90,11 +95,11 @@ def from_detailed_data(company_name, data):
|
||||
|
||||
if sales_tax_templates:
|
||||
for template in sales_tax_templates:
|
||||
make_taxes_and_charges_template(company_name, 'Sales Taxes and Charges Template', template)
|
||||
make_taxes_and_charges_template(company_name, "Sales Taxes and Charges Template", template)
|
||||
|
||||
if purchase_tax_templates:
|
||||
for template in purchase_tax_templates:
|
||||
make_taxes_and_charges_template(company_name, 'Purchase Taxes and Charges Template', template)
|
||||
make_taxes_and_charges_template(company_name, "Purchase Taxes and Charges Template", template)
|
||||
|
||||
if item_tax_templates:
|
||||
for template in item_tax_templates:
|
||||
@@ -102,40 +107,45 @@ def from_detailed_data(company_name, data):
|
||||
|
||||
|
||||
def update_regional_tax_settings(country, company):
|
||||
path = frappe.get_app_path('erpnext', 'regional', frappe.scrub(country))
|
||||
path = frappe.get_app_path("erpnext", "regional", frappe.scrub(country))
|
||||
if os.path.exists(path.encode("utf-8")):
|
||||
try:
|
||||
module_name = "erpnext.regional.{0}.setup.update_regional_tax_settings".format(frappe.scrub(country))
|
||||
module_name = "erpnext.regional.{0}.setup.update_regional_tax_settings".format(
|
||||
frappe.scrub(country)
|
||||
)
|
||||
frappe.get_attr(module_name)(country, company)
|
||||
except Exception as e:
|
||||
# Log error and ignore if failed to setup regional tax settings
|
||||
frappe.log_error()
|
||||
pass
|
||||
|
||||
def make_taxes_and_charges_template(company_name, doctype, template):
|
||||
template['company'] = company_name
|
||||
template['doctype'] = doctype
|
||||
|
||||
if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}):
|
||||
def make_taxes_and_charges_template(company_name, doctype, template):
|
||||
template["company"] = company_name
|
||||
template["doctype"] = doctype
|
||||
|
||||
if frappe.db.exists(doctype, {"title": template.get("title"), "company": company_name}):
|
||||
return
|
||||
|
||||
for tax_row in template.get('taxes'):
|
||||
account_data = tax_row.get('account_head')
|
||||
for tax_row in template.get("taxes"):
|
||||
account_data = tax_row.get("account_head")
|
||||
tax_row_defaults = {
|
||||
'category': 'Total',
|
||||
'charge_type': 'On Net Total',
|
||||
'cost_center': frappe.db.get_value('Company', company_name, 'cost_center')
|
||||
"category": "Total",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": frappe.db.get_value("Company", company_name, "cost_center"),
|
||||
}
|
||||
|
||||
if doctype == 'Purchase Taxes and Charges Template':
|
||||
tax_row_defaults['add_deduct_tax'] = 'Add'
|
||||
if doctype == "Purchase Taxes and Charges Template":
|
||||
tax_row_defaults["add_deduct_tax"] = "Add"
|
||||
|
||||
# if account_head is a dict, search or create the account and get it's name
|
||||
if isinstance(account_data, dict):
|
||||
tax_row_defaults['description'] = '{0} @ {1}'.format(account_data.get('account_name'), account_data.get('tax_rate'))
|
||||
tax_row_defaults['rate'] = account_data.get('tax_rate')
|
||||
tax_row_defaults["description"] = "{0} @ {1}".format(
|
||||
account_data.get("account_name"), account_data.get("tax_rate")
|
||||
)
|
||||
tax_row_defaults["rate"] = account_data.get("tax_rate")
|
||||
account = get_or_create_account(company_name, account_data)
|
||||
tax_row['account_head'] = account.name
|
||||
tax_row["account_head"] = account.name
|
||||
|
||||
# use the default value if nothing other is specified
|
||||
for fieldname, default_value in tax_row_defaults.items():
|
||||
@@ -151,28 +161,29 @@ def make_taxes_and_charges_template(company_name, doctype, template):
|
||||
doc.insert(ignore_permissions=True)
|
||||
return doc
|
||||
|
||||
|
||||
def make_item_tax_template(company_name, template):
|
||||
"""Create an Item Tax Template.
|
||||
|
||||
This requires a separate method because Item Tax Template is structured
|
||||
differently from Sales and Purchase Tax Templates.
|
||||
"""
|
||||
doctype = 'Item Tax Template'
|
||||
template['company'] = company_name
|
||||
template['doctype'] = doctype
|
||||
doctype = "Item Tax Template"
|
||||
template["company"] = company_name
|
||||
template["doctype"] = doctype
|
||||
|
||||
if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}):
|
||||
if frappe.db.exists(doctype, {"title": template.get("title"), "company": company_name}):
|
||||
return
|
||||
|
||||
for tax_row in template.get('taxes'):
|
||||
account_data = tax_row.get('tax_type')
|
||||
for tax_row in template.get("taxes"):
|
||||
account_data = tax_row.get("tax_type")
|
||||
|
||||
# if tax_type is a dict, search or create the account and get it's name
|
||||
if isinstance(account_data, dict):
|
||||
account = get_or_create_account(company_name, account_data)
|
||||
tax_row['tax_type'] = account.name
|
||||
if 'tax_rate' not in tax_row:
|
||||
tax_row['tax_rate'] = account_data.get('tax_rate')
|
||||
tax_row["tax_type"] = account.name
|
||||
if "tax_rate" not in tax_row:
|
||||
tax_row["tax_rate"] = account_data.get("tax_rate")
|
||||
|
||||
doc = frappe.get_doc(template)
|
||||
|
||||
@@ -183,46 +194,47 @@ def make_item_tax_template(company_name, template):
|
||||
doc.insert(ignore_permissions=True)
|
||||
return doc
|
||||
|
||||
|
||||
def make_tax_category(tax_category):
|
||||
""" Make tax category based on title if not already created """
|
||||
doctype = 'Tax Category'
|
||||
if not frappe.db.exists(doctype, tax_category['title']):
|
||||
tax_category['doctype'] = doctype
|
||||
"""Make tax category based on title if not already created"""
|
||||
doctype = "Tax Category"
|
||||
if not frappe.db.exists(doctype, tax_category["title"]):
|
||||
tax_category["doctype"] = doctype
|
||||
doc = frappe.get_doc(tax_category)
|
||||
doc.flags.ignore_links = True
|
||||
doc.flags.ignore_validate = True
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
|
||||
def get_or_create_account(company_name, account):
|
||||
"""
|
||||
Check if account already exists. If not, create it.
|
||||
Return a tax account or None.
|
||||
"""
|
||||
default_root_type = 'Liability'
|
||||
root_type = account.get('root_type', default_root_type)
|
||||
default_root_type = "Liability"
|
||||
root_type = account.get("root_type", default_root_type)
|
||||
|
||||
existing_accounts = frappe.get_all('Account',
|
||||
filters={
|
||||
'company': company_name,
|
||||
'root_type': root_type
|
||||
},
|
||||
existing_accounts = frappe.get_all(
|
||||
"Account",
|
||||
filters={"company": company_name, "root_type": root_type},
|
||||
or_filters={
|
||||
'account_name': account.get('account_name'),
|
||||
'account_number': account.get('account_number')
|
||||
})
|
||||
"account_name": account.get("account_name"),
|
||||
"account_number": account.get("account_number"),
|
||||
},
|
||||
)
|
||||
|
||||
if existing_accounts:
|
||||
return frappe.get_doc('Account', existing_accounts[0].name)
|
||||
return frappe.get_doc("Account", existing_accounts[0].name)
|
||||
|
||||
tax_group = get_or_create_tax_group(company_name, root_type)
|
||||
|
||||
account['doctype'] = 'Account'
|
||||
account['company'] = company_name
|
||||
account['parent_account'] = tax_group
|
||||
account['report_type'] = 'Balance Sheet'
|
||||
account['account_type'] = 'Tax'
|
||||
account['root_type'] = root_type
|
||||
account['is_group'] = 0
|
||||
account["doctype"] = "Account"
|
||||
account["company"] = company_name
|
||||
account["parent_account"] = tax_group
|
||||
account["report_type"] = "Balance Sheet"
|
||||
account["account_type"] = "Tax"
|
||||
account["root_type"] = root_type
|
||||
account["is_group"] = 0
|
||||
|
||||
doc = frappe.get_doc(account)
|
||||
doc.flags.ignore_links = True
|
||||
@@ -230,50 +242,53 @@ def get_or_create_account(company_name, account):
|
||||
doc.insert(ignore_permissions=True, ignore_mandatory=True)
|
||||
return doc
|
||||
|
||||
|
||||
def get_or_create_tax_group(company_name, root_type):
|
||||
# Look for a group account of type 'Tax'
|
||||
tax_group_name = frappe.db.get_value('Account', {
|
||||
'is_group': 1,
|
||||
'root_type': root_type,
|
||||
'account_type': 'Tax',
|
||||
'company': company_name
|
||||
})
|
||||
tax_group_name = frappe.db.get_value(
|
||||
"Account",
|
||||
{"is_group": 1, "root_type": root_type, "account_type": "Tax", "company": company_name},
|
||||
)
|
||||
|
||||
if tax_group_name:
|
||||
return tax_group_name
|
||||
|
||||
# Look for a group account named 'Duties and Taxes' or 'Tax Assets'
|
||||
account_name = _('Duties and Taxes') if root_type == 'Liability' else _('Tax Assets')
|
||||
tax_group_name = frappe.db.get_value('Account', {
|
||||
'is_group': 1,
|
||||
'root_type': root_type,
|
||||
'account_name': account_name,
|
||||
'company': company_name
|
||||
})
|
||||
account_name = _("Duties and Taxes") if root_type == "Liability" else _("Tax Assets")
|
||||
tax_group_name = frappe.db.get_value(
|
||||
"Account",
|
||||
{"is_group": 1, "root_type": root_type, "account_name": account_name, "company": company_name},
|
||||
)
|
||||
|
||||
if tax_group_name:
|
||||
return tax_group_name
|
||||
|
||||
# Create a new group account named 'Duties and Taxes' or 'Tax Assets' just
|
||||
# below the root account
|
||||
root_account = frappe.get_all('Account', {
|
||||
'is_group': 1,
|
||||
'root_type': root_type,
|
||||
'company': company_name,
|
||||
'report_type': 'Balance Sheet',
|
||||
'parent_account': ('is', 'not set')
|
||||
}, limit=1)[0]
|
||||
root_account = frappe.get_all(
|
||||
"Account",
|
||||
{
|
||||
"is_group": 1,
|
||||
"root_type": root_type,
|
||||
"company": company_name,
|
||||
"report_type": "Balance Sheet",
|
||||
"parent_account": ("is", "not set"),
|
||||
},
|
||||
limit=1,
|
||||
)[0]
|
||||
|
||||
tax_group_account = frappe.get_doc({
|
||||
'doctype': 'Account',
|
||||
'company': company_name,
|
||||
'is_group': 1,
|
||||
'report_type': 'Balance Sheet',
|
||||
'root_type': root_type,
|
||||
'account_type': 'Tax',
|
||||
'account_name': account_name,
|
||||
'parent_account': root_account.name
|
||||
})
|
||||
tax_group_account = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Account",
|
||||
"company": company_name,
|
||||
"is_group": 1,
|
||||
"report_type": "Balance Sheet",
|
||||
"root_type": root_type,
|
||||
"account_type": "Tax",
|
||||
"account_name": account_name,
|
||||
"parent_account": root_account.name,
|
||||
}
|
||||
)
|
||||
|
||||
tax_group_account.flags.ignore_links = True
|
||||
tax_group_account.flags.ignore_validate = True
|
||||
@@ -285,11 +300,11 @@ def get_or_create_tax_group(company_name, root_type):
|
||||
|
||||
|
||||
def make_tax_catgory(tax_category):
|
||||
doctype = 'Tax Category'
|
||||
doctype = "Tax Category"
|
||||
if isinstance(tax_category, str):
|
||||
tax_category = {'title': tax_category}
|
||||
tax_category = {"title": tax_category}
|
||||
|
||||
tax_category['doctype'] = doctype
|
||||
if not frappe.db.exists(doctype, tax_category['title']):
|
||||
tax_category["doctype"] = doctype
|
||||
if not frappe.db.exists(doctype, tax_category["title"]):
|
||||
doc = frappe.get_doc(tax_category)
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
@@ -14,96 +14,66 @@ def get_setup_stages(args=None):
|
||||
if frappe.db.sql("select name from tabCompany"):
|
||||
stages = [
|
||||
{
|
||||
'status': _('Wrapping up'),
|
||||
'fail_msg': _('Failed to login'),
|
||||
'tasks': [
|
||||
{
|
||||
'fn': fin,
|
||||
'args': args,
|
||||
'fail_msg': _("Failed to login")
|
||||
}
|
||||
]
|
||||
"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")
|
||||
}
|
||||
]
|
||||
"status": _("Installing presets"),
|
||||
"fail_msg": _("Failed to install presets"),
|
||||
"tasks": [{"fn": stage_fixtures, "args": args, "fail_msg": _("Failed to install presets")}],
|
||||
},
|
||||
{
|
||||
'status': _('Setting up company'),
|
||||
'fail_msg': _('Failed to setup company'),
|
||||
'tasks': [
|
||||
{
|
||||
'fn': setup_company,
|
||||
'args': args,
|
||||
'fail_msg': _("Failed to setup company")
|
||||
}
|
||||
]
|
||||
"status": _("Setting up company"),
|
||||
"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': [
|
||||
{
|
||||
'fn': setup_defaults,
|
||||
'args': args,
|
||||
'fail_msg': _("Failed to setup defaults")
|
||||
},
|
||||
{
|
||||
'fn': stage_four,
|
||||
'args': args,
|
||||
'fail_msg': _("Failed to create website")
|
||||
},
|
||||
{
|
||||
'fn': set_active_domains,
|
||||
'args': args,
|
||||
'fail_msg': _("Failed to add Domain")
|
||||
},
|
||||
]
|
||||
"status": _("Setting defaults"),
|
||||
"fail_msg": "Failed to set defaults",
|
||||
"tasks": [
|
||||
{"fn": setup_defaults, "args": args, "fail_msg": _("Failed to setup defaults")},
|
||||
{"fn": stage_four, "args": args, "fail_msg": _("Failed to create website")},
|
||||
{"fn": set_active_domains, "args": args, "fail_msg": _("Failed to add Domain")},
|
||||
],
|
||||
},
|
||||
{
|
||||
'status': _('Wrapping up'),
|
||||
'fail_msg': _('Failed to login'),
|
||||
'tasks': [
|
||||
{
|
||||
'fn': fin,
|
||||
'args': args,
|
||||
'fail_msg': _("Failed to login")
|
||||
}
|
||||
]
|
||||
}
|
||||
"status": _("Wrapping up"),
|
||||
"fail_msg": _("Failed to login"),
|
||||
"tasks": [{"fn": fin, "args": args, "fail_msg": _("Failed to login")}],
|
||||
},
|
||||
]
|
||||
|
||||
return stages
|
||||
|
||||
|
||||
def stage_fixtures(args):
|
||||
fixtures.install(args.get('country'))
|
||||
fixtures.install(args.get("country"))
|
||||
|
||||
|
||||
def setup_company(args):
|
||||
fixtures.install_company(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()
|
||||
company_setup.create_logo(args)
|
||||
|
||||
|
||||
def fin(args):
|
||||
frappe.local.message_log = []
|
||||
login_as_first_user(args)
|
||||
|
||||
make_sample_data(args.get('domains'))
|
||||
make_sample_data(args.get("domains"))
|
||||
|
||||
|
||||
def make_sample_data(domains):
|
||||
try:
|
||||
@@ -114,6 +84,7 @@ def make_sample_data(domains):
|
||||
frappe.message_log.pop()
|
||||
pass
|
||||
|
||||
|
||||
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"))
|
||||
@@ -127,6 +98,7 @@ def setup_complete(args=None):
|
||||
stage_four(args)
|
||||
fin(args)
|
||||
|
||||
|
||||
def set_active_domains(args):
|
||||
domain_settings = frappe.get_single('Domain Settings')
|
||||
domain_settings.set_active_domains(args.get('domains'))
|
||||
domain_settings = frappe.get_single("Domain Settings")
|
||||
domain_settings.set_active_domains(args.get("domains"))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
@@ -6,8 +5,7 @@ from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
|
||||
|
||||
|
||||
def complete():
|
||||
with open(os.path.join(os.path.dirname(__file__),
|
||||
'data', 'test_mfg.json'), 'r') as f:
|
||||
with open(os.path.join(os.path.dirname(__file__), "data", "test_mfg.json"), "r") as f:
|
||||
data = json.loads(f.read())
|
||||
|
||||
setup_complete(data)
|
||||
|
||||
Reference in New Issue
Block a user