Additional GST related fields in Invoice and Sales/Purchase Register reort (#10405)

diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index c386450..ef233c6 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -325,23 +325,6 @@
 		}
 
 		this.frm.refresh_fields();
-	},
-
-	company_address: function() {
-		var me = this;
-		if(this.frm.doc.company_address) {
-			frappe.call({
-				method: "frappe.contacts.doctype.address.address.get_address_display",
-				args: {"address_dict": this.frm.doc.company_address },
-				callback: function(r) {
-					if(r.message) {
-						me.frm.set_value("company_address_display", r.message)
-					}
-				}
-			})
-		} else {
-			this.frm.set_value("company_address_display", "");
-		}
 	}
 });
 
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 5cb04c5..ba7ae32 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -79,7 +79,7 @@
 		out.shipping_address = get_address_display(out["shipping_address_name"])
 		out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name))
 
-	if doctype and doctype in ['Sales Invoice']:
+	if doctype and doctype in ['Delivery Note', 'Sales Invoice']:
 		out.update(get_company_address(company))
 		if out.company_address:
 			out.update(get_fetch_values(doctype, 'company_address', out.company_address))
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 10862f5..8f9948e 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -47,7 +47,7 @@
 
 		row += [
 			d.credit_to, d.mode_of_payment, d.project, d.company, d.purchase_order,
-			purchase_receipt, expense_account, d.qty, d.base_net_rate, d.base_net_amount
+			purchase_receipt, expense_account, d.qty, d.stock_uom, d.base_net_rate, d.base_net_amount
 		]
 
 		total_tax = 0
@@ -79,7 +79,8 @@
 		_("Mode of Payment") + ":Link/Mode of Payment:80", _("Project") + ":Link/Project:80",
 		_("Company") + ":Link/Company:100", _("Purchase Order") + ":Link/Purchase Order:100",
 		_("Purchase Receipt") + ":Link/Purchase Receipt:100", _("Expense Account") + ":Link/Account:140",
-		_("Qty") + ":Float:120", _("Rate") + ":Currency/currency:120", _("Amount") + ":Currency/currency:120"
+		_("Qty") + ":Float:120", _("Stock UOM") + "::100",
+		_("Rate") + ":Currency/currency:120", _("Amount") + ":Currency/currency:120"
 	]
 
 	return columns
@@ -109,8 +110,9 @@
 			pi_item.name, pi_item.parent, pi.posting_date, pi.credit_to, pi.company,
 			pi.supplier, pi.remarks, pi.base_net_total, pi_item.item_code, pi_item.item_name,
 			pi_item.item_group, pi_item.project, pi_item.purchase_order, pi_item.purchase_receipt,
