chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config
* chore: Sort imports with isort
* chore: Clean up imports with pycln
* chore: Sort imports with isort
* chore: Fix import issues
* chore: Clean up sider issues
* chore: Remove import errors from flake8 ignore list
* chore: Clean up lint issues
diff --git a/erpnext/setup/default_energy_point_rules.py b/erpnext/setup/default_energy_point_rules.py
index 8dbccc4..c41d000 100644
--- a/erpnext/setup/default_energy_point_rules.py
+++ b/erpnext/setup/default_energy_point_rules.py
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
+
from frappe import _
doctype_rule_map = {
diff --git a/erpnext/setup/default_success_action.py b/erpnext/setup/default_success_action.py
index 827839f..be072fc 100644
--- a/erpnext/setup/default_success_action.py
+++ b/erpnext/setup/default_success_action.py
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
+
from frappe import _
doctype_list = [
diff --git a/erpnext/setup/doctype/authorization_control/authorization_control.py b/erpnext/setup/doctype/authorization_control/authorization_control.py
index fec5c7c..332d7f4 100644
--- a/erpnext/setup/doctype/authorization_control/authorization_control.py
+++ b/erpnext/setup/doctype/authorization_control/authorization_control.py
@@ -2,11 +2,14 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
-from frappe.utils import cstr, flt, has_common, comma_or
-from frappe import session, _
+from frappe import _, session
+from frappe.utils import comma_or, cstr, flt, has_common
+
from erpnext.utilities.transaction_base import TransactionBase
+
class AuthorizationControl(TransactionBase):
def get_appr_user_role(self, det, doctype_name, total, based_on, condition, item, company):
amt_list, appr_users, appr_roles = [], [], []
diff --git a/erpnext/setup/doctype/authorization_rule/authorization_rule.py b/erpnext/setup/doctype/authorization_rule/authorization_rule.py
index eb8e6eb..ab0f420 100644
--- a/erpnext/setup/doctype/authorization_rule/authorization_rule.py
+++ b/erpnext/setup/doctype/authorization_rule/authorization_rule.py
@@ -2,12 +2,12 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
-
-from frappe.utils import cstr, flt
-from frappe import _, msgprint
-
+from frappe import _
from frappe.model.document import Document
+from frappe.utils import cstr, flt
+
class AuthorizationRule(Document):
def check_duplicate_entry(self):
diff --git a/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py b/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py
index 332f103..8a0f664 100644
--- a/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py
+++ b/erpnext/setup/doctype/authorization_rule/test_authorization_rule.py
@@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
-import frappe
import unittest
# test_records = frappe.get_test_records('Authorization Rule')
diff --git a/erpnext/setup/doctype/brand/brand.py b/erpnext/setup/doctype/brand/brand.py
index a8d1cf8..4cfb018 100644
--- a/erpnext/setup/doctype/brand/brand.py
+++ b/erpnext/setup/doctype/brand/brand.py
@@ -2,11 +2,13 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
+
import copy
+import frappe
from frappe.model.document import Document
+
class Brand(Document):
pass
diff --git a/erpnext/setup/doctype/brand/test_brand.py b/erpnext/setup/doctype/brand/test_brand.py
index 25ed86e..16873c9 100644
--- a/erpnext/setup/doctype/brand/test_brand.py
+++ b/erpnext/setup/doctype/brand/test_brand.py
@@ -2,6 +2,6 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('Brand')
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 6dee2ad..6257d56 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -2,23 +2,24 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe, os, json
-from frappe import _
-from frappe.utils import get_timestamp
-from frappe.utils import cint, today, formatdate
-import frappe.defaults
-from frappe.cache_manager import clear_defaults_cache
-
-from frappe.model.document import Document
-from frappe.contacts.address_and_contact import load_address_and_contact
-from frappe.utils.nestedset import NestedSet
-
-from past.builtins import cmp
import functools
+import json
+import os
+
+import frappe
+import frappe.defaults
+from frappe import _
+from frappe.cache_manager import clear_defaults_cache
+from frappe.contacts.address_and_contact import load_address_and_contact
+from frappe.utils import cint, formatdate, get_timestamp, today
+from frappe.utils.nestedset import NestedSet
+from past.builtins import cmp
+
from erpnext.accounts.doctype.account.account import get_account_currency
from erpnext.setup.setup_wizard.operations.taxes_setup import setup_taxes_and_charges
+
class Company(NestedSet):
nsm_parent_field = 'parent_company'
@@ -479,8 +480,9 @@
def update_company_monthly_sales(company):
'''Cache past year monthly sales of every company based on sales invoices'''
- from frappe.utils.goal import get_monthly_results
import json
+
+ from frappe.utils.goal import get_monthly_results
filter_str = "company = {0} and status != 'Draft' and docstatus=1".format(frappe.db.escape(company))
month_to_value_dict = get_monthly_results("Sales Invoice", "base_grand_total",
"posting_date", filter_str, "sum")
diff --git a/erpnext/setup/doctype/company/company_dashboard.py b/erpnext/setup/doctype/company/company_dashboard.py
index 2d76028..3afea09 100644
--- a/erpnext/setup/doctype/company/company_dashboard.py
+++ b/erpnext/setup/doctype/company/company_dashboard.py
@@ -1,6 +1,8 @@
from __future__ import unicode_literals
+
from frappe import _
+
def get_data():
return {
'graph': True,
diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py
index 1b7fd4f..abc4689 100644
--- a/erpnext/setup/doctype/company/test_company.py
+++ b/erpnext/setup/doctype/company/test_company.py
@@ -2,12 +2,16 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
-import unittest
import json
+import unittest
+
+import frappe
from frappe import _
from frappe.utils import random_string
-from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import get_charts_for_country
+
+from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import (
+ get_charts_for_country,
+)
test_ignore = ["Account", "Cost Center", "Payment Terms Template", "Salary Component", "Warehouse"]
test_dependencies = ["Fiscal Year"]
diff --git a/erpnext/setup/doctype/currency_exchange/currency_exchange.py b/erpnext/setup/doctype/currency_exchange/currency_exchange.py
index 6480f60..0b86e29 100644
--- a/erpnext/setup/doctype/currency_exchange/currency_exchange.py
+++ b/erpnext/setup/doctype/currency_exchange/currency_exchange.py
@@ -4,10 +4,11 @@
# For license information, please see license.txt
from __future__ import unicode_literals
-import frappe
+
from frappe import _, throw
from frappe.model.document import Document
-from frappe.utils import get_datetime_str, formatdate, nowdate, cint
+from frappe.utils import cint, formatdate, get_datetime_str, nowdate
+
class CurrencyExchange(Document):
def autoname(self):
diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py
index 0eb7e7b..2b007e9 100644
--- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py
+++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py
@@ -1,11 +1,13 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
-import frappe, unittest
+import unittest
from unittest import mock
-from frappe.utils import flt
+
+import frappe
+from frappe.utils import cint, flt
+
from erpnext.setup.utils import get_exchange_rate
-from frappe.utils import cint
test_records = frappe.get_test_records('Currency Exchange')
diff --git a/erpnext/setup/doctype/customer_group/customer_group.py b/erpnext/setup/doctype/customer_group/customer_group.py
index c06669b..6e72810 100644
--- a/erpnext/setup/doctype/customer_group/customer_group.py
+++ b/erpnext/setup/doctype/customer_group/customer_group.py
@@ -2,11 +2,12 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
from frappe import _
-
-
from frappe.utils.nestedset import NestedSet, get_root_of
+
+
class CustomerGroup(NestedSet):
nsm_parent_field = 'parent_customer_group'
def validate(self):
diff --git a/erpnext/setup/doctype/customer_group/test_customer_group.py b/erpnext/setup/doctype/customer_group/test_customer_group.py
index ec90b37..e04b79b 100644
--- a/erpnext/setup/doctype/customer_group/test_customer_group.py
+++ b/erpnext/setup/doctype/customer_group/test_customer_group.py
@@ -7,4 +7,5 @@
import frappe
+
test_records = frappe.get_test_records('Customer Group')
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index 217829f..4e9a8cc 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -2,19 +2,34 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
-from frappe import _
-from frappe.utils import (fmt_money, formatdate, format_time, now_datetime,
- get_url_to_form, get_url_to_list, flt, get_link_to_report, add_to_date, today)
+
from datetime import timedelta
-from dateutil.relativedelta import relativedelta
-from frappe.core.doctype.user.user import STANDARD_USERS
+
+import frappe
import frappe.desk.notifications
+from dateutil.relativedelta import relativedelta
+from frappe import _
+from frappe.core.doctype.user.user import STANDARD_USERS
+from frappe.utils import (
+ add_to_date,
+ flt,
+ fmt_money,
+ format_time,
+ formatdate,
+ get_link_to_report,
+ get_url_to_form,
+ get_url_to_list,
+ now_datetime,
+ today,
+)
+
from erpnext.accounts.utils import get_balance_on, get_count_on, get_fiscal_year
user_specific_content = ["calendar_events", "todo_list"]
from frappe.model.document import Document
+
+
class EmailDigest(Document):
def __init__(self, *args, **kwargs):
super(EmailDigest, self).__init__(*args, **kwargs)
diff --git a/erpnext/setup/doctype/email_digest/quotes.py b/erpnext/setup/doctype/email_digest/quotes.py
index 5451ee1..c77fe82 100644
--- a/erpnext/setup/doctype/email_digest/quotes.py
+++ b/erpnext/setup/doctype/email_digest/quotes.py
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+
import random
+
def get_random_quote():
quotes = [
("Start by doing what's necessary; then do what's possible; and suddenly you are doing the impossible.", "Francis of Assisi"),
diff --git a/erpnext/setup/doctype/email_digest/test_email_digest.py b/erpnext/setup/doctype/email_digest/test_email_digest.py
index afe693a..b3d0ce3 100644
--- a/erpnext/setup/doctype/email_digest/test_email_digest.py
+++ b/erpnext/setup/doctype/email_digest/test_email_digest.py
@@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
-import frappe
import unittest
# test_records = frappe.get_test_records('Email Digest')
diff --git a/erpnext/setup/doctype/email_digest_recipient/email_digest_recipient.py b/erpnext/setup/doctype/email_digest_recipient/email_digest_recipient.py
index 968c51c..5c8d695 100644
--- a/erpnext/setup/doctype/email_digest_recipient/email_digest_recipient.py
+++ b/erpnext/setup/doctype/email_digest_recipient/email_digest_recipient.py
@@ -3,8 +3,10 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+
# import frappe
from frappe.model.document import Document
+
class EmailDigestRecipient(Document):
pass
diff --git a/erpnext/setup/doctype/global_defaults/global_defaults.py b/erpnext/setup/doctype/global_defaults/global_defaults.py
index a0ba1ef..66d3b9e 100644
--- a/erpnext/setup/doctype/global_defaults/global_defaults.py
+++ b/erpnext/setup/doctype/global_defaults/global_defaults.py
@@ -2,11 +2,12 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
"""Global Defaults"""
import frappe
import frappe.defaults
-from frappe.utils import cint
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
+from frappe.utils import cint
keydict = {
# "key in defaults": "key in Global Defaults"
@@ -22,6 +23,7 @@
from frappe.model.document import Document
+
class GlobalDefaults(Document):
def on_update(self):
diff --git a/erpnext/setup/doctype/global_defaults/test_global_defaults.py b/erpnext/setup/doctype/global_defaults/test_global_defaults.py
index 0495af7..70a7c08 100644
--- a/erpnext/setup/doctype/global_defaults/test_global_defaults.py
+++ b/erpnext/setup/doctype/global_defaults/test_global_defaults.py
@@ -3,8 +3,8 @@
# See license.txt
from __future__ import unicode_literals
-import frappe
import unittest
+
class TestGlobalDefaults(unittest.TestCase):
pass
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index c46b6cc..ddf3e66 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -2,19 +2,22 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
+
import copy
+
+import frappe
from frappe import _
-from frappe.utils import nowdate, cint, cstr
+from frappe.utils import cint, cstr, nowdate
from frappe.utils.nestedset import NestedSet
-from frappe.website.website_generator import WebsiteGenerator
from frappe.website.utils import clear_cache
-from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
-from erpnext.shopping_cart.product_info import set_product_info_for_website
-from erpnext.utilities.product import get_qty_in_stock
+from frappe.website.website_generator import WebsiteGenerator
from six.moves.urllib.parse import quote
-from erpnext.shopping_cart.product_query import ProductQuery
+
from erpnext.shopping_cart.filters import ProductFiltersBuilder
+from erpnext.shopping_cart.product_info import set_product_info_for_website
+from erpnext.shopping_cart.product_query import ProductQuery
+from erpnext.utilities.product import get_qty_in_stock
+
class ItemGroup(NestedSet, WebsiteGenerator):
nsm_parent_field = 'parent_item_group'
diff --git a/erpnext/setup/doctype/item_group/test_item_group.py b/erpnext/setup/doctype/item_group/test_item_group.py
index 745b13a..a816f39 100644
--- a/erpnext/setup/doctype/item_group/test_item_group.py
+++ b/erpnext/setup/doctype/item_group/test_item_group.py
@@ -2,10 +2,18 @@
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
+
import unittest
+
import frappe
-from frappe.utils.nestedset import NestedSetRecursionError, NestedSetMultipleRootsError, \
- NestedSetChildExistsError, NestedSetInvalidMergeError, rebuild_tree, get_ancestors_of
+from frappe.utils.nestedset import (
+ NestedSetChildExistsError,
+ NestedSetInvalidMergeError,
+ NestedSetMultipleRootsError,
+ NestedSetRecursionError,
+ get_ancestors_of,
+ rebuild_tree,
+)
test_records = frappe.get_test_records('Item Group')
diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py
index c5d5747..005cfec 100644
--- a/erpnext/setup/doctype/naming_series/naming_series.py
+++ b/erpnext/setup/doctype/naming_series/naming_series.py
@@ -2,15 +2,15 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
-
-from frappe.utils import cstr, cint
-from frappe import msgprint, throw, _
-
+from frappe import _, msgprint, throw
+from frappe.core.doctype.doctype.doctype import validate_series
from frappe.model.document import Document
from frappe.model.naming import parse_naming_series
from frappe.permissions import get_doctypes_with_read
-from frappe.core.doctype.doctype.doctype import validate_series
+from frappe.utils import cint, cstr
+
class NamingSeriesNotSetError(frappe.ValidationError): pass
diff --git a/erpnext/setup/doctype/party_type/party_type.py b/erpnext/setup/doctype/party_type/party_type.py
index 96e6093..8424c7f 100644
--- a/erpnext/setup/doctype/party_type/party_type.py
+++ b/erpnext/setup/doctype/party_type/party_type.py
@@ -3,9 +3,11 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+
import frappe
from frappe.model.document import Document
+
class PartyType(Document):
pass
diff --git a/erpnext/setup/doctype/party_type/test_party_type.py b/erpnext/setup/doctype/party_type/test_party_type.py
index 079fe2f..e5f2908 100644
--- a/erpnext/setup/doctype/party_type/test_party_type.py
+++ b/erpnext/setup/doctype/party_type/test_party_type.py
@@ -3,7 +3,6 @@
# See license.txt
from __future__ import unicode_literals
-import frappe
import unittest
# test_records = frappe.get_test_records('Party Type')
diff --git a/erpnext/setup/doctype/print_heading/print_heading.py b/erpnext/setup/doctype/print_heading/print_heading.py
index 3d5cd2d..cf25638 100644
--- a/erpnext/setup/doctype/print_heading/print_heading.py
+++ b/erpnext/setup/doctype/print_heading/print_heading.py
@@ -2,9 +2,9 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
from frappe.model.document import Document
+
class PrintHeading(Document):
pass
diff --git a/erpnext/setup/doctype/print_heading/test_print_heading.py b/erpnext/setup/doctype/print_heading/test_print_heading.py
index b2be2e3..06f801a 100644
--- a/erpnext/setup/doctype/print_heading/test_print_heading.py
+++ b/erpnext/setup/doctype/print_heading/test_print_heading.py
@@ -2,6 +2,6 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('Print Heading')
diff --git a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.py b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.py
index 42c5a5a..9131cc3 100644
--- a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.py
+++ b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.py
@@ -2,9 +2,9 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
from frappe.model.document import Document
+
class QuotationLostReason(Document):
pass
diff --git a/erpnext/setup/doctype/quotation_lost_reason/test_quotation_lost_reason.py b/erpnext/setup/doctype/quotation_lost_reason/test_quotation_lost_reason.py
index f6b30b6..ab8d61f 100644
--- a/erpnext/setup/doctype/quotation_lost_reason/test_quotation_lost_reason.py
+++ b/erpnext/setup/doctype/quotation_lost_reason/test_quotation_lost_reason.py
@@ -2,6 +2,6 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('Quotation Lost Reason')
diff --git a/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py b/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py
index 7bb8d02..434f24e 100644
--- a/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py
+++ b/erpnext/setup/doctype/quotation_lost_reason_detail/quotation_lost_reason_detail.py
@@ -3,8 +3,10 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+
# import frappe
from frappe.model.document import Document
+
class QuotationLostReasonDetail(Document):
pass
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.py b/erpnext/setup/doctype/sales_partner/sales_partner.py
index 675f9ca..6c741a8 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.py
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.py
@@ -2,10 +2,12 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
+from frappe.contacts.address_and_contact import load_address_and_contact
from frappe.utils import cstr, filter_strip_join
from frappe.website.website_generator import WebsiteGenerator
-from frappe.contacts.address_and_contact import load_address_and_contact
+
class SalesPartner(WebsiteGenerator):
website = frappe._dict(
diff --git a/erpnext/setup/doctype/sales_partner/test_sales_partner.py b/erpnext/setup/doctype/sales_partner/test_sales_partner.py
index 4548a4e..6ece239 100644
--- a/erpnext/setup/doctype/sales_partner/test_sales_partner.py
+++ b/erpnext/setup/doctype/sales_partner/test_sales_partner.py
@@ -2,8 +2,8 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('Sales Partner')
test_ignore = ["Item Group"]
diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py
index 19c2e5b..c7cad6b 100644
--- a/erpnext/setup/doctype/sales_person/sales_person.py
+++ b/erpnext/setup/doctype/sales_person/sales_person.py
@@ -2,12 +2,15 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
from frappe import _
from frappe.utils import flt
from frappe.utils.nestedset import NestedSet, get_root_of
+
from erpnext import get_default_currency
+
class SalesPerson(NestedSet):
nsm_parent_field = 'parent_sales_person'
diff --git a/erpnext/setup/doctype/sales_person/sales_person_dashboard.py b/erpnext/setup/doctype/sales_person/sales_person_dashboard.py
index 662008e..61c1ba4 100644
--- a/erpnext/setup/doctype/sales_person/sales_person_dashboard.py
+++ b/erpnext/setup/doctype/sales_person/sales_person_dashboard.py
@@ -1,6 +1,8 @@
from __future__ import unicode_literals
+
from frappe import _
+
def get_data():
return {
'heatmap': True,
diff --git a/erpnext/setup/doctype/sales_person/test_sales_person.py b/erpnext/setup/doctype/sales_person/test_sales_person.py
index 8313cb4..497aaad 100644
--- a/erpnext/setup/doctype/sales_person/test_sales_person.py
+++ b/erpnext/setup/doctype/sales_person/test_sales_person.py
@@ -5,6 +5,7 @@
test_dependencies = ["Employee"]
import frappe
+
test_records = frappe.get_test_records('Sales Person')
test_ignore = ["Item Group"]
diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.py b/erpnext/setup/doctype/supplier_group/supplier_group.py
index 9d84f90..0ca3525 100644
--- a/erpnext/setup/doctype/supplier_group/supplier_group.py
+++ b/erpnext/setup/doctype/supplier_group/supplier_group.py
@@ -3,9 +3,11 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+
import frappe
from frappe.utils.nestedset import NestedSet, get_root_of
+
class SupplierGroup(NestedSet):
nsm_parent_field = 'parent_supplier_group'
diff --git a/erpnext/setup/doctype/supplier_group/test_supplier_group.py b/erpnext/setup/doctype/supplier_group/test_supplier_group.py
index 0e3d23d..b3a6366 100644
--- a/erpnext/setup/doctype/supplier_group/test_supplier_group.py
+++ b/erpnext/setup/doctype/supplier_group/test_supplier_group.py
@@ -4,4 +4,5 @@
from __future__ import unicode_literals
import frappe
+
test_records = frappe.get_test_records('Supplier Group')
diff --git a/erpnext/setup/doctype/target_detail/target_detail.py b/erpnext/setup/doctype/target_detail/target_detail.py
index 633be45..89cd814 100644
--- a/erpnext/setup/doctype/target_detail/target_detail.py
+++ b/erpnext/setup/doctype/target_detail/target_detail.py
@@ -2,9 +2,9 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
from frappe.model.document import Document
+
class TargetDetail(Document):
pass
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
index 5b00ccb..8c9059f 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
@@ -2,15 +2,17 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
+import json
+
import frappe
from frappe import _, throw
-import json
from frappe.model.document import Document
-from frappe.utils.jinja import validate_template
from frappe.utils import cint
-
+from frappe.utils.jinja import validate_template
from six import string_types
+
class TermsandConditions(Document):
def validate(self):
if self.terms:
diff --git a/erpnext/setup/doctype/terms_and_conditions/test_terms_and_conditions.py b/erpnext/setup/doctype/terms_and_conditions/test_terms_and_conditions.py
index 6fea78f..abfa921 100644
--- a/erpnext/setup/doctype/terms_and_conditions/test_terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/test_terms_and_conditions.py
@@ -2,6 +2,6 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('Terms and Conditions')
diff --git a/erpnext/setup/doctype/territory/territory.py b/erpnext/setup/doctype/territory/territory.py
index 7eefe77..f61796b 100644
--- a/erpnext/setup/doctype/territory/territory.py
+++ b/erpnext/setup/doctype/territory/territory.py
@@ -2,12 +2,13 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
-from frappe.utils import flt
-from frappe import _
+import frappe
+from frappe import _
+from frappe.utils import flt
from frappe.utils.nestedset import NestedSet, get_root_of
+
class Territory(NestedSet):
nsm_parent_field = 'parent_territory'
diff --git a/erpnext/setup/doctype/territory/test_territory.py b/erpnext/setup/doctype/territory/test_territory.py
index efe00c5..a3aa866 100644
--- a/erpnext/setup/doctype/territory/test_territory.py
+++ b/erpnext/setup/doctype/territory/test_territory.py
@@ -2,8 +2,8 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('Territory')
test_ignore = ["Item Group"]
diff --git a/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py
index 933a8c3..aa0f79b 100644
--- a/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py
+++ b/erpnext/setup/doctype/transaction_deletion_record/test_transaction_deletion_record.py
@@ -3,9 +3,11 @@
# See license.txt
from __future__ import unicode_literals
-import frappe
import unittest
+import frappe
+
+
class TestTransactionDeletionRecord(unittest.TestCase):
def setUp(self):
create_company('Dunder Mifflin Paper Co')
diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py
index 8a49155..efb038f 100644
--- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py
+++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py
@@ -3,11 +3,13 @@
# For license information, please see license.txt
from __future__ import unicode_literals
-from frappe.utils import cint
+
import frappe
-from frappe.model.document import Document
from frappe import _
from frappe.desk.notifications import clear_notifications
+from frappe.model.document import Document
+from frappe.utils import cint
+
class TransactionDeletionRecord(Document):
def validate(self):
diff --git a/erpnext/setup/doctype/transaction_deletion_record_item/transaction_deletion_record_item.py b/erpnext/setup/doctype/transaction_deletion_record_item/transaction_deletion_record_item.py
index 2176cb1..a113d50 100644
--- a/erpnext/setup/doctype/transaction_deletion_record_item/transaction_deletion_record_item.py
+++ b/erpnext/setup/doctype/transaction_deletion_record_item/transaction_deletion_record_item.py
@@ -3,8 +3,10 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+
# import frappe
from frappe.model.document import Document
+
class TransactionDeletionRecordItem(Document):
pass
diff --git a/erpnext/setup/doctype/uom/test_uom.py b/erpnext/setup/doctype/uom/test_uom.py
index 330d303..e222c13 100644
--- a/erpnext/setup/doctype/uom/test_uom.py
+++ b/erpnext/setup/doctype/uom/test_uom.py
@@ -2,6 +2,6 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-
import frappe
+
test_records = frappe.get_test_records('UOM')
diff --git a/erpnext/setup/doctype/uom/uom.py b/erpnext/setup/doctype/uom/uom.py
index 404b84b..f0e97b3 100644
--- a/erpnext/setup/doctype/uom/uom.py
+++ b/erpnext/setup/doctype/uom/uom.py
@@ -2,9 +2,9 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
from frappe.model.document import Document
+
class UOM(Document):
pass
diff --git a/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py b/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py
index 04596ef..33795d6 100644
--- a/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py
+++ b/erpnext/setup/doctype/uom_conversion_factor/test_uom_conversion_factor.py
@@ -5,5 +5,6 @@
import unittest
+
class TestUOMConversionFactor(unittest.TestCase):
pass
diff --git a/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.py b/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.py
index 3566c53..45342e9 100644
--- a/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.py
+++ b/erpnext/setup/doctype/uom_conversion_factor/uom_conversion_factor.py
@@ -3,7 +3,9 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+
from frappe.model.document import Document
+
class UOMConversionFactor(Document):
pass
diff --git a/erpnext/setup/doctype/website_item_group/website_item_group.py b/erpnext/setup/doctype/website_item_group/website_item_group.py
index e416b50..2f72013 100644
--- a/erpnext/setup/doctype/website_item_group/website_item_group.py
+++ b/erpnext/setup/doctype/website_item_group/website_item_group.py
@@ -4,9 +4,9 @@
# For license information, please see license.txt
from __future__ import unicode_literals
-import frappe
from frappe.model.document import Document
+
class WebsiteItemGroup(Document):
pass
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index bbee74c..cdc83c1 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -4,16 +4,18 @@
from __future__ import print_function, unicode_literals
import frappe
-from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import DEFAULT_MAPPERS
-from .default_success_action import get_default_success_action
from frappe import _
-from frappe.utils import cint
-from frappe.installer import update_site_config
-from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
-from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules
+from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
+from frappe.installer import update_site_config
+from frappe.utils import cint
from six import iteritems
+from erpnext.accounts.doctype.cash_flow_mapper.default_cash_flow_mapper import DEFAULT_MAPPERS
+from erpnext.setup.default_energy_point_rules import get_default_energy_point_rules
+
+from .default_success_action import get_default_success_action
+
default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
<a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
diff --git a/erpnext/setup/setup_wizard/data/dashboard_charts.py b/erpnext/setup/setup_wizard/data/dashboard_charts.py
index 9ce64eb..5369bba 100644
--- a/erpnext/setup/setup_wizard/data/dashboard_charts.py
+++ b/erpnext/setup/setup_wizard/data/dashboard_charts.py
@@ -1,8 +1,10 @@
from __future__ import unicode_literals
-from frappe import _
-import frappe
+
import json
+import frappe
+
+
def get_company_for_dashboards():
company = frappe.defaults.get_defaults().company
if company:
diff --git a/erpnext/setup/setup_wizard/data/industry_type.py b/erpnext/setup/setup_wizard/data/industry_type.py
index 4fa9f8a..2c83a5c 100644
--- a/erpnext/setup/setup_wizard/data/industry_type.py
+++ b/erpnext/setup/setup_wizard/data/industry_type.py
@@ -1,6 +1,8 @@
from __future__ import unicode_literals
+
from frappe import _
+
def get_industry_types():
return [
_('Accounting'),
diff --git a/erpnext/setup/setup_wizard/operations/company_setup.py b/erpnext/setup/setup_wizard/operations/company_setup.py
index 4833d93..bea3906 100644
--- a/erpnext/setup/setup_wizard/operations/company_setup.py
+++ b/erpnext/setup/setup_wizard/operations/company_setup.py
@@ -6,7 +6,6 @@
from frappe import _
from frappe.utils import cstr, getdate
from .default_website import website_maker
-from erpnext.accounts.doctype.account.account import RootNotEditable
def create_fiscal_year_and_company(args):
if (args.get('fy_start_date')):
diff --git a/erpnext/setup/setup_wizard/operations/default_website.py b/erpnext/setup/setup_wizard/operations/default_website.py
index 38b5c14..2288ae0 100644
--- a/erpnext/setup/setup_wizard/operations/default_website.py
+++ b/erpnext/setup/setup_wizard/operations/default_website.py
@@ -2,11 +2,12 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
+import frappe
from frappe import _
from frappe.utils import nowdate
+
class website_maker(object):
def __init__(self, args):
self.args = args
diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py
index cd49a18..907967c 100644
--- a/erpnext/setup/setup_wizard/operations/install_fixtures.py
+++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py
@@ -3,16 +3,20 @@
from __future__ import unicode_literals
-import frappe, os, json
+import json
+import os
+import frappe
from frappe import _
+from frappe.desk.doctype.global_search_settings.global_search_settings import (
+ update_global_search_doctypes,
+)
from frappe.desk.page.setup_wizard.setup_wizard import make_records
from frappe.utils import cstr, getdate
-from frappe.desk.doctype.global_search_settings.global_search_settings import update_global_search_doctypes
+from frappe.utils.nestedset import rebuild_tree
from erpnext.accounts.doctype.account.account import RootNotEditable
from erpnext.regional.address_template.setup import set_up_address_templates
-from frappe.utils.nestedset import rebuild_tree
default_lead_sources = ["Existing Customer", "Reference", "Advertisement",
"Cold Calling", "Exhibition", "Supplier Reference", "Mass Mailing",
diff --git a/erpnext/setup/setup_wizard/operations/sample_data.py b/erpnext/setup/setup_wizard/operations/sample_data.py
index c6d9f08..3aef40d 100644
--- a/erpnext/setup/setup_wizard/operations/sample_data.py
+++ b/erpnext/setup/setup_wizard/operations/sample_data.py
@@ -3,11 +3,15 @@
from __future__ import unicode_literals
+import json
+import os
+import random
+
import frappe
-from frappe.utils.make_random import add_random_children
import frappe.utils
-import random, os, json
from frappe import _
+from frappe.utils.make_random import add_random_children
+
def make_sample_data(domains, make_dependent = False):
"""Create a few opportunities, quotes, material requests, issues, todos, projects
diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py
index 9275d1b..ecb07d5 100644
--- a/erpnext/setup/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/setup_wizard/setup_wizard.py
@@ -6,7 +6,10 @@
import frappe
from frappe import _
-from .operations import install_fixtures as fixtures, company_setup, sample_data
+from .operations import company_setup
+from .operations import install_fixtures as fixtures
+from .operations import sample_data
+
def get_setup_stages(args=None):
if frappe.db.sql("select name from tabCompany"):
diff --git a/erpnext/setup/setup_wizard/utils.py b/erpnext/setup/setup_wizard/utils.py
index 4223f00..30b88ae 100644
--- a/erpnext/setup/setup_wizard/utils.py
+++ b/erpnext/setup/setup_wizard/utils.py
@@ -1,8 +1,10 @@
from __future__ import unicode_literals
-import json, os
+
+import json
+import os
from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
-from erpnext.setup.setup_wizard import setup_wizard
+
def complete():
with open(os.path.join(os.path.dirname(__file__),
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index 409f776..2302a66 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -2,12 +2,14 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
+
import frappe
from frappe import _
-from frappe.utils import flt, add_days
-from frappe.utils import get_datetime_str, nowdate
+from frappe.utils import add_days, flt, get_datetime_str, nowdate
+
from erpnext import get_default_company
+
def get_root_of(doctype):
"""Get root element of a DocType with a tree structure"""
result = frappe.db.sql_list("""select name from `tab%s`