Merge pull request #18161 from deepeshgarg007/additional_discount

fix: Additonal discount not getting set in sales transactions
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.js b/erpnext/accounts/doctype/pos_profile/pos_profile.js
index 10f127a..5e94118 100755
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.js
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.js
@@ -8,6 +8,10 @@
 		return { filters: { selling: 1 } };
 	});
 
+	frm.set_query("tc_name", function() {
+		return { filters: { selling: 1 } };
+	});
+
 	erpnext.queries.setup_queries(frm, "Warehouse", function() {
 		return erpnext.queries.warehouse(frm.doc);
 	});
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index a6f6ace..1b03896 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -484,9 +484,13 @@
 							"credit": flt(item.rm_supp_cost)
 						}, warehouse_account[self.supplier_warehouse]["account_currency"], item=item))
 				elif not item.is_fixed_asset or (item.is_fixed_asset and is_cwip_accounting_disabled()):
+
+					expense_account = (item.expense_account
+						if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account)
+
 					gl_entries.append(
 						self.get_gl_dict({
-							"account": item.expense_account if not item.enable_deferred_expense else item.deferred_expense_account,
+							"account": expense_account,
 							"against": self.supplier,
 							"debit": flt(item.base_net_amount, item.precision("base_net_amount")),
 							"debit_in_account_currency": (flt(item.base_net_amount,
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index b725c73..71bdc2a 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -783,10 +783,13 @@
 					asset.db_set("disposal_date", self.posting_date)
 					asset.set_status("Sold" if self.docstatus==1 else None)
 				else:
-					account_currency = get_account_currency(item.income_account)
+					income_account = (item.income_account
+						if (not item.enable_deferred_revenue or self.is_return) else item.deferred_revenue_account)
+
+					account_currency = get_account_currency(income_account)
 					gl_entries.append(
 						self.get_gl_dict({
-							"account": item.income_account if not item.enable_deferred_revenue else item.deferred_revenue_account,
+							"account": income_account,
 							"against": self.customer,
 							"credit": flt(item.base_net_amount, item.precision("base_net_amount")),
 							"credit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount"))
diff --git a/erpnext/config/manufacturing.py b/erpnext/config/manufacturing.py
index da60550..c79c5b8 100644
--- a/erpnext/config/manufacturing.py
+++ b/erpnext/config/manufacturing.py
@@ -4,43 +4,6 @@
 def get_data():
 	return [
 		{
-			"label": _("Production"),
-			"icon": "fa fa-star",
-			"items": [
-				{
-					"type": "doctype",
-					"name": "Work Order",
-					"description": _("Orders released for production."),
-					"onboard": 1,
-					"dependencies": ["Item", "BOM"]
-				},
-				{
-					"type": "doctype",
-					"name": "Production Plan",
-					"description": _("Generate Material Requests (MRP) and Work Orders."),
-					"onboard": 1,
-					"dependencies": ["Item", "BOM"]
-				},
-				{
-					"type": "doctype",
-					"name": "Stock Entry",
-					"onboard": 1,
-					"dependencies": ["Item"]
-				},
-				{
-					"type": "doctype",
-					"name": "Timesheet",
-					"description": _("Time Sheet for manufacturing."),
-					"onboard": 1,
-					"dependencies": ["Activity Type"]
-				},
-				{
-					"type": "doctype",
-					"name": "Job Card"
-				}
-			]
-		},
-		{
 			"label": _("Bill of Materials"),
 			"items": [
 				{
@@ -86,6 +49,43 @@
 			]
 		},
 		{
+			"label": _("Production"),
+			"icon": "fa fa-star",
+			"items": [
+				{
+					"type": "doctype",
+					"name": "Work Order",
+					"description": _("Orders released for production."),
+					"onboard": 1,
+					"dependencies": ["Item", "BOM"]
+				},
+				{
+					"type": "doctype",
+					"name": "Production Plan",
+					"description": _("Generate Material Requests (MRP) and Work Orders."),
+					"onboard": 1,
+					"dependencies": ["Item", "BOM"]
+				},
+				{
+					"type": "doctype",
+					"name": "Stock Entry",
+					"onboard": 1,
+					"dependencies": ["Item"]
+				},
+				{
+					"type": "doctype",
+					"name": "Timesheet",
+					"description": _("Time Sheet for manufacturing."),
+					"onboard": 1,
+					"dependencies": ["Activity Type"]
+				},
+				{
+					"type": "doctype",
+					"name": "Job Card"
+				}
+			]
+		},
+		{
 			"label": _("Tools"),
 			"icon": "fa fa-wrench",
 			"items": [
diff --git a/erpnext/hr/doctype/job_offer/job_offer.js b/erpnext/hr/doctype/job_offer/job_offer.js
index 1ee35af..c3d83c4 100755
--- a/erpnext/hr/doctype/job_offer/job_offer.js
+++ b/erpnext/hr/doctype/job_offer/job_offer.js
@@ -4,6 +4,12 @@
 frappe.provide("erpnext.job_offer");
 
 frappe.ui.form.on("Job Offer", {
+	onload: function (frm) {
+		frm.set_query("select_terms", function() {
+			return { filters: { hr: 1 } };
+		});
+	},
+
 	select_terms: function (frm) {
 		erpnext.utils.get_terms(frm.doc.select_terms, frm.doc, function (r) {
 			if (!r.exc) {
diff --git a/erpnext/manufacturing/doctype/blanket_order/blanket_order.js b/erpnext/manufacturing/doctype/blanket_order/blanket_order.js
index 89efb93..0bbf689 100644
--- a/erpnext/manufacturing/doctype/blanket_order/blanket_order.js
+++ b/erpnext/manufacturing/doctype/blanket_order/blanket_order.js
@@ -2,6 +2,10 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Blanket Order', {
+	onload: function(frm) {
+		frm.trigger('set_tc_name_filter');
+	},
+
 	setup: function(frm) {
 		frm.add_fetch("customer", "customer_name", "customer_name");
 		frm.add_fetch("supplier", "supplier_name", "supplier_name");
@@ -44,4 +48,23 @@
 			}
 		});
 	},
+
+	set_tc_name_filter: function(frm) {
+		if (frm.doc.blanket_order_type === 'Selling') {
+			frm.set_query("tc_name", function() {
+				return { filters: { selling: 1 } };
+			});
+		}
+		if (frm.doc.blanket_order_type === 'Purchasing') {
+			frm.set_query("tc_name", function() {
+				return { filters: { buying: 1 } };
+			});
+		}
+	},
+
+	blanket_order_type: function (frm) {
+		frm.trigger('set_tc_name_filter');
+	}
 });
+
+
diff --git a/erpnext/manufacturing/doctype/blanket_order/blanket_order_dashboard.py b/erpnext/manufacturing/doctype/blanket_order/blanket_order_dashboard.py
new file mode 100644
index 0000000..ed319a0
--- /dev/null
+++ b/erpnext/manufacturing/doctype/blanket_order/blanket_order_dashboard.py
@@ -0,0 +1,12 @@
+from __future__ import unicode_literals
+from frappe import _
+
+def get_data():
+	return {
+		'fieldname': 'blanket_order',
+		'transactions': [
+			{
+				'items': ['Purchase Order', 'Sales Order']
+			}
+		]
+	}
diff --git a/erpnext/manufacturing/doctype/bom/bom_dashboard.py b/erpnext/manufacturing/doctype/bom/bom_dashboard.py
new file mode 100644
index 0000000..803ece7
--- /dev/null
+++ b/erpnext/manufacturing/doctype/bom/bom_dashboard.py
@@ -0,0 +1,27 @@
+from __future__ import unicode_literals
+from frappe import _
+
+def get_data():
+	return {
+		'fieldname': 'bom_no',
+		'non_standard_fieldnames': {
+			'Item': 'default_bom',
+			'Purchase Order': 'bom',
+			'Purchase Receipt': 'bom',
+			'Purchase Invoice': 'bom'
+		},
+		'transactions': [
+			{
+				'label': _('Stock'),
+				'items': ['Item', 'Stock Entry', 'Quality Inspection']
+			},
+			{
+				'label': _('Manufacture'),
+				'items': ['BOM', 'Work Order', 'Job Card', 'Production Plan']
+			},
+			{
+				'label': _('Purchase'),
+				'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
+			}
+		]
+	}
diff --git a/erpnext/manufacturing/doctype/job_card/job_card_dashboard.py b/erpnext/manufacturing/doctype/job_card/job_card_dashboard.py
index d48bccf..c2aa2bd 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card_dashboard.py
+++ b/erpnext/manufacturing/doctype/job_card/job_card_dashboard.py
@@ -10,4 +10,4 @@
 				'items': ['Material Request', 'Stock Entry']
 			}
 		]
-	}
\ No newline at end of file
+	}
diff --git a/erpnext/manufacturing/doctype/operation/operation_dashboard.py b/erpnext/manufacturing/doctype/operation/operation_dashboard.py
new file mode 100644
index 0000000..8deb9ec
--- /dev/null
+++ b/erpnext/manufacturing/doctype/operation/operation_dashboard.py
@@ -0,0 +1,13 @@
+from __future__ import unicode_literals
+from frappe import _
+
+def get_data():
+	return {
+		'fieldname': 'operation',
+		'transactions': [
+			{
+				'label': _('Manufacture'),
+				'items': ['BOM', 'Work Order', 'Job Card', 'Timesheet']
+			}
+		]
+	}
diff --git a/erpnext/manufacturing/doctype/routing/routing_dashboard.py b/erpnext/manufacturing/doctype/routing/routing_dashboard.py
new file mode 100644
index 0000000..ab309cc
--- /dev/null
+++ b/erpnext/manufacturing/doctype/routing/routing_dashboard.py
@@ -0,0 +1,12 @@
+from __future__ import unicode_literals
+from frappe import _
+
+def get_data():
+	return {
+		'fieldname': 'routing',
+		'transactions': [
+			{
+				'items': ['BOM']
+			}
+		]
+	}
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/workstation/workstation_dashboard.py b/erpnext/manufacturing/doctype/workstation/workstation_dashboard.py
new file mode 100644
index 0000000..9e0d1d1
--- /dev/null
+++ b/erpnext/manufacturing/doctype/workstation/workstation_dashboard.py
@@ -0,0 +1,13 @@
+from __future__ import unicode_literals
+from frappe import _
+
+def get_data():
+	return {
+		'fieldname': 'workstation',
+		'transactions': [
+			{
+				'label': _('Manufacture'),
+				'items': ['BOM', 'Routing', 'Work Order', 'Job Card', 'Operation', 'Timesheet']
+			}
+		]
+	}
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 72db8ad..bd41c7e 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -615,3 +615,4 @@
 erpnext.patches.v12_0.set_quotation_status
 erpnext.patches.v12_0.set_priority_for_support
 erpnext.patches.v12_0.delete_priority_property_setter
+erpnext.patches.v12_0.add_default_buying_selling_terms_in_company
diff --git a/erpnext/patches/v12_0/add_default_buying_selling_terms_in_company.py b/erpnext/patches/v12_0/add_default_buying_selling_terms_in_company.py
new file mode 100644
index 0000000..484f81a
--- /dev/null
+++ b/erpnext/patches/v12_0/add_default_buying_selling_terms_in_company.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2019, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+
+import frappe
+from frappe.model.utils.rename_field import rename_field
+
+def execute():
+	frappe.reload_doc("setup", "doctype", "company")
+	if frappe.db.has_column('Company', 'default_terms'):
+		rename_field('Company', "default_terms", "default_selling_terms")
+
+		for company in frappe.get_all("Company", ["name", "default_selling_terms", "default_buying_terms"]):
+			if company.default_selling_terms and not company.default_buying_terms:
+				frappe.db.set_value("Company", company.name, "default_buying_terms", company.default_selling_terms)
+	
+	frappe.reload_doc("setup", "doctype", "terms_and_conditions")
+	frappe.db.sql("update `tabTerms and Conditions` set selling=1, buying=1, hr=1")
diff --git a/erpnext/portal/product_configurator/item_variants_cache.py b/erpnext/portal/product_configurator/item_variants_cache.py
index f33c8d6..fc294ce 100644
--- a/erpnext/portal/product_configurator/item_variants_cache.py
+++ b/erpnext/portal/product_configurator/item_variants_cache.py
@@ -110,4 +110,4 @@
 def enqueue_build_cache(item_code):
 	if frappe.cache().hget('item_cache_build_in_progress', item_code):
 		return
-	frappe.enqueue(build_cache, item_code=item_code, queue='short')
+	frappe.enqueue(build_cache, item_code=item_code, queue='long')
diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js
index 97c823d..824b8d9 100644
--- a/erpnext/public/js/controllers/buying.js
+++ b/erpnext/public/js/controllers/buying.js
@@ -61,6 +61,14 @@
 			});
 		}
 
+		if(this.frm.fields_dict.tc_name) {
+			this.frm.set_query("tc_name", function() {
+				return{
+					filters: { 'buying': 1 }
+				}
+			});
+		}
+
 		me.frm.set_query('supplier', erpnext.queries.supplier);
 		me.frm.set_query('contact_person', erpnext.queries.contact_query);
 		me.frm.set_query('supplier_address', erpnext.queries.address_query);
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 8fb21bc..11fdb8b 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -383,8 +383,9 @@
 
 	setup_sms: function() {
 		var me = this;
+		let blacklist = ['Purchase Invoice', 'BOM'];
 		if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped", "Closed"], this.frm.doc.status)
-			&& this.frm.doctype != "Purchase Invoice") {
+			&& !blacklist.includes(this.frm.doctype)) {
 			this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
 		}
 	},
@@ -584,8 +585,17 @@
 						me.frm.set_value("letter_head", company_doc.default_letter_head);
 					}
 				}
-				if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice" && frappe.meta.has_field(me.frm.doc.doctype, "tc_name")) {
-					me.frm.set_value("tc_name", company_doc.default_terms);
+				let selling_doctypes_for_tc = ["Sales Invoice", "Quotation", "Sales Order", "Delivery Note"];
+				if (company_doc.default_selling_terms && frappe.meta.has_field(me.frm.doc.doctype, "tc_name") &&
+				selling_doctypes_for_tc.indexOf(me.frm.doc.doctype) != -1) {
+					me.frm.set_value("tc_name", company_doc.default_selling_terms);
+				}
+				let buying_doctypes_for_tc = ["Request for Quotation", "Supplier Quotation", "Purchase Order",
+					"Material Request", "Purchase Receipt"];
+				// Purchase Invoice is excluded as per issue #3345
+				if (company_doc.default_buying_terms && frappe.meta.has_field(me.frm.doc.doctype, "tc_name") &&
+				buying_doctypes_for_tc.indexOf(me.frm.doc.doctype) != -1) {
+					me.frm.set_value("tc_name", company_doc.default_buying_terms);
 				}
 
 				frappe.run_serially([
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index ad3f27c..a2bae56 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -59,6 +59,12 @@
 			});
 		}
 