-			pi_item.po_detail, pi_item.expense_account, pi_item.qty, pi_item.base_net_rate,
-			pi_item.base_net_amount, pi.supplier_name, pi.mode_of_payment {0}
+			pi_item.po_detail, pi_item.expense_account, pi_item.qty, pi_item.stock_uom, 
+			pi_item.base_net_rate, pi_item.base_net_amount,
+			pi.supplier_name, pi.mode_of_payment {0}
 		from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` pi_item
 		where pi.name = pi_item.parent and pi.docstatus = 1 %s %s
 		order by pi.posting_date desc, pi_item.item_code desc
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index 37707cd..30c545f 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -47,7 +47,8 @@
 		row += [
 			d.customer_group, d.debit_to, ", ".join(mode_of_payments.get(d.parent, [])),
 			d.territory, d.project, d.company, d.sales_order,
-			delivery_note, d.income_account, d.cost_center, d.qty, d.base_net_rate, d.base_net_amount
+			delivery_note, d.income_account, d.cost_center, d.qty, d.stock_uom,
+			d.base_net_rate, d.base_net_amount
 		]
 
 		total_tax = 0
@@ -79,7 +80,7 @@
 		_("Project") + ":Link/Project:80", _("Company") + ":Link/Company:100",
 		_("Sales Order") + ":Link/Sales Order:100", _("Delivery Note") + ":Link/Delivery Note:100",
 		_("Income Account") + ":Link/Account:140", _("Cost Center") + ":Link/Cost Center:140",
-		_("Qty") + ":Float:120",
+		_("Qty") + ":Float:120", _("Stock UOM") + "::100",
 		_("Rate") + ":Currency/currency:120",
 		_("Amount") + ":Currency/currency:120"
 	]
@@ -114,9 +115,9 @@
 			si_item.name, si_item.parent, si.posting_date, si.debit_to, si.project,
 			si.customer, si.remarks, si.territory, si.company, si.base_net_total,
 			si_item.item_code, si_item.item_name, si_item.item_group, si_item.sales_order,
-			si_item.delivery_note, si_item.income_account, si_item.cost_center, si_item.qty,
-			si_item.base_net_rate, si_item.base_net_amount, si.customer_name,
-			si.customer_group, si_item.so_detail, si.update_stock {0}
+			si_item.delivery_note, si_item.income_account, si_item.cost_center,
+			si_item.qty, si_item.stock_uom, si_item.base_net_rate, si_item.base_net_amount,
+			si.customer_name, si.customer_group, si_item.so_detail, si.update_stock {0}
 		from `tabSales Invoice` si, `tabSales Invoice Item` si_item
 		where si.name = si_item.parent and si.docstatus = 1 %s
 		order by si.posting_date desc, si_item.item_code desc
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 6b660e1..d781ec7 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -431,4 +431,5 @@
 erpnext.patches.v8_5.update_customer_group_in_POS_profile
 erpnext.patches.v8_6.update_timesheet_company_from_PO
 erpnext.patches.v8_6.set_write_permission_for_quotation_for_sales_manager
-erpnext.patches.v8_5.remove_project_type_property_setter
\ No newline at end of file
+erpnext.patches.v8_5.remove_project_type_property_setter
+erpnext.patches.v8_7.add_more_gst_fields
\ No newline at end of file
diff --git a/erpnext/patches/v8_7/__init__.py b/erpnext/patches/v8_7/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v8_7/__init__.py
diff --git a/erpnext/patches/v8_7/add_more_gst_fields.py b/erpnext/patches/v8_7/add_more_gst_fields.py
new file mode 100644
index 0000000..a1512ed
--- /dev/null
+++ b/erpnext/patches/v8_7/add_more_gst_fields.py
@@ -0,0 +1,9 @@
+import frappe
+from erpnext.regional.india.setup  import make_custom_fields
+
+def execute():
+	company = frappe.get_all('Company', filters = {'country': 'India'})
+	if not company:
+		return
+
+	make_custom_fields()
\ No newline at end of file
diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py
index 7a7e937..0c59ba0 100644
--- a/erpnext/regional/india/setup.py
+++ b/erpnext/regional/india/setup.py
@@ -81,6 +81,47 @@
 def make_custom_fields():
 	hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC',
 		fieldtype='Data', options='item_code.gst_hsn_code', insert_after='description', print_hide=1)
+	invoice_gst_fields = [
+		dict(fieldname='gst_section', label='GST Details', fieldtype='Section Break',
+			insert_after='select_print_heading', print_hide=1, collapsible=1),
+		dict(fieldname='invoice_copy', label='Invoice Copy',
+			fieldtype='Select', insert_after='gst_section', print_hide=1, allow_on_submit=1,
+			options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'),
+		dict(fieldname='reverse_charge', label='Reverse Charge',
+			fieldtype='Select', insert_after='invoice_copy', print_hide=1,
+			options='Y\nN', default='N'),
+		dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='reverse_charge'),
+		dict(fieldname='invoice_type', label='Invoice Type',
+			fieldtype='Select', insert_after='reverse_charge', print_hide=1,
+			options='Regular\nSEZ\nExport\nDeemed Export', default='Regular'),
+		dict(fieldname='export_type', label='Export Type',
+			fieldtype='Select', insert_after='invoice_type', print_hide=1,
+			depends_on='eval:in_list(["SEZ", "Export", "Deemed Export"], doc.invoice_type)',
+			options='\nWith Payment of Tax\nWithout Payment of Tax'),
+		dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN',
+			fieldtype='Data', insert_after='export_type', print_hide=1)
+	]
+	
+	purchase_invoice_gst_fields = [
+			dict(fieldname='supplier_gstin', label='Supplier GSTIN',
+				fieldtype='Data', insert_after='supplier_address',
+				options='supplier_address.gstin', print_hide=1),
+			dict(fieldname='company_gstin', label='Company GSTIN',
+				fieldtype='Data', insert_after='shipping_address',
+				options='shipping_address.gstin', print_hide=1)
+		]
+		
+	sales_invoice_gst_fields = [
+			dict(fieldname='customer_gstin', label='Customer GSTIN',
+				fieldtype='Data', insert_after='shipping_address',
+				options='shipping_address_name.gstin', print_hide=1),
+			dict(fieldname='place_of_supply', label='Place of Supply',
+				fieldtype='Data', insert_after='customer_gstin', print_hide=1,
+				options='shipping_address_name.gst_state_number', read_only=1),
+			dict(fieldname='company_gstin', label='Company GSTIN',
+				fieldtype='Data', insert_after='company_address',
+				options='company_address.gstin', print_hide=1)
+		]
 	
 	custom_fields = {
 		'Address': [
@@ -91,25 +132,9 @@
 			dict(fieldname='gst_state_number', label='GST State Number',
 				fieldtype='Int', insert_after='gst_state', read_only=1),
 		],
-		'Purchase Invoice': [
-			dict(fieldname='supplier_gstin', label='Supplier GSTIN',
-				fieldtype='Data', insert_after='supplier_address',
-				options='supplier_address.gstin', print_hide=1),
-			dict(fieldname='company_gstin', label='Company GSTIN',
-				fieldtype='Data', insert_after='shipping_address',
-				options='shipping_address.gstin', print_hide=1),
-		],
-		'Sales Invoice': [
-			dict(fieldname='customer_gstin', label='Customer GSTIN',
-				fieldtype='Data', insert_after='shipping_address',
-				options='shipping_address_name.gstin', print_hide=1),
-			dict(fieldname='company_gstin', label='Company GSTIN',
-				fieldtype='Data', insert_after='company_address',
-				options='company_address.gstin', print_hide=1),
-			dict(fieldname='invoice_copy', label='Invoice Copy',
-				fieldtype='Select', insert_after='select_print_heading', print_hide=1, allow_on_submit=1,
-				options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier')
-		],
+		'Purchase Invoice': purchase_invoice_gst_fields + invoice_gst_fields,
+		'Sales Invoice': sales_invoice_gst_fields + invoice_gst_fields,
+		"Delivery Note": sales_invoice_gst_fields,
 		'Item': [
 			dict(fieldname='gst_hsn_code', label='HSN/SAC',
 				fieldtype='Link', options='GST HSN Code', insert_after='item_group'),
diff --git a/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py b/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py
index d88febc..1d94c97 100644
--- a/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py
+++ b/erpnext/regional/report/gst_itemised_purchase_register/gst_itemised_purchase_register.py
@@ -9,9 +9,17 @@
 	return _execute(filters, additional_table_columns=[
 		dict(fieldtype='Data', label='Supplier GSTIN', width=120),
 		dict(fieldtype='Data', label='Company GSTIN', width=120),
+		dict(fieldtype='Data', label='Reverse Charge', width=120),
+		dict(fieldtype='Data', label='Invoice Type', width=120),
+		dict(fieldtype='Data', label='Export Type', width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130),
 		dict(fieldtype='Data', label='HSN Code', width=120)
 	], additional_query_columns=[
 		'supplier_gstin',
 		'company_gstin',
+		'reverse_charge',
+		'invoice_type',
+		'export_type',
+		'ecommerce_gstin',
 		'gst_hsn_code'
 	])
diff --git a/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py b/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py
index 14ddff3..40bbae8 100644
--- a/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py
+++ b/erpnext/regional/report/gst_itemised_sales_register/gst_itemised_sales_register.py
@@ -9,9 +9,19 @@
 	return _execute(filters, additional_table_columns=[
 		dict(fieldtype='Data', label='Customer GSTIN', width=120),
 		dict(fieldtype='Data', label='Company GSTIN', width=120),
+		dict(fieldtype='Data', label='Place of Supply', width=120),
+		dict(fieldtype='Data', label='Reverse Charge', width=120),
+		dict(fieldtype='Data', label='Invoice Type', width=120),
+		dict(fieldtype='Data', label='Export Type', width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130),
 		dict(fieldtype='Data', label='HSN Code', width=120)
 	], additional_query_columns=[
 		'customer_gstin',
 		'company_gstin',
+		'place_of_supply',
+		'reverse_charge',
+		'invoice_type',
+		'export_type',
+		'ecommerce_gstin',
 		'gst_hsn_code'
 	])
diff --git a/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py b/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py
index 59687d0..8d479a9 100644
--- a/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py
+++ b/erpnext/regional/report/gst_purchase_register/gst_purchase_register.py
@@ -8,9 +8,17 @@
 def execute(filters=None):
 	return _execute(filters, additional_table_columns=[
 		dict(fieldtype='Data', label='Supplier GSTIN', width=120),
-		dict(fieldtype='Data', label='Company GSTIN', width=120)
+		dict(fieldtype='Data', label='Company GSTIN', width=120),
+		dict(fieldtype='Data', label='Reverse Charge', width=120),
+		dict(fieldtype='Data', label='Invoice Type', width=120),
+		dict(fieldtype='Data', label='Export Type', width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130)
 	], additional_query_columns=[
 		'supplier_gstin',
-		'company_gstin'
+		'company_gstin',
+		'reverse_charge',
+		'invoice_type',
+		'export_type',
+		'ecommerce_gstin'
 	])
 
diff --git a/erpnext/regional/report/gst_sales_register/gst_sales_register.py b/erpnext/regional/report/gst_sales_register/gst_sales_register.py
index 440594a..7f6f809 100644
--- a/erpnext/regional/report/gst_sales_register/gst_sales_register.py
+++ b/erpnext/regional/report/gst_sales_register/gst_sales_register.py
@@ -8,8 +8,18 @@
 def execute(filters=None):
 	return _execute(filters, additional_table_columns=[
 		dict(fieldtype='Data', label='Customer GSTIN', width=120),
-		dict(fieldtype='Data', label='Company GSTIN', width=120)
+		dict(fieldtype='Data', label='Company GSTIN', width=120),
+		dict(fieldtype='Data', label='Place of Supply', width=120),
+		dict(fieldtype='Data', label='Reverse Charge', width=120),
+		dict(fieldtype='Data', label='Invoice Type', width=120),
+		dict(fieldtype='Data', label='Export Type', width=120),
+		dict(fieldtype='Data', label='E-Commerce GSTIN', width=130)
 	], additional_query_columns=[
 		'customer_gstin',
-		'company_gstin'
+		'company_gstin',
+		'place_of_supply',
+		'reverse_charge',
+		'invoice_type',
+		'export_type',
+		'ecommerce_gstin'
 	])
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index b16169b..396b1c2 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -466,6 +466,11 @@
 		target.ignore_pricing_rule = 1
 		target.run_method("set_missing_values")
 		target.run_method("calculate_taxes_and_totals")
+		
+		# set company address
+		target.update(get_company_address(target.company))
+		if target.company_address:
+			target.update(get_fetch_values("Delivery Note", 'company_address', target.company_address))
 
 	def update_item(source, target, source_parent):
 		target.base_amount = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.base_rate)
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 6a84d0e..e9671c8 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -326,6 +326,23 @@
 			this.calculate_taxes_and_totals();
 			cur_frm.refresh_fields();
 		}
+	},
+
+	company_address: function() {
+		var me = this;
+		if(this.frm.doc.company_address) {
+			frappe.call({
+				method: "frappe.contacts.doctype.address.address.get_address_display",
+				args: {"address_dict": this.frm.doc.company_address },
+				callback: function(r) {
+					if(r.message) {
+						me.frm.set_value("company_address_display", r.message)
+					}
+				}
+			})
+		} else {
+			this.frm.set_value("company_address_display", "");
+		}
 	}
 });
 
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 345750f..4477c1d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -860,22 +860,22 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "", 
-   "fieldname": "customer_group", 
+   "fieldname": "company_address", 
    "fieldtype": "Link", 
-   "hidden": 1, 
+   "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Customer Group", 
+   "label": "Company Address Name", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Customer Group", 
+   "options": "Address", 
    "permlevel": 0, 
-   "print_hide": 1, 
+   "precision": "", 
+   "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
@@ -891,9 +891,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "", 
-   "fieldname": "territory", 
-   "fieldtype": "Link", 
+   "fieldname": "company_address_display", 
+   "fieldtype": "Small Text", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -901,12 +900,12 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Territory", 
+   "label": "Company Address", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Territory", 
    "permlevel": 0, 
-   "print_hide": 1, 
+   "precision": "", 
+   "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
@@ -2761,6 +2760,68 @@
    "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "description": "", 
+   "fieldname": "customer_group", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Customer Group", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Customer Group", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "description": "", 
+   "fieldname": "territory", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Territory", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Territory", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
    "collapsible": 1, 
    "columns": 0, 
    "fieldname": "printing_details", 
@@ -3426,7 +3487,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-07-19 13:48:09.630820", 
+ "modified": "2017-08-09 15:44:14.253457", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note",