Test Case:
stock entry submit and cancel
Sandbox created for maintaining testdata and testcases
diff --git a/erpnext/sandbox/__init__.py b/erpnext/sandbox/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/sandbox/__init__.py
diff --git a/erpnext/sandbox/test_stock_entry.py b/erpnext/sandbox/test_stock_entry.py
new file mode 100644
index 0000000..273c442
--- /dev/null
+++ b/erpnext/sandbox/test_stock_entry.py
@@ -0,0 +1,110 @@
+import unittest
+
+import webnotes
+import webnotes.profile
+webnotes.user = webnotes.profile.Profile()
+
+
+from webnotes.model.doc import Document
+from webnotes.model.code import get_obj
+from webnotes.utils import cstr, flt
+sql = webnotes.conn.sql
+
+from sandbox.testdata.masters import *
+from sandbox.testdata import stock_entry
+#----------------------------------------------------------
+
+class TestStockEntry(unittest.TestCase):
+	def setUp(self):
+		print "====================================="
+		webnotes.conn.begin()
+		
+		create_master_records()
+		print 'Master Data Created'
+		
+		for each in stock_entry.mr:
+			each.save(1)
+
+		for t in stock_entry.mr[1:]:
+			sql("update `tabStock Entry Detail` set parent = '%s' where name = '%s'" % (stock_entry.mr[0].name, t.name))
+		print "Stock Entry Created"
+		
+	
+	#===========================================================================
+	def test_stock_entry_onsubmit(self):
+		print "Test Case: Stock Entry submission"
+		self.submit_stock_entry()
+		
+		expected_sle = (('Stock Entry', stock_entry.mr[0].name, 10, 10, 100, 'No'),)
+		self.check_sle(expected_sle)
+		
+		self.check_bin_qty(10)
+		self.check_serial_no('submit', 10)
+		
+	#===========================================================================
+	def test_stock_entry_oncancel(self):
+		print "Test Case: Stock Entry Cancellation"
+		self.cancel_stock_entry()
+		
+		expected_sle = (
+			('Stock Entry', stock_entry.mr[0].name, 10, 10, 100, 'Yes'), 
+			('Stock Entry', stock_entry.mr[0].name, -10, None, None, 'Yes'),
+		)
+		self.check_sle(expected_sle)
+		
+		self.check_bin_qty(0)		
+		self.check_serial_no('cancel', 10)
+		
+		
+	#===========================================================================
+	def submit_stock_entry(self):
+		ste1 = get_obj('Stock Entry', stock_entry.mr[0].name, with_children=1)
+		ste1.validate()
+		ste1.on_submit()
+		
+		ste1.doc.docstatus = 1
+		ste1.doc.save()
+		
+		print "Stock Entry Submitted"
+		
+			
+	#===========================================================================
+	def cancel_stock_entry(self):
+		self.submit_stock_entry()
+		
+		ste1 = get_obj('Stock Entry', stock_entry.mr[0].name, with_children=1)
+		ste1.on_cancel()
+		
+		ste1.doc.cancel_reason = "testing"
+		ste1.doc.docstatus = 2
+		ste1.doc.save()
+		
+		print "Stock Entry Cancelled"
+		
+	#===========================================================================
+	def check_sle(self, expected):
+		print "Checking stock ledger entry........."
+		sle = sql("select voucher_type, voucher_no, actual_qty, bin_aqat, valuation_rate, is_cancelled from `tabStock Ledger Entry` where item_code = 'it' and warehouse = 'wh1'")
+		self.assertTrue(sle == expected)
+
+	#===========================================================================
+	def check_bin_qty(self, expected_qty):
+		print "Checking Bin qty........."
+		bin_qty = sql("select actual_qty from tabBin where item_code = 'it' and warehouse = 'wh1'")
+		self.assertTrue(bin_qty[0][0] == expected_qty)
+		
+	#===========================================================================
+	def check_serial_no(self, action, cnt):
+		print "Checking serial nos........"
+		if action == 'submit':
+			status, wh, docstatus = 'In Store', 'wh1', 0
+		else:
+			status, wh, docstatus = 'Not in Use', '', 2
+
+		ser = sql("select count(name) from `tabSerial No` where item_code = 'it' and warehouse = '%s' and status = '%s' and docstatus = %s" % (wh, status, docstatus))
+
+		self.assertTrue(ser[0][0] == cnt)
+	
+	#===========================================================================
+	def tearDown(self):
+		webnotes.conn.rollback()
diff --git a/erpnext/sandbox/testdata/__init__.py b/erpnext/sandbox/testdata/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/sandbox/testdata/__init__.py
diff --git a/erpnext/sandbox/testdata/masters.py b/erpnext/sandbox/testdata/masters.py
new file mode 100644
index 0000000..7f2d67c
--- /dev/null
+++ b/erpnext/sandbox/testdata/masters.py
@@ -0,0 +1,282 @@
+"""
+	All master data in one place, can be created by 1 function call
+
+"""
+
+import webnotes
+from webnotes.model.doc import Document
+
+
+master_groups = {
+	# Company
+	#----------------------------------
+	'company': Document(
+		fielddata={
+			'doctype':'Company',
+			'abbr': 'co',
+			'company_name' : 'comp',
+			'name': 'comp'
+		}
+	),
+	
+	# Customer Group
+	#----------------------------------
+	'customer_group':  Document(
+		fielddata={
+			'doctype':'Customer Group',
+			'customer_group_name' : 'cg',
+			'name': 'cg',
+			'is_group': 'No',
+			'parent_customer_group':'', 
+			'lft' : 1,
+			'rgt': 2
+		}
+	),
+	
+	# Item Group
+	#----------------------------------
+	'item_group': Document(
+		fielddata = {
+			'doctype': 'Item Group',
+			'item_group_name': 'ig',
+			'lft': 1,
+			'rgt': 2,
+			'parent_item_group' : '',
+			'is_group': 'No',
+			'name': 'ig'
+		}
+	),
+	
+	# Warehouse Type
+	#-----------------------------
+	'warehouse_type' : Document(
+		fielddata = {
+			'doctype' : 'Warehouse Type',
+			'name': 'normal',
+			'warehouse_type' : 'normal'
+		}
+	),
+	
+	# Supplier Type
+	#-----------------------------
+	'supplier_type' : Document(
+		fielddata = {
+			'doctype': 'Supplier Type',
+			'supplier_type': 'stype'
+		}
+	)
+
+}
+
+
+main_masters = {
+	# Customer
+	#----------------------------------
+	'customer': Document(
+		fielddata={
+			'doctype':'Customer',
+			'docstatus':0,
+			'customer_name' : 'cust',
+			'company' : 'comp',
+			'customer_group' : '',
+			'name': 'cust'
+		}
+	),
+
+
+	# Supplier
+	#----------------------------------
+	'supplier': Document(
+		fielddata = {
+			'doctype': 'Supplier',
+			'supplier_name': 'supp',
+			'name': 'supp',	
+			'supplier_type' : 'stype'
+		}
+	),
+	
+	# Customer Account
+	#----------------------------------
+	'customer_acc': Document(
+		fielddata={
+			'doctype':'Account',
+			'docstatus':0,
+			'account_name' : 'cust',
+			'debit_or_credit': 'Debit',
+			'company' : 'comp',
+			'lft': 1,
+			'rgt': 2,
+			'group_or_ledger' : 'Ledger',
+			'is_pl_account': 'No',
+			'name' : 'cust - co'
+		}
+	),
+	
+	# Customer Account
+	#----------------------------------
+	'supplier_acc': Document(
+		fielddata={
+			'doctype':'Account',
+			'docstatus':0,
+			'account_name' : 'supp',
+			'debit_or_credit': 'Credit',
+			'company' : 'comp',
+			'lft': 5,
+			'rgt': 6,
+			'group_or_ledger' : 'Ledger',
+			'is_pl_account': 'No',
+			'name' : 'supp - co'
+		}
+	),	
+
+	# Bank Account
+	#----------------------------------
+	'bank_acc': Document(
+		fielddata={
+			'doctype':'Account',
+			'docstatus':0,
+			'account_name' : 'icici',
+			'parent_account': '',
+			'debit_or_credit': 'Debit',
+			'company' : 'comp',
+			'lft': 3,
+			'rgt': 4,
+			'group_or_ledger' : 'Ledger',
+			'is_pl_account': 'No',
+			'name' : 'icici - co'
+		}
+	),
+
+	# Income Account
+	#----------------------------------
+	'income_acc': Document(
+		fielddata={
+			'doctype':'Account',
+			'docstatus':0,
+			'account_name' : 'income',
+			'debit_or_credit': 'Credit',
+			'company' : 'comp',
+			'lft': 7,
+			'rgt': 8,
+			'group_or_ledger' : 'Ledger',
+			'is_pl_account': 'Yes',
+			'name' : 'income - co'
+		}
+	),
+	
+	# Expense Account
+	#----------------------------------
+	'expense_acc': Document(
+		fielddata={
+			'doctype':'Account',
+			'docstatus':0,
+			'account_name' : 'expense',
+			'debit_or_credit': 'Debit',
+			'company' : 'comp',
+			'lft': 9,
+			'rgt': 10,
+			'group_or_ledger' : 'Ledger',
+			'is_pl_account': 'Yes',
+			'name' : 'expense - co'
+		}
+	),
+
+	# Cost Center
+	#----------------------------------
+	'cost_center': Document(
+		fielddata={
+			'doctype':'Cost Center',
+			'docstatus':0,
+			'cost_center_name' : 'cc',
+			'lft': 1,
+			'rgt': 2,
+			'group_or_ledger' : 'Ledger',
+			'name' : 'cc'
+		}
+	),
+
+	# Item
+	#----------------------------------
+	# Stock item / non-serialized
+
+	'item': [
+		Document(
+			fielddata = {
+				'doctype': 'Item',
+				'docstatus': 0,
+				'name': 'it',
+				'item_name': 'it',
+				'item_code': 'it',
+				'item_group': 'ig',
+				'is_stock_item': 'Yes',
+				'has_serial_no': 'Yes',
+				'stock_uom': 'Nos',
+				'is_sales_item': 'Yes',
+				'is_purchase_item': 'Yes',
+				'is_service_item': 'No',
+				'is_sub_contracted_item': 'No',
+				'is_pro_applicable': 'Yes',
+				'is_manufactured_item': 'Yes'		
+			}
+		),
+		Document(
+			fielddata = {
+				'doctype': 'Ref Rate Detail',
+				'parentfield': 'ref_rate_details',
+				'parenttype': 'Item',
+				'parent' : 'it',
+				'price_list_name': 'pl',
+				'ref_currency': 'INR',
+				'ref_rate': 100
+			}
+		),
+		Document(
+			fielddata = {
+				'doctype': 'Item Tax',
+				'parentfield': 'item_tax',
+				'parenttype': 'Item',
+				'parent' : 'it',
+				'tax_type' : 'Tax1',
+				'tax_rate': 10
+			}
+		)
+	],
+	
+	# Warehouse
+	#-----------------------------
+	'warehouse': [
+		Document(
+			fielddata = {
+				'doctype': 'Warehouse',
+				'name' : 'wh1',
+				'warehouse_name' : 'wh1',
+				'warehouse_type': 'normal',
+				'company': 'comp'
+			}
+		),
+		Document(
+			fielddata = {
+				'doctype': 'Warehouse',
+				'name' : 'wh2',
+				'warehouse_name' : 'wh2',
+				'warehouse_type': 'normal',
+				'company': 'comp'
+			}
+		)
+	]
+}
+
+
+
+# Save all master records
+#----------------------------------
+def create_master_records():
+	for m in master_groups.keys():
+		master_groups[m].save(1)
+
+	for m in main_masters.keys():
+		if type(main_masters[m]) == list:
+			for each in main_masters[m]:
+				each.save(1)
+		else:
+			main_masters[m].save(1)
diff --git a/erpnext/sandbox/testdata/stock_entry.py b/erpnext/sandbox/testdata/stock_entry.py
new file mode 100644
index 0000000..e2d1d71
--- /dev/null
+++ b/erpnext/sandbox/testdata/stock_entry.py
@@ -0,0 +1,32 @@
+from webnotes.model.doc import Document
+
+mr = [
+	Document(
+		fielddata = {
+			'doctype': 'Stock Entry',
+			'posting_date': '2011-09-01',
+			'transfer_date': '2011-09-01',
+			'posting_time': '12:00',
+			'company': 'comp',
+			'fiscal_year' : '2011-2012',
+			'purpose': 'Material Receipt',
+			'name': 'ste'
+		}
+	),
+	Document(
+		fielddata  ={
+			'doctype': 'Stock Entry Detail',
+			'parenttype': 'Stock Entry',
+			'parentfield' : 'mtn_details',
+			'parent' : 'ste',
+			'item_code' : 'it',
+			't_warehouse' : 'wh1',
+			'qty' : 10,
+			'transfer_qty' : 10,
+			'incoming_rate': 100,
+			'stock_uom': 'Nos',
+			'conversion_factor': 1,
+			'serial_no': 'srno1, srno2, srno3, srno4, srno5, srno6, srno7, srno8, srno9, srno10'	
+		}
+	)
+]