+		if(this.frm.fields_dict.tc_name) {
+			this.frm.set_query("tc_name", function() {
+				return { filters: { selling: 1 } };
+			});
+		}
+
 		if(!this.frm.fields_dict["items"]) {
 			return;
 		}
diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js
index 1e6056e..313de67 100644
--- a/erpnext/setup/doctype/company/company.js
+++ b/erpnext/setup/doctype/company/company.js
@@ -17,6 +17,14 @@
 				filters: {"is_group": 1}
 			}
 		});
+
+		frm.set_query("default_selling_terms", function() {
+			return { filters: { selling: 1 } };
+		});
+
+		frm.set_query("default_buying_terms", function() {
+			return { filters: { buying: 1 } };
+		});
 	},
 
 	company_name: function(frm) {
diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json
index bb652ca..bc34189 100644
--- a/erpnext/setup/doctype/company/company.json
+++ b/erpnext/setup/doctype/company/company.json
@@ -1,769 +1,776 @@
 {
-  "allow_import": 1,
-  "allow_rename": 1,
-  "autoname": "field:company_name",
-  "creation": "2013-04-10 08:35:39",
-  "description": "Legal Entity / Subsidiary with a separate Chart of Accounts belonging to the Organization.",
-  "doctype": "DocType",
-  "document_type": "Setup",
-  "engine": "InnoDB",
-  "field_order": [
-   "details",
-   "company_name",
-   "abbr",
-   "change_abbr",
-   "is_group",
-   "cb0",
-   "domain",
-   "parent_company",
-   "charts_section",
-   "default_currency",
-   "default_letter_head",
-   "default_holiday_list",
-   "default_finance_book",
-   "standard_working_hours",
-   "default_terms",
-   "default_warehouse_for_sales_return",
-   "column_break_10",
-   "country",
-   "create_chart_of_accounts_based_on",
-   "chart_of_accounts",
-   "existing_company",
-   "tax_id",
-   "date_of_establishment",
-   "sales_settings",
-   "monthly_sales_target",
-   "sales_monthly_history",
-   "column_break_goals",
-   "transactions_annual_history",
-   "total_monthly_sales",
-   "default_settings",
-   "default_bank_account",
-   "default_cash_account",
-   "default_receivable_account",
-   "round_off_account",
-   "round_off_cost_center",
-   "write_off_account",
-   "discount_allowed_account",
-   "discount_received_account",
-   "exchange_gain_loss_account",
-   "unrealized_exchange_gain_loss_account",
-   "column_break0",
-   "allow_account_creation_against_child_company",
-   "default_payable_account",
-   "default_employee_advance_account",
-   "default_expense_account",
-   "default_income_account",
-   "default_deferred_revenue_account",
-   "default_deferred_expense_account",
-   "default_payroll_payable_account",
-   "default_expense_claim_payable_account",
-   "section_break_22",
-   "cost_center",
-   "column_break_26",
-   "credit_limit",
-   "payment_terms",
-   "auto_accounting_for_stock_settings",
-   "enable_perpetual_inventory",
-   "default_inventory_account",
-   "stock_adjustment_account",
-   "column_break_32",
-   "stock_received_but_not_billed",
-   "expenses_included_in_valuation",
-   "fixed_asset_depreciation_settings",
-   "accumulated_depreciation_account",
-   "depreciation_expense_account",
-   "series_for_depreciation_entry",
-   "expenses_included_in_asset_valuation",
-   "column_break_40",
-   "disposal_account",
-   "depreciation_cost_center",
-   "capital_work_in_progress_account",
-   "asset_received_but_not_billed",
-   "budget_detail",
-   "exception_budget_approver_role",
-   "company_info",
-   "company_logo",
-   "date_of_incorporation",
-   "address_html",
-   "date_of_commencement",
-   "phone_no",
-   "fax",
-   "email",
-   "website",
-   "column_break1",
-   "company_description",
-   "registration_info",
-   "registration_details",
-   "delete_company_transactions",
-   "lft",
-   "rgt",
-   "old_parent"
-  ],
-  "fields": [
-   {
-    "fieldname": "details",
-    "fieldtype": "Section Break",
-    "oldfieldtype": "Section Break"
-   },
-   {
-    "fieldname": "company_name",
-    "fieldtype": "Data",
-    "label": "Company",
-    "oldfieldname": "company_name",
-    "oldfieldtype": "Data",
-    "reqd": 1,
-    "unique": 1
-   },
-   {
-    "fieldname": "abbr",
-    "fieldtype": "Data",
-    "label": "Abbr",
-    "oldfieldname": "abbr",
-    "oldfieldtype": "Data",
-    "reqd": 1
-   },
-   {
-    "depends_on": "eval:!doc.__islocal && in_list(frappe.user_roles, \"System Manager\")",
-    "fieldname": "change_abbr",
-    "fieldtype": "Button",
-    "label": "Change Abbreviation"
-   },
-   {
-    "bold": 1,
-    "default": "0",
-    "fieldname": "is_group",
-    "fieldtype": "Check",
-    "label": "Is Group"
-   },
-   {
-    "fieldname": "default_finance_book",
-    "fieldtype": "Link",
-    "label": "Default Finance Book",
-    "options": "Finance Book"
-   },
-   {
-    "fieldname": "cb0",
-    "fieldtype": "Column Break"
-   },
-   {
-    "fieldname": "domain",
-    "fieldtype": "Link",
-    "label": "Domain",
-    "options": "Domain"
-   },
-   {
-    "fieldname": "parent_company",
-    "fieldtype": "Link",
-    "in_list_view": 1,
-    "label": "Parent Company",
-    "options": "Company"
-   },
-   {
-    "fieldname": "company_logo",
-    "fieldtype": "Attach Image",
-    "hidden": 1,
-    "label": "Company Logo"
-   },
-   {
-    "fieldname": "company_description",
-    "fieldtype": "Text Editor",
-    "label": "Company Description"
-   },
-   {
-    "collapsible": 1,
-    "fieldname": "sales_settings",
-    "fieldtype": "Section Break",
-    "label": "Sales Settings"
-   },
-   {
-    "fieldname": "sales_monthly_history",
-    "fieldtype": "Small Text",
-    "hidden": 1,
-    "label": "Sales Monthly History",
-    "no_copy": 1,
-    "read_only": 1
-   },
-   {
-    "fieldname": "transactions_annual_history",
-    "fieldtype": "Code",
-    "hidden": 1,
-    "label": "Transactions Annual History",
-    "no_copy": 1,
-    "read_only": 1
-   },
-   {
-    "fieldname": "monthly_sales_target",
-    "fieldtype": "Currency",
-    "label": "Monthly Sales Target",
-    "options": "default_currency"
-   },
-   {
-    "fieldname": "column_break_goals",
-    "fieldtype": "Column Break"
-   },
-   {
-    "fieldname": "total_monthly_sales",
-    "fieldtype": "Currency",
-    "label": "Total Monthly Sales",
-    "no_copy": 1,
-    "options": "default_currency",
-    "read_only": 1
-   },
-   {
-    "fieldname": "charts_section",
-    "fieldtype": "Section Break",
-    "label": "Default Values"
-   },
-   {
-    "fieldname": "default_currency",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Currency",
-    "options": "Currency",
-    "reqd": 1
-   },
-   {
-    "fieldname": "default_letter_head",
-    "fieldtype": "Link",
-    "label": "Default Letter Head",
-    "options": "Letter Head"
-   },
-   {
-    "fieldname": "default_holiday_list",
-    "fieldtype": "Link",
-    "label": "Default Holiday List",
-    "options": "Holiday List"
-   },
-   {
-    "fieldname": "standard_working_hours",
-    "fieldtype": "Float",
-    "label": "Standard Working Hours"
-   },
-   {
-    "fieldname": "default_terms",
-    "fieldtype": "Link",
-    "label": "Default Terms",
-    "options": "Terms and Conditions"
-   },
-   {
-    "fieldname": "default_warehouse_for_sales_return",
-    "fieldtype": "Link",
-    "label": "Default warehouse for Sales Return",
-    "options": "Warehouse"
-   },
-   {
-    "fieldname": "column_break_10",
-    "fieldtype": "Column Break"
-   },
-   {
-    "fieldname": "country",
-    "fieldtype": "Link",
-    "in_list_view": 1,
-    "label": "Country",
-    "options": "Country",
-    "reqd": 1
-   },
-   {
-    "fieldname": "create_chart_of_accounts_based_on",
-    "fieldtype": "Select",
-    "label": "Create Chart Of Accounts Based On",
-    "options": "\nStandard Template\nExisting Company"
-   },
-   {
-    "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Standard Template\"",
-    "fieldname": "chart_of_accounts",
-    "fieldtype": "Select",
-    "label": "Chart Of Accounts Template",
-    "no_copy": 1
-   },
-   {
-    "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Existing Company\"",
-    "fieldname": "existing_company",
-    "fieldtype": "Link",
-    "label": "Existing Company ",
-    "no_copy": 1,
-    "options": "Company"
-   },
-   {
-    "fieldname": "tax_id",
-    "fieldtype": "Data",
-    "label": "Tax ID"
-   },
-   {
-    "fieldname": "date_of_establishment",
-    "fieldtype": "Date",
-    "label": "Date of Establishment"
-   },
-   {
-    "fieldname": "default_settings",
-    "fieldtype": "Section Break",
-    "label": "Accounts Settings",
-    "oldfieldtype": "Section Break"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_bank_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Bank Account",
-    "no_copy": 1,
-    "oldfieldname": "default_bank_account",
-    "oldfieldtype": "Link",
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_cash_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Cash Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_receivable_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Receivable Account",
-    "no_copy": 1,
-    "oldfieldname": "receivables_group",
-    "oldfieldtype": "Link",
-    "options": "Account"
-   },
-   {
-    "fieldname": "round_off_account",
-    "fieldtype": "Link",
-    "label": "Round Off Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "round_off_cost_center",
-    "fieldtype": "Link",
-    "label": "Round Off Cost Center",
-    "options": "Cost Center"
-   },
-   {
-    "fieldname": "write_off_account",
-    "fieldtype": "Link",
-    "label": "Write Off Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "discount_allowed_account",
-    "fieldtype": "Link",
-    "label": "Discount Allowed Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "discount_received_account",
-    "fieldtype": "Link",
-    "label": "Discount Received Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "exchange_gain_loss_account",
-    "fieldtype": "Link",
-    "label": "Exchange Gain / Loss Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "unrealized_exchange_gain_loss_account",
-    "fieldtype": "Link",
-    "label": "Unrealized Exchange Gain/Loss Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "column_break0",
-    "fieldtype": "Column Break",
-    "oldfieldtype": "Column Break",
-    "width": "50%"
-   },
-   {
-    "default": "0",
-    "depends_on": "eval:doc.parent_company",
-    "fieldname": "allow_account_creation_against_child_company",
-    "fieldtype": "Check",
-    "label": "Allow Account Creation Against Child Company"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_payable_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Payable Account",
-    "no_copy": 1,
-    "oldfieldname": "payables_group",
-    "oldfieldtype": "Link",
-    "options": "Account"
-   },
-   {
-    "fieldname": "default_employee_advance_account",
-    "fieldtype": "Link",
-    "label": "Default Employee Advance Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_expense_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Cost of Goods Sold Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_income_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Income Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_deferred_revenue_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Deferred Revenue Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_deferred_expense_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Deferred Expense Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_payroll_payable_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Payroll Payable Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "default_expense_claim_payable_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Expense Claim Payable Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "fieldname": "section_break_22",
-    "fieldtype": "Section Break"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "cost_center",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Default Cost Center",
-    "no_copy": 1,
-    "options": "Cost Center"
-   },
-   {
-    "fieldname": "column_break_26",
-    "fieldtype": "Column Break"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "credit_limit",
-    "fieldtype": "Currency",
-    "label": "Credit Limit",
-    "oldfieldname": "credit_limit",
-    "oldfieldtype": "Currency",
-    "options": "default_currency"
-   },
-   {
-    "fieldname": "payment_terms",
-    "fieldtype": "Link",
-    "label": "Default Payment Terms Template",
-    "options": "Payment Terms Template"
-   },
-   {
-    "depends_on": "eval:!doc.__islocal",
-    "fieldname": "auto_accounting_for_stock_settings",
-    "fieldtype": "Section Break",
-    "label": "Stock Settings"
-   },
-   {
-    "default": "1",
-    "fieldname": "enable_perpetual_inventory",
-    "fieldtype": "Check",
-    "label": "Enable Perpetual Inventory"
-   },
-   {
-    "fieldname": "default_inventory_account",
-    "fieldtype": "Link",
-    "label": "Default Inventory Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "stock_adjustment_account",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Stock Adjustment Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "fieldname": "column_break_32",
-    "fieldtype": "Column Break"
-   },
-   {
-    "fieldname": "stock_received_but_not_billed",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Stock Received But Not Billed",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "fieldname": "expenses_included_in_valuation",
-    "fieldtype": "Link",
-    "ignore_user_permissions": 1,
-    "label": "Expenses Included In Valuation",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "collapsible": 1,
-    "fieldname": "fixed_asset_depreciation_settings",
-    "fieldtype": "Section Break",
-    "label": "Fixed Asset Depreciation Settings"
-   },
-   {
-    "fieldname": "accumulated_depreciation_account",
-    "fieldtype": "Link",
-    "label": "Accumulated Depreciation Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "fieldname": "depreciation_expense_account",
-    "fieldtype": "Link",
-    "label": "Depreciation Expense Account",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "fieldname": "series_for_depreciation_entry",
-    "fieldtype": "Data",
-    "label": "Series for Asset Depreciation Entry (Journal Entry)"
-   },
-   {
-    "fieldname": "expenses_included_in_asset_valuation",
-    "fieldtype": "Link",
-    "label": "Expenses Included In Asset Valuation",
-    "options": "Account"
-   },
-   {
-    "fieldname": "column_break_40",
-    "fieldtype": "Column Break"
-   },
-   {
-    "fieldname": "disposal_account",
-    "fieldtype": "Link",
-    "label": "Gain/Loss Account on Asset Disposal",
-    "no_copy": 1,
-    "options": "Account"
-   },
-   {
-    "fieldname": "depreciation_cost_center",
-    "fieldtype": "Link",
-    "label": "Asset Depreciation Cost Center",
-    "no_copy": 1,
-    "options": "Cost Center"
-   },
-   {
-    "fieldname": "capital_work_in_progress_account",
-    "fieldtype": "Link",
-    "label": "Capital Work In Progress Account",
-    "options": "Account"
-   },
-   {
-    "fieldname": "asset_received_but_not_billed",
-    "fieldtype": "Link",
-    "label": "Asset Received But Not Billed",
-    "options": "Account"
-   },
-   {
-    "collapsible": 1,
-    "fieldname": "budget_detail",
-    "fieldtype": "Section Break",
-    "label": "Budget Detail"
-   },
-   {
-    "fieldname": "exception_budget_approver_role",
-    "fieldtype": "Link",
-    "label": "Exception Budget Approver Role",
-    "options": "Role"
-   },
-   {
-    "collapsible": 1,
-    "description": "For reference only.",
-    "fieldname": "company_info",
-    "fieldtype": "Section Break",
-    "label": "Company Info"
-   },
-   {
-    "fieldname": "date_of_incorporation",
-    "fieldtype": "Date",
-    "label": "Date of Incorporation"
-   },
-   {
-    "fieldname": "address_html",
-    "fieldtype": "HTML"
-   },
-   {
-    "fieldname": "column_break1",
-    "fieldtype": "Column Break",
-    "oldfieldtype": "Column Break",
-    "width": "50%"
-   },
-   {
-    "depends_on": "eval:doc.date_of_incorporation",
-    "fieldname": "date_of_commencement",
-    "fieldtype": "Date",
-    "label": "Date of Commencement"
-   },
-   {
-    "fieldname": "phone_no",
-    "fieldtype": "Data",
-    "label": "Phone No",
-    "oldfieldname": "phone_no",
-    "oldfieldtype": "Data",
-    "options": "Phone"
-   },
-   {
-    "fieldname": "fax",
-    "fieldtype": "Data",
-    "label": "Fax",
-    "oldfieldname": "fax",
-    "oldfieldtype": "Data",
-    "options": "Phone"
-   },
-   {
-    "fieldname": "email",
-    "fieldtype": "Data",
-    "label": "Email",
-    "oldfieldname": "email",
-    "oldfieldtype": "Data",
-    "options": "Email"
-   },
-   {
-    "fieldname": "website",
-    "fieldtype": "Data",
-    "label": "Website",
-    "oldfieldname": "website",
-    "oldfieldtype": "Data"
-   },
-   {
-    "fieldname": "registration_info",
-    "fieldtype": "Section Break",
-    "oldfieldtype": "Section Break",
-    "width": "50%"
-   },
-   {
-    "description": "Company registration numbers for your reference. Tax numbers etc.",
-    "fieldname": "registration_details",
-    "fieldtype": "Code",
-    "label": "Registration Details",
-    "oldfieldname": "registration_details",
-    "oldfieldtype": "Code"
-   },
-   {
-    "fieldname": "delete_company_transactions",
-    "fieldtype": "Button",
-    "label": "Delete Company Transactions"
-   },
-   {
-    "fieldname": "lft",
-    "fieldtype": "Int",
-    "hidden": 1,
-    "label": "Lft",
-    "print_hide": 1,
-    "read_only": 1,
-    "search_index": 1
-   },
-   {
-    "fieldname": "rgt",
-    "fieldtype": "Int",
-    "hidden": 1,
-    "label": "Rgt",
-    "print_hide": 1,
-    "read_only": 1,
-    "search_index": 1
-   },
-   {
-    "fieldname": "old_parent",
-    "fieldtype": "Data",
-    "hidden": 1,
-    "label": "old_parent",
-    "print_hide": 1,
-    "read_only": 1
-   }
-  ],
-  "icon": "fa fa-building",
-  "idx": 1,
-  "image_field": "company_logo",
-  "modified": "2019-06-14 14:36:11.363309",
-  "modified_by": "Administrator",
-  "module": "Setup",
-  "name": "Company",
-  "owner": "Administrator",
-  "permissions": [
-   {
-    "create": 1,
-    "delete": 1,
-    "email": 1,
-    "print": 1,
-    "read": 1,
-    "report": 1,
-    "role": "System Manager",
-    "share": 1,
-    "write": 1
-   },
-   {
-    "email": 1,
-    "print": 1,
-    "read": 1,
-    "role": "Accounts User"
-   },
-   {
-    "read": 1,
-    "role": "Employee"
-   },
-   {
-    "read": 1,
-    "role": "Sales User"
-   },
-   {
-    "read": 1,
-    "role": "Purchase User"
-   },
-   {
-    "read": 1,
-    "role": "Stock User"
-   },
-   {
-    "read": 1,
-    "role": "Projects User"
-   }
-  ],
-  "show_name_in_global_search": 1,
-  "sort_field": "modified",
-  "sort_order": "ASC",
-  "track_changes": 1
- }
\ No newline at end of file
+ "allow_import": 1,
+ "allow_rename": 1,
+ "autoname": "field:company_name",
+ "creation": "2013-04-10 08:35:39",
+ "description": "Legal Entity / Subsidiary with a separate Chart of Accounts belonging to the Organization.",
+ "doctype": "DocType",
+ "document_type": "Setup",
+ "engine": "InnoDB",
+ "field_order": [
+  "details",
+  "company_name",
+  "abbr",
+  "change_abbr",
+  "is_group",
+  "cb0",
+  "domain",
+  "parent_company",
+  "charts_section",
+  "default_currency",
+  "default_letter_head",
+  "default_holiday_list",
+  "default_finance_book",
+  "standard_working_hours",
+  "default_selling_terms",
+  "default_buying_terms",
+  "default_warehouse_for_sales_return",
+  "column_break_10",
+  "country",
+  "create_chart_of_accounts_based_on",
+  "chart_of_accounts",
+  "existing_company",
+  "tax_id",
+  "date_of_establishment",
+  "sales_settings",
+  "monthly_sales_target",
+  "sales_monthly_history",
+  "column_break_goals",
+  "transactions_annual_history",
+  "total_monthly_sales",
+  "default_settings",
+  "default_bank_account",
+  "default_cash_account",
+  "default_receivable_account",
+  "round_off_account",
+  "round_off_cost_center",
+  "write_off_account",
+  "discount_allowed_account",
+  "discount_received_account",
+  "exchange_gain_loss_account",
+  "unrealized_exchange_gain_loss_account",
+  "column_break0",
+  "allow_account_creation_against_child_company",
+  "default_payable_account",
+  "default_employee_advance_account",
+  "default_expense_account",
+  "default_income_account",
+  "default_deferred_revenue_account",
+  "default_deferred_expense_account",
+  "default_payroll_payable_account",
+  "default_expense_claim_payable_account",
+  "section_break_22",
+  "cost_center",
+  "column_break_26",
+  "credit_limit",
+  "payment_terms",
+  "auto_accounting_for_stock_settings",
+  "enable_perpetual_inventory",
+  "default_inventory_account",
+  "stock_adjustment_account",
+  "column_break_32",
+  "stock_received_but_not_billed",
+  "expenses_included_in_valuation",
+  "fixed_asset_depreciation_settings",
+  "accumulated_depreciation_account",
+  "depreciation_expense_account",
+  "series_for_depreciation_entry",
+  "expenses_included_in_asset_valuation",
+  "column_break_40",
+  "disposal_account",
+  "depreciation_cost_center",
+  "capital_work_in_progress_account",
+  "asset_received_but_not_billed",
+  "budget_detail",
+  "exception_budget_approver_role",
+  "company_info",
+  "company_logo",
+  "date_of_incorporation",
+  "address_html",
+  "date_of_commencement",
+  "phone_no",
+  "fax",
+  "email",
+  "website",
+  "column_break1",
+  "company_description",
+  "registration_info",
+  "registration_details",
+  "delete_company_transactions",
+  "lft",
+  "rgt",
+  "old_parent"
+ ],
+ "fields": [
+  {
+   "fieldname": "details",
+   "fieldtype": "Section Break",
+   "oldfieldtype": "Section Break"
+  },
+  {
+   "fieldname": "company_name",
+   "fieldtype": "Data",
+   "label": "Company",
+   "oldfieldname": "company_name",
+   "oldfieldtype": "Data",
+   "reqd": 1,
+   "unique": 1
+  },
+  {
+   "fieldname": "abbr",
+   "fieldtype": "Data",
+   "label": "Abbr",
+   "oldfieldname": "abbr",
+   "oldfieldtype": "Data",
+   "reqd": 1
+  },
+  {
+   "depends_on": "eval:!doc.__islocal && in_list(frappe.user_roles, \"System Manager\")",
+   "fieldname": "change_abbr",
+   "fieldtype": "Button",
+   "label": "Change Abbreviation"
+  },
+  {
+   "bold": 1,
+   "default": "0",
+   "fieldname": "is_group",
+   "fieldtype": "Check",
+   "label": "Is Group"
+  },
+  {
+   "fieldname": "default_finance_book",
+   "fieldtype": "Link",
+   "label": "Default Finance Book",
+   "options": "Finance Book"
+  },
+  {
+   "fieldname": "cb0",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "domain",
+   "fieldtype": "Link",
+   "label": "Domain",
+   "options": "Domain"
+  },
+  {
+   "fieldname": "parent_company",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Parent Company",
+   "options": "Company"
+  },
+  {
+   "fieldname": "company_logo",
+   "fieldtype": "Attach Image",
+   "hidden": 1,
+   "label": "Company Logo"
+  },
+  {
+   "fieldname": "company_description",
+   "fieldtype": "Text Editor",
+   "label": "Company Description"
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "sales_settings",
+   "fieldtype": "Section Break",
+   "label": "Sales Settings"
+  },
+  {
+   "fieldname": "sales_monthly_history",
+   "fieldtype": "Small Text",
+   "hidden": 1,
+   "label": "Sales Monthly History",
+   "no_copy": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "transactions_annual_history",
+   "fieldtype": "Code",
+   "hidden": 1,
+   "label": "Transactions Annual History",
+   "no_copy": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "monthly_sales_target",
+   "fieldtype": "Currency",
+   "label": "Monthly Sales Target",
+   "options": "default_currency"
+  },
+  {
+   "fieldname": "column_break_goals",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "total_monthly_sales",
+   "fieldtype": "Currency",
+   "label": "Total Monthly Sales",
+   "no_copy": 1,
+   "options": "default_currency",
+   "read_only": 1
+  },
+  {
+   "fieldname": "charts_section",
+   "fieldtype": "Section Break",
+   "label": "Default Values"
+  },
+  {
+   "fieldname": "default_currency",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Currency",
+   "options": "Currency",
+   "reqd": 1
+  },
+  {
+   "fieldname": "default_letter_head",
+   "fieldtype": "Link",
+   "label": "Default Letter Head",
+   "options": "Letter Head"
+  },
+  {
+   "fieldname": "default_holiday_list",
+   "fieldtype": "Link",
+   "label": "Default Holiday List",
+   "options": "Holiday List"
+  },
+  {
+   "fieldname": "standard_working_hours",
+   "fieldtype": "Float",
+   "label": "Standard Working Hours"
+  },
+  {
+   "fieldname": "default_warehouse_for_sales_return",
+   "fieldtype": "Link",
+   "label": "Default warehouse for Sales Return",
+   "options": "Warehouse"
+  },
+  {
+   "fieldname": "column_break_10",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "country",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Country",
+   "options": "Country",
+   "reqd": 1
+  },
+  {
+   "fieldname": "create_chart_of_accounts_based_on",
+   "fieldtype": "Select",
+   "label": "Create Chart Of Accounts Based On",
+   "options": "\nStandard Template\nExisting Company"
+  },
+  {
+   "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Standard Template\"",
+   "fieldname": "chart_of_accounts",
+   "fieldtype": "Select",
+   "label": "Chart Of Accounts Template",
+   "no_copy": 1
+  },
+  {
+   "depends_on": "eval:doc.create_chart_of_accounts_based_on===\"Existing Company\"",
+   "fieldname": "existing_company",
+   "fieldtype": "Link",
+   "label": "Existing Company ",
+   "no_copy": 1,
+   "options": "Company"
+  },
+  {
+   "fieldname": "tax_id",
+   "fieldtype": "Data",
+   "label": "Tax ID"
+  },
+  {
+   "fieldname": "date_of_establishment",
+   "fieldtype": "Date",
+   "label": "Date of Establishment"
+  },
+  {
+   "fieldname": "default_settings",
+   "fieldtype": "Section Break",
+   "label": "Accounts Settings",
+   "oldfieldtype": "Section Break"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_bank_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Bank Account",
+   "no_copy": 1,
+   "oldfieldname": "default_bank_account",
+   "oldfieldtype": "Link",
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_cash_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Cash Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_receivable_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Receivable Account",
+   "no_copy": 1,
+   "oldfieldname": "receivables_group",
+   "oldfieldtype": "Link",
+   "options": "Account"
+  },
+  {
+   "fieldname": "round_off_account",
+   "fieldtype": "Link",
+   "label": "Round Off Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "round_off_cost_center",
+   "fieldtype": "Link",
+   "label": "Round Off Cost Center",
+   "options": "Cost Center"
+  },
+  {
+   "fieldname": "write_off_account",
+   "fieldtype": "Link",
+   "label": "Write Off Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "discount_allowed_account",
+   "fieldtype": "Link",
+   "label": "Discount Allowed Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "discount_received_account",
+   "fieldtype": "Link",
+   "label": "Discount Received Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "exchange_gain_loss_account",
+   "fieldtype": "Link",
+   "label": "Exchange Gain / Loss Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "unrealized_exchange_gain_loss_account",
+   "fieldtype": "Link",
+   "label": "Unrealized Exchange Gain/Loss Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "column_break0",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break",
+   "width": "50%"
+  },
+  {
+   "default": "0",
+   "depends_on": "eval:doc.parent_company",
+   "fieldname": "allow_account_creation_against_child_company",
+   "fieldtype": "Check",
+   "label": "Allow Account Creation Against Child Company"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_payable_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Payable Account",
+   "no_copy": 1,
+   "oldfieldname": "payables_group",
+   "oldfieldtype": "Link",
+   "options": "Account"
+  },
+  {
+   "fieldname": "default_employee_advance_account",
+   "fieldtype": "Link",
+   "label": "Default Employee Advance Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_expense_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Cost of Goods Sold Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_income_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Income Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_deferred_revenue_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Deferred Revenue Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_deferred_expense_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Deferred Expense Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_payroll_payable_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Payroll Payable Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "default_expense_claim_payable_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Expense Claim Payable Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "fieldname": "section_break_22",
+   "fieldtype": "Section Break"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "cost_center",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Default Cost Center",
+   "no_copy": 1,
+   "options": "Cost Center"
+  },
+  {
+   "fieldname": "column_break_26",
+   "fieldtype": "Column Break"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "credit_limit",
+   "fieldtype": "Currency",
+   "label": "Credit Limit",
+   "oldfieldname": "credit_limit",
+   "oldfieldtype": "Currency",
+   "options": "default_currency"
+  },
+  {
+   "fieldname": "payment_terms",
+   "fieldtype": "Link",
+   "label": "Default Payment Terms Template",
+   "options": "Payment Terms Template"
+  },
+  {
+   "depends_on": "eval:!doc.__islocal",
+   "fieldname": "auto_accounting_for_stock_settings",
+   "fieldtype": "Section Break",
+   "label": "Stock Settings"
+  },
+  {
+   "default": "1",
+   "fieldname": "enable_perpetual_inventory",
+   "fieldtype": "Check",
+   "label": "Enable Perpetual Inventory"
+  },
+  {
+   "fieldname": "default_inventory_account",
+   "fieldtype": "Link",
+   "label": "Default Inventory Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "stock_adjustment_account",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Stock Adjustment Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "fieldname": "column_break_32",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "stock_received_but_not_billed",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Stock Received But Not Billed",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "fieldname": "expenses_included_in_valuation",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Expenses Included In Valuation",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "fixed_asset_depreciation_settings",
+   "fieldtype": "Section Break",
+   "label": "Fixed Asset Depreciation Settings"
+  },
+  {
+   "fieldname": "accumulated_depreciation_account",
+   "fieldtype": "Link",
+   "label": "Accumulated Depreciation Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "fieldname": "depreciation_expense_account",
+   "fieldtype": "Link",
+   "label": "Depreciation Expense Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "fieldname": "series_for_depreciation_entry",
+   "fieldtype": "Data",
+   "label": "Series for Asset Depreciation Entry (Journal Entry)"
+  },
+  {
+   "fieldname": "expenses_included_in_asset_valuation",
+   "fieldtype": "Link",
+   "label": "Expenses Included In Asset Valuation",
+   "options": "Account"
+  },
+  {
+   "fieldname": "column_break_40",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "disposal_account",
+   "fieldtype": "Link",
+   "label": "Gain/Loss Account on Asset Disposal",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "fieldname": "depreciation_cost_center",
+   "fieldtype": "Link",
+   "label": "Asset Depreciation Cost Center",
+   "no_copy": 1,
+   "options": "Cost Center"
+  },
+  {
+   "fieldname": "capital_work_in_progress_account",
+   "fieldtype": "Link",
+   "label": "Capital Work In Progress Account",
+   "options": "Account"
+  },
+  {
+   "fieldname": "asset_received_but_not_billed",
+   "fieldtype": "Link",
+   "label": "Asset Received But Not Billed",
+   "options": "Account"
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "budget_detail",
+   "fieldtype": "Section Break",
+   "label": "Budget Detail"
+  },
+  {
+   "fieldname": "exception_budget_approver_role",
+   "fieldtype": "Link",
+   "label": "Exception Budget Approver Role",
+   "options": "Role"
+  },
+  {
+   "collapsible": 1,
+   "description": "For reference only.",
+   "fieldname": "company_info",
+   "fieldtype": "Section Break",
+   "label": "Company Info"
+  },
+  {
+   "fieldname": "date_of_incorporation",
+   "fieldtype": "Date",
+   "label": "Date of Incorporation"
+  },
+  {
+   "fieldname": "address_html",
+   "fieldtype": "HTML"
+  },
+  {
+   "fieldname": "column_break1",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break",
+   "width": "50%"
+  },
+  {
+   "depends_on": "eval:doc.date_of_incorporation",
+   "fieldname": "date_of_commencement",
+   "fieldtype": "Date",
+   "label": "Date of Commencement"
+  },
+  {
+   "fieldname": "phone_no",
+   "fieldtype": "Data",
+   "label": "Phone No",
+   "oldfieldname": "phone_no",
+   "oldfieldtype": "Data",
+   "options": "Phone"
+  },
+  {
+   "fieldname": "fax",
+   "fieldtype": "Data",
+   "label": "Fax",
+   "oldfieldname": "fax",
+   "oldfieldtype": "Data",
+   "options": "Phone"
+  },
+  {
+   "fieldname": "email",
+   "fieldtype": "Data",
+   "label": "Email",
+   "oldfieldname": "email",
+   "oldfieldtype": "Data",
+   "options": "Email"
+  },
+  {
+   "fieldname": "website",
+   "fieldtype": "Data",
+   "label": "Website",
+   "oldfieldname": "website",
+   "oldfieldtype": "Data"
+  },
+  {
+   "fieldname": "registration_info",
+   "fieldtype": "Section Break",
+   "oldfieldtype": "Section Break",
+   "width": "50%"
+  },
+  {
+   "description": "Company registration numbers for your reference. Tax numbers etc.",
+   "fieldname": "registration_details",
+   "fieldtype": "Code",
+   "label": "Registration Details",
+   "oldfieldname": "registration_details",
+   "oldfieldtype": "Code"
+  },
+  {
+   "fieldname": "delete_company_transactions",
+   "fieldtype": "Button",
+   "label": "Delete Company Transactions"
+  },
+  {
+   "fieldname": "lft",
+   "fieldtype": "Int",
+   "hidden": 1,
+   "label": "Lft",
+   "print_hide": 1,
+   "read_only": 1,
+   "search_index": 1
+  },
+  {
+   "fieldname": "rgt",
+   "fieldtype": "Int",
+   "hidden": 1,
+   "label": "Rgt",
+   "print_hide": 1,
+   "read_only": 1,
+   "search_index": 1
+  },
+  {
+   "fieldname": "old_parent",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "old_parent",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "default_selling_terms",
+   "fieldtype": "Link",
+   "label": "Default Selling Terms",
+   "options": "Terms and Conditions"
+  },
+  {
+   "fieldname": "default_buying_terms",
+   "fieldtype": "Link",
+   "label": "Default Buying Terms",
+   "options": "Terms and Conditions"
+  }
+ ],
+ "icon": "fa fa-building",
+ "idx": 1,
+ "image_field": "company_logo",
+ "modified": "2019-07-04 22:20:45.104307",
+ "modified_by": "Administrator",
+ "module": "Setup",
+ "name": "Company",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "role": "Accounts User"
+  },
+  {
+   "read": 1,
+   "role": "Employee"
+  },
+  {
+   "read": 1,
+   "role": "Sales User"
+  },
+  {
+   "read": 1,
+   "role": "Purchase User"
+  },
+  {
+   "read": 1,
+   "role": "Stock User"
+  },
+  {
+   "read": 1,
+   "role": "Projects User"
+  }
+ ],
+ "show_name_in_global_search": 1,
+ "sort_field": "modified",
+ "sort_order": "ASC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
index c1d459f..aba6a79 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.json
@@ -1,288 +1,142 @@
 {
- "allow_copy": 0,
- "allow_guest_to_view": 0,
  "allow_import": 1,
  "allow_rename": 1,
  "autoname": "field:title",
- "beta": 0,
  "creation": "2013-01-10 16:34:24",
- "custom": 0,
  "description": "Standard Terms and Conditions that can be added to Sales and Purchases.\n\nExamples:\n\n1. Validity of the offer.\n1. Payment Terms (In Advance, On Credit, part advance etc).\n1. What is extra (or payable by the Customer).\n1. Safety / usage warning.\n1. Warranty if any.\n1. Returns Policy.\n1. Terms of shipping, if applicable.\n1. Ways of addressing disputes, indemnity, liability, etc.\n1. Address and Contact of your Company.",
- "docstatus": 0,
  "doctype": "DocType",
  "document_type": "Setup",
- "editable_grid": 0,
+ "engine": "InnoDB",
+ "field_order": [
+  "title",
+  "disabled",
+  "applicable_modules_section",
+  "selling",
+  "buying",
+  "hr",
+  "section_break_7",
+  "terms",
+  "terms_and_conditions_help"
+ ],
  "fields": [
   {
-   "allow_bulk_edit": 0,
-   "allow_in_quick_entry": 0,
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "columns": 0,
    "fieldname": "title",
    "fieldtype": "Data",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "ignore_xss_filter": 0,
-   "in_filter": 0,
-   "in_global_search": 0,
-   "in_list_view": 0,
-   "in_standard_filter": 0,
    "label": "Title",
-   "length": 0,
    "no_copy": 1,
    "oldfieldname": "title",
    "oldfieldtype": "Data",
-   "permlevel": 0,
-   "print_hide": 0,
-   "print_hide_if_no_value": 0,
-   "read_only": 0,
-   "remember_last_selected_value": 0,
-   "report_hide": 0,
    "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "translatable": 0,
    "unique": 1
   },
   {
-   "allow_bulk_edit": 0,
-   "allow_in_quick_entry": 0,
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "columns": 0,
+   "default": "0",
    "fieldname": "disabled",
    "fieldtype": "Check",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "ignore_xss_filter": 0,
-   "in_filter": 0,
-   "in_global_search": 0,
    "in_list_view": 1,
-   "in_standard_filter": 0,
-   "label": "Disabled",
-   "length": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "print_hide_if_no_value": 0,
-   "read_only": 0,
-   "remember_last_selected_value": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
-   "translatable": 0,
-   "unique": 0
+   "label": "Disabled"
   },
   {
-   "allow_bulk_edit": 0,
-   "allow_in_quick_entry": 0,
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "columns": 0,
+   "allow_in_quick_entry": 1,
    "fieldname": "terms",
    "fieldtype": "Text Editor",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "ignore_xss_filter": 0,
-   "in_filter": 0,
    "in_global_search": 1,
-   "in_list_view": 0,
-   "in_standard_filter": 0,
    "label": "Terms and Conditions",
-   "length": 0,
-   "no_copy": 0,
    "oldfieldname": "terms",
-   "oldfieldtype": "Text Editor",
-   "permlevel": 0,
-   "print_hide": 0,
-   "print_hide_if_no_value": 0,
-   "read_only": 0,
-   "remember_last_selected_value": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
-   "translatable": 0,
-   "unique": 0
+   "oldfieldtype": "Text Editor"
   },
   {
-   "allow_bulk_edit": 0,
-   "allow_in_quick_entry": 0,
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "columns": 0,
    "fieldname": "terms_and_conditions_help",
    "fieldtype": "HTML",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "ignore_xss_filter": 0,
-   "in_filter": 0,
-   "in_global_search": 0,
-   "in_list_view": 0,
-   "in_standard_filter": 0,
    "label": "Terms and Conditions Help",
-   "length": 0,
-   "no_copy": 0,
-   "options": "<h4>Standard Terms and Conditions Example</h4>\n\n<pre>Delivery Terms for Order number {{ name }}\n\n-Order Date : {{ transaction_date }} \n-Expected Delivery Date : {{ delivery_date }}\n</pre>\n\n<h4>How to get fieldnames</h4>\n\n<p>The fieldnames you can use in your email template are the fields in the document from which you are sending the email. You can find out the fields of any documents via Setup &gt; Customize Form View and selecting the document type (e.g. Sales Invoice)</p>\n\n<h4>Templating</h4>\n\n<p>Templates are compiled using the Jinja Templating Langauge. To learn more about Jinja, <a class=\"strong\" href=\"http://jinja.pocoo.org/docs/dev/templates/\">read this documentation.</a></p>",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "print_hide_if_no_value": 0,
-   "read_only": 0,
-   "remember_last_selected_value": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
-   "translatable": 0,
-   "unique": 0
+   "options": "<h4>Standard Terms and Conditions Example</h4>\n\n<pre>Delivery Terms for Order number {{ name }}\n\n-Order Date : {{ transaction_date }} \n-Expected Delivery Date : {{ delivery_date }}\n</pre>\n\n<h4>How to get fieldnames</h4>\n\n<p>The fieldnames you can use in your email template are the fields in the document from which you are sending the email. You can find out the fields of any documents via Setup &gt; Customize Form View and selecting the document type (e.g. Sales Invoice)</p>\n\n<h4>Templating</h4>\n\n<p>Templates are compiled using the Jinja Templating Langauge. To learn more about Jinja, <a class=\"strong\" href=\"http://jinja.pocoo.org/docs/dev/templates/\">read this documentation.</a></p>"
+  },
+  {
+   "fieldname": "applicable_modules_section",
+   "fieldtype": "Section Break",
+   "label": "Applicable Modules"
+  },
+  {
+   "default": "1",
+   "fieldname": "selling",
+   "fieldtype": "Check",
+   "label": "Selling"
+  },
+  {
+   "default": "1",
+   "fieldname": "buying",
+   "fieldtype": "Check",
+   "label": "Buying"
+  },
+  {
+   "default": "1",
+   "fieldname": "hr",
+   "fieldtype": "Check",
+   "label": "HR"
+  },
+  {
+   "fieldname": "section_break_7",
+   "fieldtype": "Section Break"
   }
  ],
- "has_web_view": 0,
- "hide_heading": 0,
- "hide_toolbar": 0,
  "icon": "icon-legal",
  "idx": 1,
- "image_view": 0,
- "in_create": 0,
- "is_submittable": 0,
- "issingle": 0,
- "istable": 0,
- "max_attachments": 0,
- "modified": "2018-08-29 06:36:33.131473",
+ "modified": "2019-07-04 13:31:30.393425",
  "modified_by": "Administrator",
  "module": "Setup",
  "name": "Terms and Conditions",
  "owner": "Administrator",
  "permissions": [
   {
-   "amend": 0,
-   "cancel": 0,
    "create": 1,
    "delete": 1,
    "email": 1,
    "export": 1,
-   "if_owner": 0,
    "import": 1,
-   "permlevel": 0,
    "print": 1,
    "read": 1,
    "report": 1,
    "role": "Sales Master Manager",
-   "set_user_permissions": 0,
    "share": 1,
-   "submit": 0,
    "write": 1
   },
   {
-   "amend": 0,
-   "cancel": 0,
-   "create": 0,
-   "delete": 0,
-   "email": 0,
-   "export": 0,
-   "if_owner": 0,
-   "import": 0,
-   "permlevel": 0,
-   "print": 0,
    "read": 1,
-   "report": 0,
-   "role": "Sales User",
-   "set_user_permissions": 0,
-   "share": 0,
-   "submit": 0,
-   "write": 0
+   "role": "Sales User"
   },
   {
-   "amend": 0,
-   "cancel": 0,
-   "create": 0,
-   "delete": 0,
-   "email": 0,
-   "export": 0,
-   "if_owner": 0,
-   "import": 0,
-   "permlevel": 0,
-   "print": 0,
    "read": 1,
-   "report": 0,
-   "role": "Purchase User",
-   "set_user_permissions": 0,
-   "share": 0,
-   "submit": 0,
-   "write": 0
+   "role": "Purchase User"
   },
   {
-   "amend": 0,
-   "cancel": 0,
    "create": 1,
    "delete": 1,
    "email": 1,
-   "export": 0,
-   "if_owner": 0,
-   "import": 0,
-   "permlevel": 0,
    "print": 1,
    "read": 1,
    "report": 1,
    "role": "System Manager",
-   "set_user_permissions": 0,
    "share": 1,
-   "submit": 0,
    "write": 1
   },
   {
-   "amend": 0,
-   "cancel": 0,
    "create": 1,
    "delete": 1,
    "email": 1,
-   "export": 0,
-   "if_owner": 0,
-   "import": 0,
-   "permlevel": 0,
    "print": 1,
    "read": 1,
    "report": 1,
    "role": "Accounts User",
-   "set_user_permissions": 0,
    "share": 1,
-   "submit": 0,
    "write": 1
   },
   {
-   "amend": 0,
-   "cancel": 0,
-   "create": 0,
-   "delete": 0,
-   "email": 0,
-   "export": 0,
-   "if_owner": 0,
-   "import": 0,
-   "permlevel": 0,
-   "print": 0,
    "read": 1,
-   "report": 0,
-   "role": "Stock User",
-   "set_user_permissions": 0,
-   "share": 0,
-   "submit": 0,
-   "write": 0
+   "role": "Stock User"
   }
  ],
  "quick_entry": 1,
- "read_only": 0,
- "read_only_onload": 0,
  "show_name_in_global_search": 1,
- "sort_order": "ASC",
- "track_changes": 0,
- "track_seen": 0,
- "track_views": 0
+ "sort_field": "modified",
+ "sort_order": "ASC"
 }
