Merge pull request #3190 from nabinhait/v4.x.x

Fixes
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py
index 2cf8673..25f429a 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.py
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import flt
+from frappe.utils import flt, cstr
 from frappe import _
 
 from erpnext.stock.doctype.item.item import get_last_purchase_details
@@ -64,7 +64,7 @@
 							= d.rate = item_last_purchase_rate
 
 	def validate_for_items(self, obj):
-		check_list, chk_dupl_itm=[],[]
+		items = []
 		for d in obj.get(obj.fname):
 			# validation for valid qty
 			if flt(d.qty) < 0 or (d.parenttype != 'Purchase Receipt' and not flt(d.qty)):
@@ -96,30 +96,10 @@
 				if item[0][1] != 'Yes' and item[0][2] != 'Yes':
 					frappe.throw(_("{0} must be a Purchased or Sub-Contracted Item in row {1}").format(d.item_code, d.idx))
 
-			# list criteria that should not repeat if item is stock item
-			e = [getattr(d, "schedule_date", None), d.item_code, d.description, d.warehouse, d.uom,
-				d.meta.get_field('prevdoc_docname') and d.prevdoc_docname or d.meta.get_field('sales_order_no') and d.sales_order_no or '',
-				d.meta.get_field('prevdoc_detail_docname') and d.prevdoc_detail_docname or '',
-				d.meta.get_field('batch_no') and d.batch_no or '']
-
-			# if is not stock item
-			f = [getattr(d, "schedule_date", None), d.item_code, d.description]
-
-			ch = frappe.db.sql("""select is_stock_item from `tabItem` where name = %s""", d.item_code)
-
-			if ch and ch[0][0] == 'Yes':
-				# check for same items
-				if e in check_list:
-					frappe.throw(_("Item {0} has been entered multiple times with same description or date or warehouse").format(d.item_code))
-				else:
-					check_list.append(e)
-
-			elif ch and ch[0][0] == 'No':
-				# check for same items
-				if f in chk_dupl_itm:
-					frappe.throw(_("Item {0} has been entered multiple times with same description or date").format(d.item_code))
-				else:
-					chk_dupl_itm.append(f)
+			items.append(cstr(d.item_code))
+			if items and len(items) != len(set(items)):
+				frappe.msgprint(_("Warning: Same item has been entered multiple times."))
+			
 
 	def check_for_stopped_status(self, doctype, docname):
 		stopped = frappe.db.sql("""select name from `tab%s` where name = %s and
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index f0bb937..efc4399 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -254,8 +254,10 @@
 					ifnull(sum(ifnull(fb.qty, 0)/ifnull(bom.quantity, 1)), 0) as qty,
 					fb.description, fb.stock_uom, it.min_order_qty
 					from `tabBOM Explosion Item` fb, `tabBOM` bom, `tabItem` it
-					where bom.name = fb.parent and it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No'
+					where bom.name = fb.parent and it.name = fb.item_code 
+					and ifnull(it.is_pro_applicable, 'No') = 'No'
 					and ifnull(it.is_sub_contracted_item, 'No') = 'No'
+					and ifnull(it.is_stock_item, 'No') = 'Yes'
 					and fb.docstatus<2 and bom.name=%s
 					group by item_code, stock_uom""", bom, as_dict=1):
 						bom_wise_item_details.setdefault(d.item_code, d)
@@ -268,6 +270,7 @@
 					from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
 					where bom.name = bom_item.parent and bom.name = %s and bom_item.docstatus < 2
 					and bom_item.item_code = item.name
+					and ifnull(item.is_stock_item, 'No') = 'Yes'
 					group by item_code""", bom, as_dict=1):
 						bom_wise_item_details.setdefault(d.item_code, d)