fix: merge conflict
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 5febfd6..5fbc460 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -8,11 +8,14 @@
 from frappe.utils import nowdate, getdate
 from collections import defaultdict
 from erpnext.stock.get_item_details import _get_item_tax_template
+from frappe.utils import unique
 
  # searches for active employees
 def employee_query(doctype, txt, searchfield, start, page_len, filters):
 	conditions = []
-	return frappe.db.sql("""select name, employee_name from `tabEmployee`
+	fields = get_fields("Employee", ["name", "employee_name"])
+
+	return frappe.db.sql("""select {fields} from `tabEmployee`
 		where status = 'Active'
 			and docstatus < 2
 			and ({key} like %(txt)s
@@ -24,6 +27,7 @@
 			idx desc,
 			name, employee_name
 		limit %(start)s, %(page_len)s""".format(**{
+			'fields': ", ".join(fields),
 			'key': searchfield,
 			'fcond': get_filters_cond(doctype, filters, conditions),
 			'mcond': get_match_cond(doctype)
@@ -34,9 +38,12 @@
 			'page_len': page_len
 		})
 
- # searches for leads which are not converted
+
+# searches for leads which are not converted
 def lead_query(doctype, txt, searchfield, start, page_len, filters):
-	return frappe.db.sql("""select name, lead_name, company_name from `tabLead`
+	fields = get_fields("Lead", ["name", "lead_name", "company_name"])
+
+	return frappe.db.sql("""select {fields} from `tabLead`
 		where docstatus < 2
 			and ifnull(status, '') != 'Converted'
 			and ({key} like %(txt)s
@@ -50,6 +57,7 @@
 			idx desc,
 			name, lead_name
 		limit %(start)s, %(page_len)s""".format(**{
+			'fields': ", ".join(fields),
 			'key': searchfield,
 			'mcond':get_match_cond(doctype)
 		}), {
@@ -59,6 +67,7 @@
 			'page_len': page_len
 		})
 
+
  # searches for customer
 def customer_query(doctype, txt, searchfield, start, page_len, filters):
 	conditions = []
@@ -69,13 +78,9 @@
 	else:
 		fields = ["name", "customer_name", "customer_group", "territory"]
 
-	meta = frappe.get_meta("Customer")
-	searchfields = meta.get_search_fields()
-	searchfields = searchfields + [f for f in [searchfield or "name", "customer_name"] \
-			if not f in searchfields]
-	fields = fields + [f for f in searchfields if not f in fields]
+	fields = get_fields("Customer", fields)
 
-	fields = ", ".join(fields)
+	searchfields = frappe.get_meta("Customer").get_search_fields()
 	searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
 
 	return frappe.db.sql("""select {fields} from `tabCustomer`
@@ -88,7 +93,7 @@
 			idx desc,
 			name, customer_name
 		limit %(start)s, %(page_len)s""".format(**{
-			"fields": fields,
+			"fields": ", ".join(fields),
 			"scond": searchfields,
 			"mcond": get_match_cond(doctype),
 			"fcond": get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
@@ -99,6 +104,7 @@
 			'page_len': page_len
 		})
 
+
 # searches for supplier
 def supplier_query(doctype, txt, searchfield, start, page_len, filters):
 	supp_master_name = frappe.defaults.get_user_default("supp_master_name")
@@ -106,7 +112,8 @@
 		fields = ["name", "supplier_group"]
 	else:
 		fields = ["name", "supplier_name", "supplier_group"]
-	fields = ", ".join(fields)
+
+	fields = get_fields("Supplier", fields)
 
 	return frappe.db.sql("""select {field} from `tabSupplier`
 		where docstatus < 2
@@ -119,7 +126,7 @@
 			idx desc,
 			name, supplier_name
 		limit %(start)s, %(page_len)s """.format(**{
-			'field': fields,
+			'field': ', '.join(fields),
 			'key': searchfield,
 			'mcond':get_match_cond(doctype)
 		}), {
@@ -129,6 +136,7 @@
 			'page_len': page_len
 		})
 
+
 def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
 	company_currency = erpnext.get_company_currency(filters.get('company'))
 
@@ -153,6 +161,7 @@
 
 	return tax_accounts
 
+
 def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
 	conditions = []
 
@@ -221,10 +230,12 @@
 				"page_len": page_len
 			}, as_dict=as_dict)
 
+
 def bom(doctype, txt, searchfield, start, page_len, filters):
 	conditions = []
+	fields = get_fields("BOM", ["name", "item"])
 
-	return frappe.db.sql("""select tabBOM.name, tabBOM.item
+	return frappe.db.sql("""select {fields}
 		from tabBOM
 		where tabBOM.docstatus=1
 			and tabBOM.is_active=1
@@ -234,6 +245,7 @@
 			if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
 			idx desc, name
 		limit %(start)s, %(page_len)s """.format(
+			fields=", ".join(fields),
 			fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
 			mcond=get_match_cond(doctype).replace('%', '%%'),
 			key=searchfield),
@@ -244,13 +256,16 @@
 			'page_len': page_len or 20
 		})
 
+
 def get_project_name(doctype, txt, searchfield, start, page_len, filters):
 	cond = ''
 	if filters.get('customer'):
 		cond = """(`tabProject`.customer = %s or
 			ifnull(`tabProject`.customer,"")="") and""" %(frappe.db.escape(filters.get("customer")))
 
-	return frappe.db.sql("""select `tabProject`.name from `tabProject`
+	fields = get_fields("Project", ["name"])
+
+	return frappe.db.sql("""select {fields} from `tabProject`
 		where `tabProject`.status not in ("Completed", "Cancelled")
 			and {cond} `tabProject`.name like %(txt)s {match_cond}
 		order by
@@ -258,6 +273,7 @@
 			idx desc,
 			`tabProject`.name asc
 		limit {start}, {page_len}""".format(
+			fields=", ".join(['`tabProject`.{0}'.format(f) for f in fields]),
 			cond=cond,
 			match_cond=get_match_cond(doctype),
 			start=start,
@@ -268,8 +284,10 @@
 
 
 def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, filters, as_dict):
+	fields = get_fields("Delivery Note", ["name", "customer", "posting_date"])
+
 	return frappe.db.sql("""
-		select `tabDelivery Note`.name, `tabDelivery Note`.customer, `tabDelivery Note`.posting_date
+		select %(fields)s
 		from `tabDelivery Note`
 		where `tabDelivery Note`.`%(key)s` like %(txt)s and
 			`tabDelivery Note`.docstatus = 1
@@ -284,6 +302,7 @@
 			)
 			%(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(start)s, %(page_len)s
 	""" % {
+		"fields": ", ".join(["`tabDelivery Note`.{0}".format(f) for f in fields]),
 		"key": searchfield,
 		"fcond": get_filters_cond(doctype, filters, []),
 		"mcond": get_match_cond(doctype),
@@ -349,6 +368,7 @@
 			order by expiry_date, name desc
 			limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args)
 
+
 def get_account_list(doctype, txt, searchfield, start, page_len, filters):
 	filter_list = []
 
@@ -371,6 +391,7 @@
 		fields = ["name", "parent_account"],
 		limit_start=start, limit_page_length=page_len, as_list=True)
 
+
 def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters):
 	return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date
 		from `tabBlanket Order` bo, `tabBlanket Order Item` boi
@@ -385,6 +406,7 @@
 			company = frappe.db.escape(filters.get("company"))
 		))
 
