Merge pull request #9669 from rohitwaghchaure/sales_invoice_serial_no_revert

Revert sales invoice serial no issues
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index dc547e3..68b5d46 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -343,12 +343,12 @@
 		}
 	}
 
-	/*
+
 	var item_fields_stock = ['batch_no', 'actual_batch_qty', 'actual_qty', 'expense_account',
 		'warehouse', 'expense_account', 'quality_inspection']
 	cur_frm.fields_dict['items'].grid.set_column_disp(item_fields_stock,
 		(cint(doc.update_stock)==1 || cint(doc.is_return)==1 ? true : false));
-	*/
+
 
 	// India related fields
 	if (frappe.boot.sysdefaults.country == 'India') unhide_field(['c_form_applicable', 'c_form_no']);
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index c545ee1..282425d 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -132,8 +132,7 @@
 			self.update_billing_status_for_zero_amount_refdoc("Sales Order")
 			self.check_credit_limit()
 
-		if self.update_stock:
-			self.update_serial_no()
+		self.update_serial_no()
 
 		if not cint(self.is_pos) == 1 and not self.is_return:
 			self.update_against_document_in_jv()
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 59af618..5810c69 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -11,6 +11,7 @@
  "doctype": "DocType", 
  "document_type": "Document", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_bulk_edit": 0, 
@@ -1423,7 +1424,7 @@
    "collapsible": 1, 
    "collapsible_depends_on": "eval:doc.serial_no || doc.batch_no", 
    "columns": 0, 
-   "depends_on": "", 
+   "depends_on": "eval: parent.update_stock", 
    "fieldname": "warehouse_and_reference", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -2165,7 +2166,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-07-03 19:34:14.820285", 
+ "modified": "2017-07-06 17:54:03.347700", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice Item", 
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 13b7299..0cf0f7b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -413,3 +413,4 @@
 erpnext.patches.v8_1.removed_roles_from_gst_report_non_indian_account
 erpnext.patches.v8_1.gst_fixes #2017-07-06
 erpnext.patches.v8_0.update_production_orders
+erpnext.patches.v8_1.remove_sales_invoice_from_returned_serial_no
\ No newline at end of file
diff --git a/erpnext/patches/v8_1/remove_sales_invoice_from_returned_serial_no.py b/erpnext/patches/v8_1/remove_sales_invoice_from_returned_serial_no.py
new file mode 100644
index 0000000..3962f8f
--- /dev/null
+++ b/erpnext/patches/v8_1/remove_sales_invoice_from_returned_serial_no.py
@@ -0,0 +1,18 @@
+# Copyright (c) 2017, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	frappe.reload_doctype("Serial No")
+
+	frappe.db.sql("""
+		update
+			`tabSerial No`
+		set
+			sales_invoice = NULL
+		where
+			sales_invoice in (select return_against from
+				`tabSales Invoice` where docstatus =1 and is_return=1)
+			and sales_invoice is not null and sales_invoice !='' """)
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index 19d3f47..b168631 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -1138,7 +1138,7 @@
    "in_standard_filter": 0, 
    "label": "Has Batch No", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "oldfieldname": "has_batch_no", 
    "oldfieldtype": "Select", 
    "options": "", 
@@ -1234,7 +1234,7 @@
    "in_standard_filter": 0, 
    "label": "Has Serial No", 
    "length": 0, 
-   "no_copy": 0, 
+   "no_copy": 1, 
    "oldfieldname": "has_serial_no", 
    "oldfieldtype": "Select", 
    "options": "", 
@@ -3143,7 +3143,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 1, 
- "modified": "2017-06-13 14:29:03.003680", 
+ "modified": "2017-07-06 18:28:36.645217", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item", 
@@ -3320,4 +3320,4 @@
  "title_field": "item_name", 
  "track_changes": 1, 
  "track_seen": 0
-}
+}
\ No newline at end of file