\ No newline at end of file
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 a2152a6..372cc6d 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
@@ -3,9 +3,11 @@
 
 from __future__ import unicode_literals
 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 six import string_types
 
@@ -13,6 +15,8 @@
 	def validate(self):
 		if self.terms:
 			validate_template(self.terms)
+		if not cint(self.buying) and not cint(self.selling) and not cint(self.hr) and not cint(self.disabled):
+			throw(_("At least one of the Applicable Modules should be selected"))
 
 @frappe.whitelist()
 def get_terms_and_conditions(template_name, doc):
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index a5bd93f..4ca43a8 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -33,7 +33,7 @@
 				FROM `tabCompany`
 				LIMIT 1""") and 'Yes' or 'No'
 
-		bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_terms,
+		bootinfo.docs += frappe.db.sql("""select name, default_currency, cost_center, default_selling_terms, default_buying_terms,
 			default_letter_head, default_bank_account, enable_perpetual_inventory, country from `tabCompany`""",
 			as_dict=1, update={"doctype":":Company"})
 
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index 3936bf7..164ffa4 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -76,7 +76,6 @@
    "is_customer_provided_item",
    "customer",
    "supplier_details",
-   "manufacturers",
    "delivered_by_supplier",
    "column_break2",
    "supplier_items",
@@ -1022,12 +1021,6 @@
     "fieldtype": "Check",
     "label": "Synced With Hub",
     "read_only": 1
-   },
-   {
-    "fieldname": "manufacturers",
-    "fieldtype": "Table",
-    "label": "Manufacturers",
-    "options": "Item Manufacturer"
    }
   ],
   "has_web_view": 1,
@@ -1035,7 +1028,7 @@
   "idx": 2,
   "image_field": "image",
   "max_attachments": 1,
-  "modified": "2019-06-02 04:45:59.911507",
+  "modified": "2019-07-05 12:18:13.977931",
   "modified_by": "Administrator",
   "module": "Stock",
   "name": "Item",
@@ -1097,4 +1090,4 @@
   "sort_order": "DESC",
   "title_field": "item_name",
   "track_changes": 1
- }
\ No newline at end of file
+ }
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 80d4e17..6484b93 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -122,6 +122,7 @@
 		self.validate_item_defaults()
 		self.validate_customer_provided_part()
 		self.update_defaults_from_item_group()
+		self.validate_auto_reorder_enabled_in_stock_settings()
 		self.cant_change()
 
 		if not self.get("__islocal"):
@@ -859,6 +860,12 @@
 					filters={"production_item": self.name, "docstatus": 1}):
 				return True
 
+	def validate_auto_reorder_enabled_in_stock_settings(self):
+		if self.reorder_levels:
+			enabled = frappe.db.get_single_value('Stock Settings', 'auto_indent')
+			if not enabled:
+				frappe.msgprint(msg=_("You have to enable auto re-order in Stock Settings to maintain re-order levels."), title=_("Enable Auto Re-Order"), indicator="orange")
+
 def get_timeline_data(doctype, name):
 	'''returns timeline data based on stock ledger entry'''
 	out = {}
diff --git a/erpnext/stock/doctype/item/item_dashboard.py b/erpnext/stock/doctype/item/item_dashboard.py
index b3733d3..dd4676a 100644
--- a/erpnext/stock/doctype/item/item_dashboard.py
+++ b/erpnext/stock/doctype/item/item_dashboard.py
@@ -41,7 +41,7 @@
 			},
 			{
 				'label': _('Manufacture'),
-				'items': ['Work Order', 'Item Manufacturer']
+				'items': ['Production Plan', 'Work Order', 'Item Manufacturer']
 			}
 		]
-	}
\ No newline at end of file
+	}
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index ef5f24e..2b079e7 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -370,19 +370,20 @@
 def get_material_requests_based_on_supplier(supplier):
 	supplier_items = [d.parent for d in frappe.db.get_all("Item Default",
 		{"default_supplier": supplier}, 'parent')]
-	if supplier_items:
-		material_requests = frappe.db.sql_list("""select distinct mr.name
-			from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
-			where mr.name = mr_item.parent
-				and mr_item.item_code in (%s)
-				and mr.material_request_type = 'Purchase'
-				and mr.per_ordered < 99.99
-				and mr.docstatus = 1
-				and mr.status != 'Stopped'
-			order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)),
-			tuple(supplier_items))
-	else:
-		material_requests = []
+	if not supplier_items:
+		frappe.throw(_("{0} is not the default supplier for any items.".format(supplier)))
+
+	material_requests = frappe.db.sql_list("""select distinct mr.name
+		from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
+		where mr.name = mr_item.parent
+			and mr_item.item_code in (%s)
+			and mr.material_request_type = 'Purchase'
+			and mr.per_ordered < 99.99
+			and mr.docstatus = 1
+			and mr.status != 'Stopped'
+		order by mr_item.item_code ASC""" % ', '.join(['%s']*len(supplier_items)),
+		tuple(supplier_items))
+
 	return material_requests, supplier_items
 
 @frappe.whitelist()
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 464101e..0abcbb3 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -324,8 +324,10 @@
 			completed_qty = d.completed_qty + (allowance_percentage/100 * d.completed_qty)
 			if total_completed_qty > flt(completed_qty):
 				job_card = frappe.db.get_value('Job Card', {'operation_id': d.name}, 'name')
-				frappe.throw(_("Row #{0}: Operation {1} is not completed for {2} qty of finished goods in Work Order # {3}. Please update operation status via Job Card # {4}")
-					.format(d.idx, d.operation, total_completed_qty, self.work_order, job_card), OperationsNotCompleteError)
+				work_order_link = frappe.utils.get_link_to_form('Work Order', self.work_order)
+				job_card_link = frappe.utils.get_link_to_form('Job Card', job_card)
+				frappe.throw(_("Row #{0}: Operation {1} is not completed for {2} qty of finished goods in Work Order {3}. Please update operation status via Job Card {4}.")
+					.format(d.idx, frappe.bold(d.operation), frappe.bold(total_completed_qty), work_order_link, job_card_link), OperationsNotCompleteError)
 
 	def check_duplicate_entry_for_work_order(self):
 		other_ste = [t[0] for t in frappe.db.get_values("Stock Entry",  {