+
 @frappe.whitelist()
 def get_income_account(doctype, txt, searchfield, start, page_len, filters):
 	from erpnext.controllers.queries import get_match_cond
@@ -490,6 +512,7 @@
 
 	return frappe.db.sql(query, filters)
 
+
 @frappe.whitelist()
 def item_manufacturer_query(doctype, txt, searchfield, start, page_len, filters):
 	item_filters = [
@@ -507,6 +530,7 @@
 	)
 	return item_manufacturers
 
+
 @frappe.whitelist()
 def get_purchase_receipts(doctype, txt, searchfield, start, page_len, filters):
 	query = """
@@ -520,6 +544,7 @@
 
 	return frappe.db.sql(query, filters)
 
+
 @frappe.whitelist()
 def get_purchase_invoices(doctype, txt, searchfield, start, page_len, filters):
 	query = """
@@ -533,6 +558,7 @@
 
 	return frappe.db.sql(query, filters)
 
+
 @frappe.whitelist()
 def get_tax_template(doctype, txt, searchfield, start, page_len, filters):
 
@@ -556,3 +582,13 @@
 
 		taxes = _get_item_tax_template(args, taxes, for_validate=True)
 		return [(d,) for d in set(taxes)]
+
+
+def get_fields(doctype, fields=[]):
+	meta = frappe.get_meta(doctype)
+	fields.extend(meta.get_search_fields())
+
+	if meta.title_field and not meta.title_field.strip() in fields:
+		fields.insert(1, meta.title_field.strip())
+
+	return unique(fields)
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index ebfb762..44da9ca 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -212,6 +212,12 @@
 		});
 	},
 
