Merge pull request #2195 from neilLasrado/manufacture-and-repack

[fix] Issue #2183 - Manufacturing and repack seprated in stock entry
diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py
index 365cb38..8b6aed7 100644
--- a/erpnext/stock/doctype/batch/batch.py
+++ b/erpnext/stock/doctype/batch/batch.py
@@ -3,8 +3,15 @@
 
 from __future__ import unicode_literals
 import frappe
-
+from frappe import _
 from frappe.model.document import Document
 
 class Batch(Document):
-	pass
\ No newline at end of file
+	
+	def validate(self):
+		self.item_has_batch_enabled()
+
+	def item_has_batch_enabled(self):
+		has_batch_no = frappe.db.get_value("Item",self.item,"has_batch_no")
+		if has_batch_no =='No':
+			frappe.throw(_("The selected item cannot have Batch"))
\ No newline at end of file
diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py
new file mode 100644
index 0000000..d664721
--- /dev/null
+++ b/erpnext/stock/doctype/batch/test_batch.py
@@ -0,0 +1,14 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+from frappe.exceptions import ValidationError
+import unittest
+
+class TestBatch(unittest.TestCase):
+	def test_item_has_batch_enabled(self):
+		self.assertRaises(ValidationError, frappe.get_doc({
+			"doctype": "Batch",
+			"name": "_test Batch",
+			"item": "_Test Item"
+		}).save)
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index c80d19e..fce8dfa 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -19,7 +19,7 @@
 	cur_frm.cscript.edit_prices_button();
 
 	if (!doc.__islocal && doc.is_stock_item == 'Yes') {
-		cur_frm.toggle_enable(['has_serial_no', 'is_stock_item', 'valuation_method'],
+		cur_frm.toggle_enable(['has_serial_no', 'is_stock_item', 'valuation_method', 'has_batch_no'],
 			(doc.__onload && doc.__onload.sle_exists=="exists") ? false : true);
 	}
 
@@ -185,4 +185,4 @@
 	else {
 		msgprint(__("You may need to update: {0}", [frappe.meta.get_docfield(cur_frm.doc.doctype, "description_html").label]));
 	}
-}
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 17fe0ae..b8a3190 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -187,13 +187,14 @@
 	def cant_change(self):
 		if not self.get("__islocal"):
 			vals = frappe.db.get_value("Item", self.name,
-				["has_serial_no", "is_stock_item", "valuation_method"], as_dict=True)
+				["has_serial_no", "is_stock_item", "valuation_method", "has_batch_no"], as_dict=True)
 
 			if vals and ((self.is_stock_item == "No" and vals.is_stock_item == "Yes") or
 				vals.has_serial_no != self.has_serial_no or
+				vals.has_batch_no != self.has_batch_no or
 				cstr(vals.valuation_method) != cstr(self.valuation_method)):
 					if self.check_if_sle_exists() == "exists":
-						frappe.throw(_("As there are existing stock transactions for this item, you can not change the values of 'Has Serial No', 'Is Stock Item' and 'Valuation Method'"))
+						frappe.throw(_("As there are existing stock transactions for this item, you can not change the values of 'Has Serial No', 'Has Batch No', 'Is Stock Item' and 'Valuation Method'"))
 
 	def validate_item_type_for_reorder(self):
 		if self.re_order_level or len(self.get("item_reorder", {"material_request_type": "Purchase"})):
diff --git a/erpnext/stock/doctype/item_price/test_item_price.py b/erpnext/stock/doctype/item_price/test_item_price.py
index 1a430bf..7106a53 100644
--- a/erpnext/stock/doctype/item_price/test_item_price.py
+++ b/erpnext/stock/doctype/item_price/test_item_price.py
@@ -9,6 +9,6 @@
 	def test_duplicate_item(self):
 		from erpnext.stock.doctype.item_price.item_price import ItemPriceDuplicateItem
 		doc = frappe.copy_doc(test_records[0])
-		self.assertRaises(ItemPriceDuplicateItem, doc.insert)
+		self.assertRaises(ItemPriceDuplicateItem, doc.save)
 
 test_records = frappe.get_test_records('Item Price')
\ No newline at end of file