+	rm_cost_as_per: function(frm) {
+		if (in_list(["Valuation Rate", "Last Purchase Rate"], frm.doc.rm_cost_as_per)) {
+			frm.set_value("plc_conversion_rate", 1.0);
+		}
+	},
+
 	routing: function(frm) {
 		if (frm.doc.routing) {
 			frappe.call({
@@ -242,7 +248,7 @@
 	item_code: function(doc, cdt, cdn){
 		var scrap_items = false;
 		var child = locals[cdt][cdn];
-		if(child.doctype == 'BOM Scrap Item') {
+		if (child.doctype == 'BOM Scrap Item') {
 			scrap_items = true;
 		}
 
@@ -252,8 +258,19 @@
 
 		get_bom_material_detail(doc, cdt, cdn, scrap_items);
 	},
+
+	buying_price_list: function(doc) {
+		this.apply_price_list();
+	},
+
+	plc_conversion_rate: function(doc) {
+		if (!this.in_apply_price_list) {
+			this.apply_price_list();
+		}
+	},
+
 	conversion_factor: function(doc, cdt, cdn) {
-		if(frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
+		if (frappe.meta.get_docfield(cdt, "stock_qty", cdn)) {
 			var item = frappe.get_doc(cdt, cdn);
 			frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
 			item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json
index 63f4f97..4ce0ecf 100644
--- a/erpnext/manufacturing/doctype/bom/bom.json
+++ b/erpnext/manufacturing/doctype/bom/bom.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "allow_import": 1,
  "creation": "2013-01-22 15:11:38",
  "doctype": "DocType",
@@ -6,23 +7,25 @@
  "engine": "InnoDB",
  "field_order": [
   "item",
-  "quantity",
-  "set_rate_of_sub_assembly_item_based_on_bom",
+  "company",
+  "item_name",
+  "uom",
   "cb0",
   "is_active",
   "is_default",
   "allow_alternative_item",
-  "image",
-  "item_name",
-  "uom",
-  "currency_detail",
-  "company",
+  "set_rate_of_sub_assembly_item_based_on_bom",
   "project",
+  "quantity",
+  "image",
+  "currency_detail",
+  "currency",
   "conversion_rate",
   "column_break_12",
-  "currency",
   "rm_cost_as_per",
   "buying_price_list",
+  "price_list_currency",
+  "plc_conversion_rate",
   "section_break_21",
   "with_operations",
   "column_break_23",
@@ -176,7 +179,8 @@
   },
   {
    "fieldname": "currency_detail",
-   "fieldtype": "Section Break"
+   "fieldtype": "Section Break",
+   "label": "Currency and Price List"
   },
   {
    "fieldname": "company",
@@ -324,7 +328,7 @@
   },
   {
    "fieldname": "base_scrap_material_cost",
-   "fieldtype": "Data",
+   "fieldtype": "Currency",
    "label": "Scrap Material Cost(Company Currency)",
    "no_copy": 1,
    "options": "Company:company:default_currency",
@@ -477,13 +481,31 @@
   {
    "fieldname": "column_break_52",
    "fieldtype": "Column Break"
+  },
+  {
+   "allow_on_submit": 1,
+   "depends_on": "eval:doc.rm_cost_as_per=='Price List'",
+   "fieldname": "plc_conversion_rate",
+   "fieldtype": "Float",
+   "label": "Price List Exchange Rate"
+  },
+  {
+   "allow_on_submit": 1,
+   "depends_on": "eval:doc.rm_cost_as_per=='Price List'",
+   "fieldname": "price_list_currency",
+   "fieldtype": "Link",
+   "label": "Price List Currency",
+   "options": "Currency",
+   "print_hide": 1,
+   "read_only": 1
   }
  ],
  "icon": "fa fa-sitemap",
  "idx": 1,
  "image_field": "image",
  "is_submittable": 1,
- "modified": "2019-11-22 14:35:12.142150",
+ "links": [],
+ "modified": "2020-05-05 14:29:32.634952",
  "modified_by": "Administrator",
  "module": "Manufacturing",
  "name": "BOM",
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index b1fc4de..6ac653e 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -70,11 +70,13 @@
 		self.validate_main_item()
 		self.validate_currency()
 		self.set_conversion_rate()
+		self.set_plc_conversion_rate()
 		self.validate_uom_is_interger()
 		self.set_bom_material_details()
 		self.validate_materials()
 		self.validate_operations()
 		self.calculate_cost()
+		self.update_cost(update_parent=False, from_child_bom=True, save=False)
 
 	def get_context(self, context):
 		context.parents = [{'name': 'boms', 'title': _('All BOMs') }]
@@ -165,7 +167,7 @@
 			 'rate'			: rate,
 			 'qty'			: args.get("qty") or args.get("stock_qty") or 1,
 			 'stock_qty'	: args.get("qty") or args.get("stock_qty") or 1,
-			 'base_rate'	: rate,
+			 'base_rate'	: flt(rate) * (flt(self.conversion_rate) or 1),
 			 'include_item_in_manufacturing': cint(args['transfer_for_manufacture']) or 0
 		}
 
@@ -226,7 +228,7 @@
 							frappe.msgprint(_("{0} not found for item {1}")
 								.format(self.rm_cost_as_per, arg["item_code"]), alert=True)
 
-		return flt(rate) / (self.conversion_rate or 1)
+		return flt(rate) * flt(self.plc_conversion_rate or 1) / (self.conversion_rate or 1)
 
 	def update_cost(self, update_parent=True, from_child_bom=False, save=True):
 		if self.docstatus == 2:
@@ -243,10 +245,15 @@
 				"stock_uom": d.stock_uom,
 				"conversion_factor": d.conversion_factor
 			})
+
 			if rate:
 				d.rate = rate
 			d.amount = flt(d.rate) * flt(d.qty)
-			d.db_update()
+			d.base_rate = flt(d.rate) * flt(self.conversion_rate)
+			d.base_amount = flt(d.amount) * flt(self.conversion_rate)
+
+			if save:
+				d.db_update()
 
 		if self.docstatus == 1:
 			self.flags.ignore_validate_update_after_submit = True
@@ -372,6 +379,13 @@
 		elif self.conversion_rate == 1 or flt(self.conversion_rate) <= 0:
 			self.conversion_rate = get_exchange_rate(self.currency, self.company_currency(), args="for_buying")
 
+	def set_plc_conversion_rate(self):
+		if self.rm_cost_as_per in ["Valuation Rate", "Last Purchase Rate"]:
+			self.plc_conversion_rate = 1
+		elif not self.plc_conversion_rate and self.price_list_currency:
+			self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
+				self.company_currency(), args="for_buying")
+
 	def validate_materials(self):
 		""" Validate raw material entries """
 
diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py
index 45a7b93..3dfd03b 100644
--- a/erpnext/manufacturing/doctype/bom/test_bom.py
+++ b/erpnext/manufacturing/doctype/bom/test_bom.py
@@ -81,13 +81,13 @@
 
 		# test amounts in selected currency
 		self.assertEqual(bom.operating_cost, 100)
-		self.assertEqual(bom.raw_material_cost, 8000)
-		self.assertEqual(bom.total_cost, 8100)
+		self.assertEqual(bom.raw_material_cost, 351.68)
+		self.assertEqual(bom.total_cost, 451.68)
 
 		# test amounts in selected currency
 		self.assertEqual(bom.base_operating_cost, 6000)
-		self.assertEqual(bom.base_raw_material_cost, 480000)
-		self.assertEqual(bom.base_total_cost, 486000)
+		self.assertEqual(bom.base_raw_material_cost, 21100.80)
+		self.assertEqual(bom.base_total_cost, 27100.80)
 
 	def test_bom_cost_multi_uom_multi_currency_based_on_price_list(self):
 		frappe.db.set_value("Price List", "_Test Price List", "price_not_uom_dependent", 1)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index e88e05d..7b66a2d 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -685,4 +685,5 @@
 erpnext.patches.v12_0.unset_customer_supplier_based_on_type_of_item_price
 erpnext.patches.v12_0.set_valid_till_date_in_supplier_quotation
 erpnext.patches.v12_0.set_serial_no_status
-execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts')
\ No newline at end of file
+erpnext.patches.v12_0.update_price_list_currency_in_bom
+execute:frappe.delete_doc_if_exists('Dashboard', 'Accounts')
diff --git a/erpnext/patches/v12_0/update_price_list_currency_in_bom.py b/erpnext/patches/v12_0/update_price_list_currency_in_bom.py
new file mode 100644
index 0000000..f5e7b94
--- /dev/null
+++ b/erpnext/patches/v12_0/update_price_list_currency_in_bom.py
@@ -0,0 +1,31 @@
+from __future__ import unicode_literals
+import frappe
+from frappe.utils import getdate, flt
+from erpnext.setup.utils import get_exchange_rate
+
+def execute():
+	frappe.reload_doc("manufacturing", "doctype", "bom")
+	frappe.reload_doc("manufacturing", "doctype", "bom_item")
+
+	frappe.db.sql(""" UPDATE `tabBOM`, `tabPrice List`
+		SET
+			`tabBOM`.price_list_currency = `tabPrice List`.currency,
+			`tabBOM`.plc_conversion_rate = 1.0
+		WHERE
+			`tabBOM`.buying_price_list = `tabPrice List`.name AND `tabBOM`.docstatus < 2
+			AND `tabBOM`.rm_cost_as_per = 'Price List'
+	""")
+
+	for d in frappe.db.sql("""
+		SELECT
+			bom.creation, bom.name, bom.price_list_currency as currency,
+			company.default_currency as company_currency
+		FROM
+			`tabBOM` as bom, `tabCompany` as company
+		WHERE
+			bom.company = company.name AND bom.rm_cost_as_per = 'Price List' AND
+			bom.price_list_currency != company.default_currency AND bom.docstatus < 2""", as_dict=1):
+			plc_conversion_rate = get_exchange_rate(d.currency,
+				d.company_currency, getdate(d.creation), "for_buying")
+
+			frappe.db.set_value("BOM", d.name, "plc_conversion_rate", plc_conversion_rate)
\ No newline at end of file
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 3d172ac..a6889e0 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -337,11 +337,15 @@
 	return lp_details
 
 def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None):
+	from erpnext.controllers.queries import get_fields
+
 	if frappe.db.get_default("cust_master_name") == "Customer Name":
 		fields = ["name", "customer_group", "territory"]
 	else:
 		fields = ["name", "customer_name", "customer_group", "territory"]
 
+	fields = get_fields("Customer", fields)
+
 	match_conditions = build_match_conditions("Customer")
 	match_conditions = "and {}".format(match_conditions) if match_conditions else ""
 
@@ -349,14 +353,17 @@
 		filter_conditions = get_filters_cond(doctype, filters, [])
 		match_conditions += "{}".format(filter_conditions)
 
-	return frappe.db.sql("""select %s from `tabCustomer` where docstatus < 2
-		and (%s like %s or customer_name like %s)
-		{match_conditions}
+	return frappe.db.sql("""
+		select %s
+		from `tabCustomer`
+		where docstatus < 2
+			and (%s like %s or customer_name like %s)
+			{match_conditions}
 		order by
-		case when name like %s then 0 else 1 end,
-		case when customer_name like %s then 0 else 1 end,
-		name, customer_name limit %s, %s""".format(match_conditions=match_conditions) %
-		(", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
+			case when name like %s then 0 else 1 end,
+			case when customer_name like %s then 0 else 1 end,
+			name, customer_name limit %s, %s
+		""".format(match_conditions=match_conditions) % (", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"),
 		("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len))
 
 
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.js b/erpnext/selling/page/sales_funnel/sales_funnel.js
index 85c0cd8..e3d0a55 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.js
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.js
@@ -90,6 +90,10 @@
 
 	get_data(btn) {
 		var me = this;
+		if (!this.company) {
+			frappe.throw(__("Please Select a Company."));
+		}
+
 		const method_map = {
 			"sales_funnel": "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data",
 			"opp_by_lead_source": "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source",
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py
index d62e209..dba24ef 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.py
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.py
@@ -8,14 +8,23 @@
 from erpnext.accounts.report.utils import convert
 import pandas as pd
 
+def validate_filters(from_date, to_date, company):
+	if from_date and to_date and (from_date >= to_date):
+		frappe.throw(_("To Date must be greater than From Date"))
+
+	if not company:
+		frappe.throw(_("Please Select a Company"))
+
 @frappe.whitelist()
 def get_funnel_data(from_date, to_date, company):
+	validate_filters(from_date, to_date, company)
+
 	active_leads = frappe.db.sql("""select count(*) from `tabLead`
 		where (date(`modified`) between %s and %s)
 		and status != "Do Not Contact" and company=%s""", (from_date, to_date, company))[0][0]
 
 	active_leads += frappe.db.sql("""select count(distinct contact.name) from `tabContact` contact
-		left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer' 
+		left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer'
 		and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
 
 	opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
@@ -38,6 +47,8 @@
 
 @frappe.whitelist()
 def get_opp_by_lead_source(from_date, to_date, company):
+	validate_filters(from_date, to_date, company)
+
 	opportunities = frappe.get_all("Opportunity", filters=[['status', 'in', ['Open', 'Quotation', 'Replied']], ['company', '=', company], ['transaction_date', 'Between', [from_date, to_date]]], fields=['currency', 'sales_stage', 'opportunity_amount', 'probability', 'source'])
 
 	if opportunities:
@@ -68,11 +79,13 @@
 
 @frappe.whitelist()
 def get_pipeline_data(from_date, to_date, company):
+	validate_filters(from_date, to_date, company)
+
 	opportunities = frappe.get_all("Opportunity", filters=[['status', 'in', ['Open', 'Quotation', 'Replied']], ['company', '=', company], ['transaction_date', 'Between', [from_date, to_date]]], fields=['currency', 'sales_stage', 'opportunity_amount', 'probability'])
 
 	if opportunities:
 		default_currency = frappe.get_cached_value('Global Defaults', 'None',  'default_currency')
-		
+
 		cp_opportunities = [dict(x, **{'compound_amount': (convert(x['opportunity_amount'], x['currency'], default_currency, to_date) * x['probability']/100)}) for x in opportunities]
 
 		df = pd.DataFrame(cp_opportunities).groupby(['sales_stage'], as_index=True).agg({'compound_amount': 'sum'}).to_dict()