Merge branch 'develop' into dev-serial-no-statuses
diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json
index 48df8a1..64efc27 100644
--- a/erpnext/accounts/doctype/account/account.json
+++ b/erpnext/accounts/doctype/account/account.json
@@ -188,7 +188,6 @@
    "label": "Include in gross"
   },
   {
-   "bold": 1,
    "default": "0",
    "fieldname": "disabled",
    "fieldtype": "Check",
@@ -197,7 +196,7 @@
  ],
  "icon": "fa fa-money",
  "idx": 1,
- "modified": "2019-08-23 03:40:58.441295",
+ "modified": "2019-10-10 19:10:02.967554",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Account",
diff --git a/erpnext/accounts/doctype/coupon_code/__init__.py b/erpnext/accounts/doctype/coupon_code/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/accounts/doctype/coupon_code/__init__.py
diff --git a/erpnext/accounts/doctype/coupon_code/coupon_code.js b/erpnext/accounts/doctype/coupon_code/coupon_code.js
new file mode 100644
index 0000000..0bf097f
--- /dev/null
+++ b/erpnext/accounts/doctype/coupon_code/coupon_code.js
@@ -0,0 +1,35 @@
+// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Coupon Code', {
+	coupon_name:function(frm){
+		if (frm.doc.__islocal===1) {
+			frm.trigger("make_coupon_code");
+		}
+	},
+	coupon_type:function(frm){
+		if (frm.doc.__islocal===1) {
+			frm.trigger("make_coupon_code");
+		}
+	},
+	make_coupon_code: function(frm) {
+		var coupon_name=frm.doc.coupon_name;
+		var coupon_code;
+		if (frm.doc.coupon_type=='Gift Card') {
+			coupon_code=Math.random().toString(12).substring(2, 12).toUpperCase();
+		}
+		else if(frm.doc.coupon_type=='Promotional'){
+			coupon_name=coupon_name.replace(/\s/g,'');
+			coupon_code=coupon_name.toUpperCase().slice(0,8);
+		}
+		frm.doc.coupon_code=coupon_code;
+		frm.refresh_field('coupon_code');
+	},
+	refresh: function(frm) {
+		if (frm.doc.pricing_rule) {
+			frm.add_custom_button(__("Add/Edit Coupon Conditions"), function(){
+				frappe.set_route("Form", "Pricing Rule", frm.doc.pricing_rule);
+			});
+		}
+	}
+});
diff --git a/erpnext/accounts/doctype/coupon_code/coupon_code.json b/erpnext/accounts/doctype/coupon_code/coupon_code.json
new file mode 100644
index 0000000..fafc635
--- /dev/null
+++ b/erpnext/accounts/doctype/coupon_code/coupon_code.json
@@ -0,0 +1,175 @@
+{
+ "allow_import": 1,
+ "autoname": "field:coupon_name",
+ "creation": "2018-01-22 14:34:39.701832",
+ "doctype": "DocType",
+ "document_type": "Other",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "coupon_name",
+  "coupon_type",
+  "customer",
+  "column_break_4",
+  "coupon_code",
+  "pricing_rule",
+  "uses",
+  "valid_from",
+  "valid_upto",
+  "maximum_use",
+  "used",
+  "column_break_11",
+  "description",
+  "amended_from"
+ ],
+ "fields": [
+  {
+   "fieldname": "coupon_name",
+   "fieldtype": "Data",
+   "label": "Coupon Name",
+   "reqd": 1,
+   "unique": 1
+  },
+  {
+   "fieldname": "coupon_type",
+   "fieldtype": "Select",
+   "in_list_view": 1,
+   "label": "Coupon Type",
+   "options": "Promotional\nGift Card",
+   "reqd": 1
+  },
+  {
+   "depends_on": "eval: doc.coupon_type == \"Gift Card\"",
+   "fieldname": "customer",
+   "fieldtype": "Link",
+   "label": "Customer",
+   "options": "Customer"
+  },
+  {
+   "fieldname": "column_break_4",
+   "fieldtype": "Column Break"
+  },
+  {
+   "description": "To be used to get discount",
+   "fieldname": "coupon_code",
+   "fieldtype": "Data",
+   "label": "Coupon Code",
+   "no_copy": 1,
+   "set_only_once": 1,
+   "unique": 1
+  },
+  {
+   "fieldname": "pricing_rule",
+   "fieldtype": "Link",
+   "label": "Pricing Rule",
+   "options": "Pricing Rule"
+  },
+  {
+   "fieldname": "uses",
+   "fieldtype": "Section Break",
+   "label": "Uses"
+  },
+  {
+   "fieldname": "valid_from",
+   "fieldtype": "Date",
+   "in_list_view": 1,
+   "label": "Valid From"
+  },
+  {
+   "fieldname": "valid_upto",
+   "fieldtype": "Date",
+   "label": "Valid Upto"
+  },
+  {
+   "depends_on": "eval: doc.coupon_type == \"Promotional\"",
+   "fieldname": "maximum_use",
+   "fieldtype": "Int",
+   "label": "Maximum Use"
+  },
+  {
+   "default": "0",
+   "fieldname": "used",
+   "fieldtype": "Int",
+   "label": "Used",
+   "no_copy": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_11",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "description",
+   "fieldtype": "Text Editor",
+   "label": "Coupon Description"
+  },
+  {
+   "fieldname": "amended_from",
+   "fieldtype": "Link",
+   "label": "Amended From",
+   "no_copy": 1,
+   "options": "Coupon Code",
+   "print_hide": 1,
+   "read_only": 1
+  }
+ ],
+ "modified": "2019-10-15 14:12:22.686986",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Coupon Code",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Accounts User",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Sales Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Website Manager",
+   "share": 1,
+   "write": 1
+  }
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "title_field": "coupon_name",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/coupon_code/coupon_code.py b/erpnext/accounts/doctype/coupon_code/coupon_code.py
new file mode 100644
index 0000000..7829c93
--- /dev/null
+++ b/erpnext/accounts/doctype/coupon_code/coupon_code.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.model.document import Document
+from frappe.utils import (strip)
+class CouponCode(Document):
+	def autoname(self):
+		self.coupon_name = strip(self.coupon_name)
+		self.name = self.coupon_name
+
+		if not self.coupon_code:
+			if self.coupon_type == "Promotional":
+				self.coupon_code =''.join([i for i in self.coupon_name if not i.isdigit()])[0:8].upper()
+			elif self.coupon_type == "Gift Card":
+				self.coupon_code = frappe.generate_hash()[:10].upper()
+		
+	def validate(self):
+		if self.coupon_type == "Gift Card":
+			self.maximum_use = 1
+			if not self.customer:
+				frappe.throw(_("Please select the customer."))
diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.js b/erpnext/accounts/doctype/coupon_code/test_coupon_code.js
new file mode 100644
index 0000000..460fedc
--- /dev/null
+++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Coupon Code", function (assert) {
+	let done = assert.async();
+
+	// number of asserts
+	assert.expect(1);
+
+	frappe.run_serially([
+		// insert a new Coupon Code
+		() => frappe.tests.make('Coupon Code', [
+			// values to be set
+			{key: 'value'}
+		]),
+		() => {
+			assert.equal(cur_frm.doc.key, 'value');
+		},
+		() => done()
+	]);
+
+});
diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py
new file mode 100644
index 0000000..990b896
--- /dev/null
+++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py
@@ -0,0 +1,132 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
+from erpnext.stock.get_item_details import get_item_details
+from frappe.test_runner import make_test_objects
+
+def test_create_test_data():
+	frappe.set_user("Administrator")
+	# create test item
+	if not frappe.db.exists("Item","_Test Tesla Car"):
+		item = frappe.get_doc({
+		"description": "_Test Tesla Car",
+		"doctype": "Item",
+		"has_batch_no": 0,
+		"has_serial_no": 0,
+		"inspection_required": 0,
+		"is_stock_item": 1,
+		"opening_stock":100,
+		"is_sub_contracted_item": 0,
+		"item_code": "_Test Tesla Car",
+		"item_group": "_Test Item Group",
+		"item_name": "_Test Tesla Car",
+		"apply_warehouse_wise_reorder_level": 0,
+		"warehouse":"_Test Warehouse - _TC",
+		"gst_hsn_code": "999800",
+		"valuation_rate": 5000,
+		"standard_rate":5000,
+		"item_defaults": [{
+		"company": "_Test Company",
+		"default_warehouse": "_Test Warehouse - _TC",
+		"default_price_list":"_Test Price List",
+		"expense_account": "_Test Account Cost for Goods Sold - _TC",
+		"buying_cost_center": "_Test Cost Center - _TC",
+		"selling_cost_center": "_Test Cost Center - _TC",
+		"income_account": "Sales - _TC"
+		}],
+		"show_in_website": 1,
+		"route":"-test-tesla-car",
+		"website_warehouse": "_Test Warehouse - _TC"
+		})
+		item.insert()
+	# create test item price
+	item_price = frappe.get_list('Item Price', filters={'item_code': '_Test Tesla Car', 'price_list': '_Test Price List'}, fields=['name'])
+	if len(item_price)==0:
+		item_price = frappe.get_doc({
+			"doctype": "Item Price",
+			"item_code": "_Test Tesla Car",
+			"price_list": "_Test Price List",
+			"price_list_rate": 5000
+		})
+		item_price.insert()
+	# create test item pricing rule
+	if not frappe.db.exists("Pricing Rule","_Test Pricing Rule for _Test Item"):
+		item_pricing_rule = frappe.get_doc({
+		"doctype": "Pricing Rule",
+		"title": "_Test Pricing Rule for _Test Item",
+		"apply_on": "Item Code",
+		"items": [{
+			"item_code": "_Test Tesla Car"
+		}],
+		"warehouse":"_Test Warehouse - _TC",
+		"coupon_code_based":1,
+		"selling": 1,
+		"rate_or_discount": "Discount Percentage",
+		"discount_percentage": 30,
+		"company": "_Test Company",
+		"currency":"INR",
+		"for_price_list":"_Test Price List"
+		})
+		item_pricing_rule.insert()
+	# create test item sales partner
+	if not frappe.db.exists("Sales Partner","_Test Coupon Partner"):
+		sales_partner = frappe.get_doc({
+		"doctype": "Sales Partner",
+		"partner_name":"_Test Coupon Partner",
+		"commission_rate":2,
+		"referral_code": "COPART"
+		})
+		sales_partner.insert()
+	# create test item coupon code
+	if not frappe.db.exists("Coupon Code","SAVE30"):
+		coupon_code = frappe.get_doc({
+		"doctype": "Coupon Code",
+		"coupon_name":"SAVE30",
+		"coupon_code":"SAVE30",
+		"pricing_rule": "_Test Pricing Rule for _Test Item",
+		"valid_from": "2014-01-01",
+		"maximum_use":1,
+		"used":0
+		})
+		coupon_code.insert()
+
+
+class TestCouponCode(unittest.TestCase):
+	def setUp(self):
+		test_create_test_data()
+
+	def tearDown(self):
+		frappe.set_user("Administrator")
+
+	def test_1_check_coupon_code_used_before_so(self):
+		coupon_code = frappe.get_doc("Coupon Code", frappe.db.get_value("Coupon Code", {"coupon_name":"SAVE30"}))
+		# reset used coupon code count
+		coupon_code.used=0
+		coupon_code.save()
+		# check no coupon code is used before sales order is made
+		self.assertEqual(coupon_code.get("used"),0)
+
+	def test_2_sales_order_with_coupon_code(self):
+		so = make_sales_order(customer="_Test Customer",selling_price_list="_Test Price List",item_code="_Test Tesla Car", rate=5000,qty=1, do_not_submit=True)
+		so = frappe.get_doc('Sales Order', so.name)
+		# check item price before coupon code is applied
+		self.assertEqual(so.items[0].rate, 5000)
+		so.coupon_code='SAVE30'
+		so.sales_partner='_Test Coupon Partner'
+		so.save()
+		# check item price after coupon code is applied
+		self.assertEqual(so.items[0].rate, 3500)	
+		so.submit()
+
+	def test_3_check_coupon_code_used_after_so(self):
+		doc = frappe.get_doc("Coupon Code", frappe.db.get_value("Coupon Code", {"coupon_name":"SAVE30"}))
+		# check no coupon code is used before sales order is made
+		self.assertEqual(doc.get("used"),1)
+
+
+
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index c846ba2..ab811d8 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -40,7 +40,7 @@
  "fields": [
   {
    "bold": 1,
-   "columns": 3,
+   "columns": 2,
    "fieldname": "account",
    "fieldtype": "Link",
    "in_global_search": 1,
@@ -90,14 +90,16 @@
    "fieldtype": "Column Break"
   },
   {
+   "default": "Customer",
    "fieldname": "party_type",
    "fieldtype": "Link",
+   "in_list_view": 1,
    "label": "Party Type",
    "options": "DocType",
    "search_index": 1
   },
   {
-   "columns": 3,
+   "columns": 2,
    "fieldname": "party",
    "fieldtype": "Dynamic Link",
    "in_list_view": 1,
@@ -270,7 +272,7 @@
  ],
  "idx": 1,
  "istable": 1,
- "modified": "2019-09-12 12:16:17.588399",
+ "modified": "2019-10-02 12:23:21.693443",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Journal Entry Account",
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 789bc8a..89aaffb 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1045,7 +1045,7 @@
 
 	def update_item(source_doc, target_doc, source_parent):
 		target_doc.bank_account = source_parent.party_bank_account
-		target_doc.amount = source_parent.base_paid_amount
+		target_doc.amount = source_doc.allocated_amount
 		target_doc.account = source_parent.paid_to
 		target_doc.payment_entry = source_parent.name
 		target_doc.supplier = source_parent.party
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
index 0210212..971d308 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
@@ -1,2627 +1,616 @@
 {
- "allow_copy": 0, 
- "allow_events_in_timeline": 0, 
- "allow_guest_to_view": 0, 
- "allow_import": 1, 
- "allow_rename": 1, 
- "autoname": "field:title", 
- "beta": 0, 
- "creation": "2014-02-21 15:02:51", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "", 
- "editable_grid": 0, 
+ "allow_import": 1,
+ "allow_rename": 1,
+ "autoname": "field:title",
+ "creation": "2014-02-21 15:02:51",
+ "doctype": "DocType",
+ "engine": "InnoDB",
+ "field_order": [
+  "applicability_section",
+  "title",
+  "disable",
+  "apply_on",
+  "price_or_product_discount",
+  "warehouse",
+  "column_break_7",
+  "items",
+  "item_groups",
+  "brands",
+  "mixed_conditions",
+  "is_cumulative",
+  "coupon_code_based",
+  "section_break_18",
+  "apply_rule_on_other",
+  "column_break_17",
+  "other_item_code",
+  "other_item_group",
+  "other_brand",
+  "section_break_7",
+  "selling",
+  "buying",
+  "column_break_11",
+  "applicable_for",
+  "customer",
+  "customer_group",
+  "territory",
+  "sales_partner",
+  "campaign",
+  "supplier",
+  "supplier_group",
+  "section_break_19",
+  "min_qty",
+  "max_qty",
+  "column_break_21",
+  "min_amt",
+  "max_amt",
+  "section_break_23",
+  "valid_from",
+  "valid_upto",
+  "col_break1",
+  "company",
+  "currency",
+  "margin",
+  "margin_type",
+  "column_break_33",
+  "margin_rate_or_amount",
+  "price_discount_scheme_section",
+  "rate_or_discount",
+  "apply_discount_on",
+  "col_break2",
+  "rate",
+  "discount_amount",
+  "discount_percentage",
+  "for_price_list",
+  "product_discount_scheme_section",
+  "same_item",
+  "free_item",
+  "free_qty",
+  "column_break_51",
+  "free_item_uom",
+  "free_item_rate",
+  "section_break_13",
+  "threshold_percentage",
+  "priority",
+  "column_break_66",
+  "apply_multiple_pricing_rules",
+  "apply_discount_on_rate",
+  "validate_applied_rule",
+  "rule_description",
+  "help_section",
+  "pricing_rule_help",
+  "reference_section",
+  "promotional_scheme_id",
+  "promotional_scheme"
+ ],
  "fields": [
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "applicability_section", 
-   "fieldtype": "Section Break", 
-   "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": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "applicability_section",
+   "fieldtype": "Section Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "title", 
-   "fieldtype": "Data", 
-   "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": "Title", 
-   "length": 0, 
-   "no_copy": 1, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
+   "fieldname": "title",
+   "fieldtype": "Data",
+   "label": "Title",
+   "no_copy": 1,
+   "reqd": 1,
    "unique": 1
-  }, 
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "disable", 
-   "fieldtype": "Check", 
-   "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": "Disable", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "disable",
+   "fieldtype": "Check",
+   "label": "Disable"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Item Code", 
-   "fetch_if_empty": 0, 
-   "fieldname": "apply_on", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Apply On", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nItem Code\nItem Group\nBrand\nTransaction", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "Item Code",
+   "fieldname": "apply_on",
+   "fieldtype": "Select",
+   "in_list_view": 1,
+   "in_standard_filter": 1,
+   "label": "Apply On",
+   "options": "\nItem Code\nItem Group\nBrand\nTransaction",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "price_or_product_discount", 
-   "fieldtype": "Select", 
-   "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": "Price or Product Discount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Price\nProduct", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "price_or_product_discount",
+   "fieldtype": "Select",
+   "label": "Price or Product Discount",
+   "options": "Price\nProduct",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_on != 'Transaction'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "warehouse", 
-   "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": "Warehouse", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Warehouse", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_on != 'Transaction'",
+   "fieldname": "warehouse",
+   "fieldtype": "Link",
+   "label": "Warehouse",
+   "options": "Warehouse",
+   "search_index": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_7", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_7",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_on == 'Item Code'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "items", 
-   "fieldtype": "Table", 
-   "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": "Apply Rule On Item Code", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Pricing Rule Item Code", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_on == 'Item Code'",
+   "fieldname": "items",
+   "fieldtype": "Table",
+   "label": "Apply Rule On Item Code",
+   "options": "Pricing Rule Item Code"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_on == 'Item Group'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "item_groups", 
-   "fieldtype": "Table", 
-   "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": "Apply Rule On Item Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Pricing Rule Item Group", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_on == 'Item Group'",
+   "fieldname": "item_groups",
+   "fieldtype": "Table",
+   "label": "Apply Rule On Item Group",
+   "options": "Pricing Rule Item Group"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_on == 'Brand'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "brands", 
-   "fieldtype": "Table", 
-   "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": "Apply Rule On Brand", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Pricing Rule Brand", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_on == 'Brand'",
+   "fieldname": "brands",
+   "fieldtype": "Table",
+   "label": "Apply Rule On Brand",
+   "options": "Pricing Rule Brand"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_on != 'Transaction'", 
-   "description": "Conditions will be applied on all the selected items combined. ", 
-   "fetch_if_empty": 0, 
-   "fieldname": "mixed_conditions", 
-   "fieldtype": "Check", 
-   "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": "Mixed Conditions", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "depends_on": "eval:doc.apply_on != 'Transaction'",
+   "description": "Conditions will be applied on all the selected items combined. ",
+   "fieldname": "mixed_conditions",
+   "fieldtype": "Check",
+   "label": "Mixed Conditions"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "is_cumulative", 
-   "fieldtype": "Check", 
-   "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": "Is Cumulative", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "is_cumulative",
+   "fieldtype": "Check",
+   "label": "Is Cumulative"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_on != 'Transaction'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "section_break_18", 
-   "fieldtype": "Section Break", 
-   "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": "Discount on Other Item", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "coupon_code_based",
+   "fieldtype": "Check",
+   "label": "Coupon Code Based"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "apply_rule_on_other", 
-   "fieldtype": "Select", 
-   "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": "Apply Rule On Other", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nItem Code\nItem Group\nBrand", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "depends_on": "eval:doc.apply_on != 'Transaction'",
+   "fieldname": "section_break_18",
+   "fieldtype": "Section Break",
+   "label": "Discount on Other Item"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_17", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "apply_rule_on_other",
+   "fieldtype": "Select",
+   "label": "Apply Rule On Other",
+   "options": "\nItem Code\nItem Group\nBrand"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_rule_on_other == 'Item Code'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "other_item_code", 
-   "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": "Item Code", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Item", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_17",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_rule_on_other == 'Item Group'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "other_item_group", 
-   "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": "Item Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Item Group", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_rule_on_other == 'Item Code'",
+   "fieldname": "other_item_code",
+   "fieldtype": "Link",
+   "label": "Item Code",
+   "options": "Item"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.apply_rule_on_other == 'Brand'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "other_brand", 
-   "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": "Brand", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Brand", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_rule_on_other == 'Item Group'",
+   "fieldname": "other_item_group",
+   "fieldtype": "Link",
+   "label": "Item Group",
+   "options": "Item Group"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "section_break_7", 
-   "fieldtype": "Section Break", 
-   "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": "Party Information", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.apply_rule_on_other == 'Brand'",
+   "fieldname": "other_brand",
+   "fieldtype": "Link",
+   "label": "Brand",
+   "options": "Brand"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "selling", 
-   "fieldtype": "Check", 
-   "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": "Selling", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "section_break_7",
+   "fieldtype": "Section Break",
+   "label": "Party Information"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "buying", 
-   "fieldtype": "Check", 
-   "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": "Buying", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "selling",
+   "fieldtype": "Check",
+   "label": "Selling"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_11", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "buying",
+   "fieldtype": "Check",
+   "label": "Buying"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval: doc.buying || doc.selling", 
-   "fetch_if_empty": 0, 
-   "fieldname": "applicable_for", 
-   "fieldtype": "Select", 
-   "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": "Applicable For", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nCustomer\nCustomer Group\nTerritory\nSales Partner\nCampaign\nSupplier\nSupplier Group", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_11",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Customer\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "customer", 
-   "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": "Customer", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Customer", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval: doc.buying || doc.selling",
+   "fieldname": "applicable_for",
+   "fieldtype": "Select",
+   "label": "Applicable For",
+   "options": "\nCustomer\nCustomer Group\nTerritory\nSales Partner\nCampaign\nSupplier\nSupplier Group"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Customer Group\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "customer_group", 
-   "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": "Customer Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Customer Group", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Customer\"",
+   "fieldname": "customer",
+   "fieldtype": "Link",
+   "label": "Customer",
+   "options": "Customer"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Territory\"", 
-   "fetch_if_empty": 0, 
-   "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": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Customer Group\"",
+   "fieldname": "customer_group",
+   "fieldtype": "Link",
+   "label": "Customer Group",
+   "options": "Customer Group"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Sales Partner\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "sales_partner", 
-   "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": "Sales Partner", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Sales Partner", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Territory\"",
+   "fieldname": "territory",
+   "fieldtype": "Link",
+   "label": "Territory",
+   "options": "Territory"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Campaign\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "campaign", 
-   "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": "Campaign", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Campaign", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Sales Partner\"",
+   "fieldname": "sales_partner",
+   "fieldtype": "Link",
+   "label": "Sales Partner",
+   "options": "Sales Partner"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Supplier\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "supplier", 
-   "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": "Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Supplier", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Campaign\"",
+   "fieldname": "campaign",
+   "fieldtype": "Link",
+   "label": "Campaign",
+   "options": "Campaign"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.applicable_for==\"Supplier Group\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "supplier_group", 
-   "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": "Supplier Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Supplier Group", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Supplier\"",
+   "fieldname": "supplier",
+   "fieldtype": "Link",
+   "label": "Supplier",
+   "options": "Supplier"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "section_break_19", 
-   "fieldtype": "Section Break", 
-   "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": "Quantity and Amount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.applicable_for==\"Supplier Group\"",
+   "fieldname": "supplier_group",
+   "fieldtype": "Link",
+   "label": "Supplier Group",
+   "options": "Supplier Group"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "min_qty", 
-   "fieldtype": "Float", 
-   "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": "Min Qty", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "section_break_19",
+   "fieldtype": "Section Break",
+   "label": "Quantity and Amount"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "max_qty", 
-   "fieldtype": "Float", 
-   "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": "Max Qty", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "min_qty",
+   "fieldtype": "Float",
+   "label": "Min Qty"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_21", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "max_qty",
+   "fieldtype": "Float",
+   "label": "Max Qty"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "fetch_if_empty": 0, 
-   "fieldname": "min_amt", 
-   "fieldtype": "Currency", 
-   "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": "Min Amt", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "currency", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_21",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "fetch_if_empty": 0, 
-   "fieldname": "max_amt", 
-   "fieldtype": "Currency", 
-   "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": "Max Amt", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "currency", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "min_amt",
+   "fieldtype": "Currency",
+   "label": "Min Amt",
+   "options": "currency"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "section_break_23", 
-   "fieldtype": "Section Break", 
-   "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": "Period Settings", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "max_amt",
+   "fieldtype": "Currency",
+   "label": "Max Amt",
+   "options": "currency"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Today", 
-   "fetch_if_empty": 0, 
-   "fieldname": "valid_from", 
-   "fieldtype": "Date", 
-   "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": "Valid From", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "section_break_23",
+   "fieldtype": "Section Break",
+   "label": "Period Settings"
+  },
+  {
+   "default": "Today",
+   "fieldname": "valid_from",
+   "fieldtype": "Date",
+   "label": "Valid From"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "valid_upto", 
-   "fieldtype": "Date", 
-   "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": "Valid Upto", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "valid_upto",
+   "fieldtype": "Date",
+   "label": "Valid Upto"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "col_break1", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "col_break1",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "company", 
-   "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": "Company", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Company", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 1, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "company",
+   "fieldtype": "Link",
+   "label": "Company",
+   "options": "Company",
+   "remember_last_selected_value": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "currency", 
-   "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": "Currency", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Currency", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "currency",
+   "fieldtype": "Link",
+   "label": "Currency",
+   "options": "Currency",
+   "print_hide": 1,
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval: doc.selling == 1", 
-   "fetch_if_empty": 0, 
-   "fieldname": "margin", 
-   "fieldtype": "Section Break", 
-   "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": "Margin", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval: doc.selling == 1",
+   "fieldname": "margin",
+   "fieldtype": "Section Break",
+   "label": "Margin"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Percentage", 
-   "fetch_if_empty": 0, 
-   "fieldname": "margin_type", 
-   "fieldtype": "Select", 
-   "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": "Margin Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nPercentage\nAmount", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "Percentage",
+   "fieldname": "margin_type",
+   "fieldtype": "Select",
+   "label": "Margin Type",
+   "options": "\nPercentage\nAmount"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_33", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_33",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "depends_on": "eval:doc.margin_type", 
-   "fetch_if_empty": 0, 
-   "fieldname": "margin_rate_or_amount", 
-   "fieldtype": "Float", 
-   "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": "Margin Rate or Amount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "depends_on": "eval:doc.margin_type",
+   "fieldname": "margin_rate_or_amount",
+   "fieldtype": "Float",
+   "label": "Margin Rate or Amount"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.price_or_product_discount == 'Price'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "price_discount_scheme_section", 
-   "fieldtype": "Section Break", 
-   "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": "Price Discount Scheme", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.price_or_product_discount == 'Price'",
+   "fieldname": "price_discount_scheme_section",
+   "fieldtype": "Section Break",
+   "label": "Price Discount Scheme"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Discount Percentage", 
-   "fetch_if_empty": 0, 
-   "fieldname": "rate_or_discount", 
-   "fieldtype": "Select", 
-   "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": "Rate or Discount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nRate\nDiscount Percentage\nDiscount Amount", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "Discount Percentage",
+   "fieldname": "rate_or_discount",
+   "fieldtype": "Select",
+   "label": "Rate or Discount",
+   "options": "\nRate\nDiscount Percentage\nDiscount Amount",
+   "reqd": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Grand Total", 
-   "depends_on": "eval:doc.apply_on == 'Transaction' && doc.rate_or_discount != 'Rate'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "apply_discount_on", 
-   "fieldtype": "Select", 
-   "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": "Apply Discount On", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Grand Total\nNet Total", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "Grand Total",
+   "depends_on": "eval:doc.apply_on == 'Transaction' && doc.rate_or_discount != 'Rate'",
+   "fieldname": "apply_discount_on",
+   "fieldtype": "Select",
+   "label": "Apply Discount On",
+   "options": "Grand Total\nNet Total"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "col_break2", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "col_break2",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.rate_or_discount==\"Rate\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "rate", 
-   "fieldtype": "Currency", 
-   "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": "Rate", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.rate_or_discount==\"Rate\"",
+   "fieldname": "rate",
+   "fieldtype": "Currency",
+   "label": "Rate"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "depends_on": "eval:doc.rate_or_discount==\"Discount Amount\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "discount_amount", 
-   "fieldtype": "Currency", 
-   "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": "Discount Amount", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "currency", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "depends_on": "eval:doc.rate_or_discount==\"Discount Amount\"",
+   "fieldname": "discount_amount",
+   "fieldtype": "Currency",
+   "label": "Discount Amount",
+   "options": "currency"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.rate_or_discount==\"Discount Percentage\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "discount_percentage", 
-   "fieldtype": "Float", 
-   "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": "Discount Percentage", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.rate_or_discount==\"Discount Percentage\"",
+   "fieldname": "discount_percentage",
+   "fieldtype": "Float",
+   "label": "Discount Percentage"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.rate_or_discount==\"Discount Percentage\"", 
-   "fetch_if_empty": 0, 
-   "fieldname": "for_price_list", 
-   "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": "For Price List", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Price List", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.rate_or_discount!=\"Rate\"",
+   "fieldname": "for_price_list",
+   "fieldtype": "Link",
+   "label": "For Price List",
+   "options": "Price List"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.price_or_product_discount == 'Product'", 
-   "fetch_if_empty": 0, 
-   "fieldname": "product_discount_scheme_section", 
-   "fieldtype": "Section Break", 
-   "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": "Product Discount Scheme", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:doc.price_or_product_discount == 'Product'",
+   "fieldname": "product_discount_scheme_section",
+   "fieldtype": "Section Break",
+   "label": "Product Discount Scheme"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.mixed_conditions", 
-   "fetch_if_empty": 0, 
-   "fieldname": "same_item", 
-   "fieldtype": "Check", 
-   "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": "Same Item", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "depends_on": "eval:!doc.mixed_conditions",
+   "fieldname": "same_item",
+   "fieldtype": "Check",
+   "label": "Same Item"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.same_item || doc.mixed_conditions", 
-   "fetch_if_empty": 0, 
-   "fieldname": "free_item", 
-   "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": "Free Item", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Item", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "eval:!doc.same_item || doc.mixed_conditions",
+   "fieldname": "free_item",
+   "fieldtype": "Link",
+   "label": "Free Item",
+   "options": "Item"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "free_qty", 
-   "fieldtype": "Float", 
-   "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": "Qty", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "free_qty",
+   "fieldtype": "Float",
+   "label": "Qty"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_51", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_51",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "free_item_uom", 
-   "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": "UOM", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "UOM", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "free_item_uom",
+   "fieldtype": "Link",
+   "label": "UOM",
+   "options": "UOM"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "free_item_rate", 
-   "fieldtype": "Currency", 
-   "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": "Rate", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "free_item_rate",
+   "fieldtype": "Currency",
+   "label": "Rate"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "section_break_13", 
-   "fieldtype": "Section Break", 
-   "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": "Advanced Settings", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "collapsible": 1,
+   "fieldname": "section_break_13",
+   "fieldtype": "Section Break",
+   "label": "Advanced Settings"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "System will notify to increase or decrease quantity or amount ", 
-   "fetch_if_empty": 0, 
-   "fieldname": "threshold_percentage", 
-   "fieldtype": "Percent", 
-   "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": "Threshold for Suggestion", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "description": "System will notify to increase or decrease quantity or amount ",
+   "fieldname": "threshold_percentage",
+   "fieldtype": "Percent",
+   "label": "Threshold for Suggestion"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "Higher the number, higher the priority", 
-   "fetch_if_empty": 0, 
-   "fieldname": "priority", 
-   "fieldtype": "Select", 
-   "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": "Priority", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "description": "Higher the number, higher the priority",
+   "fieldname": "priority",
+   "fieldtype": "Select",
+   "label": "Priority",
+   "options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "column_break_66", 
-   "fieldtype": "Column Break", 
-   "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, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "column_break_66",
+   "fieldtype": "Column Break"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "apply_multiple_pricing_rules", 
-   "fieldtype": "Check", 
-   "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": "Apply Multiple Pricing Rules", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "fieldname": "apply_multiple_pricing_rules",
+   "fieldtype": "Check",
+   "label": "Apply Multiple Pricing Rules"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:in_list(['Discount Percentage', 'Discount Amount'], doc.rate_or_discount) && doc.apply_multiple_pricing_rules", 
-   "fetch_if_empty": 0, 
-   "fieldname": "apply_discount_on_rate", 
-   "fieldtype": "Check", 
-   "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": "Apply Discount on Rate", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "depends_on": "eval:in_list(['Discount Percentage', 'Discount Amount'], doc.rate_or_discount) && doc.apply_multiple_pricing_rules",
+   "fieldname": "apply_discount_on_rate",
+   "fieldtype": "Check",
+   "label": "Apply Discount on Rate"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.price_or_product_discount == 'Price'", 
-   "description": "", 
-   "fetch_if_empty": 0, 
-   "fieldname": "validate_applied_rule", 
-   "fieldtype": "Check", 
-   "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": "Validate Applied Rule", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "default": "0",
+   "depends_on": "eval:doc.price_or_product_discount == 'Price'",
+   "fieldname": "validate_applied_rule",
+   "fieldtype": "Check",
+   "label": "Validate Applied Rule"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "validate_applied_rule", 
-   "fetch_if_empty": 0, 
-   "fieldname": "rule_description", 
-   "fieldtype": "Small Text", 
-   "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": "Rule Description", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "depends_on": "validate_applied_rule",
+   "fieldname": "rule_description",
+   "fieldtype": "Small Text",
+   "label": "Rule Description"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "help_section", 
-   "fieldtype": "Section Break", 
-   "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": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Simple", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "help_section",
+   "fieldtype": "Section Break",
+   "options": "Simple"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "pricing_rule_help", 
-   "fieldtype": "HTML", 
-   "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": "Pricing Rule Help", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "pricing_rule_help",
+   "fieldtype": "HTML",
+   "label": "Pricing Rule Help"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "reference_section", 
-   "fieldtype": "Section Break", 
-   "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": "Reference", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "reference_section",
+   "fieldtype": "Section Break",
+   "hidden": 1,
+   "label": "Reference"
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "promotional_scheme_id", 
-   "fieldtype": "Data", 
-   "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": "Promotional Scheme Id", 
-   "length": 0, 
-   "no_copy": 1, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "translatable": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "promotional_scheme_id",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Promotional Scheme Id",
+   "no_copy": 1,
+   "print_hide": 1,
+   "read_only": 1
+  },
   {
-   "allow_bulk_edit": 0, 
-   "allow_in_quick_entry": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fetch_if_empty": 0, 
-   "fieldname": "promotional_scheme", 
-   "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": "Promotional Scheme", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Promotional Scheme", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "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, 
-   "translatable": 0, 
-   "unique": 0
+   "fieldname": "promotional_scheme",
+   "fieldtype": "Link",
+   "label": "Promotional Scheme",
+   "options": "Promotional Scheme"
   }
- ], 
- "has_web_view": 0, 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "icon": "fa fa-gift", 
- "idx": 1, 
- "image_view": 0, 
- "in_create": 0, 
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2019-03-25 13:20:11.773190", 
- "modified_by": "Administrator", 
- "module": "Accounts", 
- "name": "Pricing Rule", 
- "owner": "Administrator", 
+ ],
+ "icon": "fa fa-gift",
+ "idx": 1,
+ "modified": "2019-10-15 12:39:40.399792",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Pricing Rule",
+ "owner": "Administrator",
  "permissions": [
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 0, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 1, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Accounts Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
+   "create": 1,
+   "delete": 1,
+   "export": 1,
+   "import": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Accounts Manager",
+   "share": 1,
    "write": 1
-  }, 
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 0, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Sales Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
+   "create": 1,
+   "delete": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Sales Manager",
+   "share": 1,
    "write": 1
-  }, 
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 0, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
+   "create": 1,
+   "delete": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Purchase Manager",
+   "share": 1,
    "write": 1
-  }, 
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 0, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Website Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
+   "create": 1,
+   "delete": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Website Manager",
+   "share": 1,
    "write": 1
-  }, 
+  },
   {
-   "amend": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 0, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 1, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "System Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
+   "create": 1,
+   "delete": 1,
+   "export": 1,
+   "import": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
    "write": 1
   }
- ], 
- "quick_entry": 0, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "show_name_in_global_search": 1, 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "title_field": "", 
- "track_changes": 0, 
- "track_seen": 0, 
- "track_views": 0
+ ],
+ "show_name_in_global_search": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index a94d127..1776275 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -249,6 +249,9 @@
 			if pricing_rule.mixed_conditions or pricing_rule.apply_rule_on_other:
 				continue
 
+			if pricing_rule.coupon_code_based==1 and args.coupon_code==None:
+				return item_details
+				
 			if (not pricing_rule.validate_applied_rule and
 				pricing_rule.price_or_product_discount == "Price"):
 				apply_price_discount_pricing_rule(pricing_rule, item_details, args)
diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py
index bbabac4..ef26c2e 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -531,4 +531,32 @@
 	for d in doc.get("items"):
 		validate_pricing_rule_on_items(doc, d, True)
 
-	return doc
\ No newline at end of file
+	return doc
+
+def validate_coupon_code(coupon_name):
+	from frappe.utils import today,getdate
+	coupon=frappe.get_doc("Coupon Code",coupon_name)
+	if coupon.valid_from:
+		if coupon.valid_from > getdate(today()) :
+			frappe.throw(_("Sorry,coupon code validity has not started"))
+	elif coupon.valid_upto:
+		if coupon.valid_upto < getdate(today()) :
+			frappe.throw(_("Sorry,coupon code validity has expired"))	
+	elif coupon.used>=coupon.maximum_use:
+		frappe.throw(_("Sorry,coupon code are exhausted"))
+	else:
+		return
+
+def update_coupon_code_count(coupon_name,transaction_type):
+	coupon=frappe.get_doc("Coupon Code",coupon_name)
+	if coupon:
+		if transaction_type=='used':
+			if coupon.used<coupon.maximum_use:
+				coupon.used=coupon.used+1
+				coupon.save(ignore_permissions=True)
+			else:
+				frappe.throw(_("{0} Coupon used are {1}. Allowed quantity is exhausted").format(coupon.coupon_code,coupon.used))
+		elif transaction_type=='cancelled':
+			if coupon.used>0:
+				coupon.used=coupon.used-1
+				coupon.save(ignore_permissions=True)
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 1f57836..96aceac 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -1,1623 +1,1624 @@
 {
-   "allow_import": 1,
-   "autoname": "naming_series:",
-   "creation": "2013-05-24 19:29:05",
-   "doctype": "DocType",
-   "engine": "InnoDB",
-   "field_order": [
-    "customer_section",
-    "title",
-    "naming_series",
-    "customer",
-    "customer_name",
-    "tax_id",
-    "is_pos",
-    "pos_profile",
-    "offline_pos_name",
-    "is_return",
-    "column_break1",
-    "company",
-    "posting_date",
-    "posting_time",
-    "set_posting_time",
-    "due_date",
-    "amended_from",
-    "returns",
-    "return_against",
-    "column_break_21",
-    "update_billed_amount_in_sales_order",
-    "accounting_dimensions_section",
-    "project",
-    "dimension_col_break",
-    "cost_center",
-    "customer_po_details",
-    "po_no",
-    "column_break_23",
-    "po_date",
-    "address_and_contact",
-    "customer_address",
-    "address_display",
-    "contact_person",
-    "contact_display",
-    "contact_mobile",
-    "contact_email",
-    "territory",
-    "col_break4",
-    "shipping_address_name",
-    "shipping_address",
-    "company_address",
-    "company_address_display",
-    "currency_and_price_list",
-    "currency",
-    "conversion_rate",
-    "column_break2",
-    "selling_price_list",
-    "price_list_currency",
-    "plc_conversion_rate",
-    "ignore_pricing_rule",
-    "sec_warehouse",
-    "set_warehouse",
-    "items_section",
-    "update_stock",
-    "scan_barcode",
-    "items",
-    "pricing_rule_details",
-    "pricing_rules",
-    "packing_list",
-    "packed_items",
-    "product_bundle_help",
-    "time_sheet_list",
-    "timesheets",
-    "total_billing_amount",
-    "section_break_30",
-    "total_qty",
-    "base_total",
-    "base_net_total",
-    "column_break_32",
-    "total",
-    "net_total",
-    "total_net_weight",
-    "taxes_section",
-    "taxes_and_charges",
-    "column_break_38",
-    "shipping_rule",
-    "tax_category",
-    "section_break_40",
-    "taxes",
-    "sec_tax_breakup",
-    "other_charges_calculation",
-    "section_break_43",
-    "base_total_taxes_and_charges",
-    "column_break_47",
-    "total_taxes_and_charges",
-    "loyalty_points_redemption",
-    "loyalty_points",
-    "loyalty_amount",
-    "redeem_loyalty_points",
-    "column_break_77",
-    "loyalty_program",
-    "loyalty_redemption_account",
-    "loyalty_redemption_cost_center",
-    "section_break_49",
-    "apply_discount_on",
-    "base_discount_amount",
-    "column_break_51",
-    "additional_discount_percentage",
-    "discount_amount",
-    "totals",
-    "base_grand_total",
-    "base_rounding_adjustment",
-    "base_rounded_total",
-    "base_in_words",
-    "column_break5",
-    "grand_total",
-    "rounding_adjustment",
-    "rounded_total",
-    "in_words",
-    "total_advance",
-    "outstanding_amount",
-    "advances_section",
-    "allocate_advances_automatically",
-    "get_advances",
-    "advances",
-    "payment_schedule_section",
-    "payment_terms_template",
-    "payment_schedule",
-    "payments_section",
-    "cash_bank_account",
-    "payments",
-    "section_break_84",
-    "base_paid_amount",
-    "column_break_86",
-    "paid_amount",
-    "section_break_88",
-    "base_change_amount",
-    "column_break_90",
-    "change_amount",
-    "account_for_change_amount",
-    "column_break4",
-    "write_off_amount",
-    "base_write_off_amount",
-    "write_off_outstanding_amount_automatically",
-    "column_break_74",
-    "write_off_account",
-    "write_off_cost_center",
-    "terms_section_break",
-    "tc_name",
-    "terms",
-    "edit_printing_settings",
-    "letter_head",
-    "group_same_items",
-    "language",
-    "column_break_84",
-    "select_print_heading",
-    "more_information",
-    "inter_company_invoice_reference",
-    "customer_group",
-    "campaign",
-    "is_discounted",
-    "col_break23",
-    "status",
-    "source",
-    "more_info",
-    "debit_to",
-    "party_account_currency",
-    "is_opening",
-    "c_form_applicable",
-    "c_form_no",
-    "column_break8",
-    "remarks",
-    "sales_team_section_break",
-    "sales_partner",
-    "column_break10",
-    "commission_rate",
-    "total_commission",
-    "section_break2",
-    "sales_team",
-    "subscription_section",
-    "from_date",
-    "to_date",
-    "column_break_140",
-    "auto_repeat",
-    "update_auto_repeat_reference",
-    "against_income_account",
-    "pos_total_qty"
-   ],
-   "fields": [
-    {
-     "fieldname": "customer_section",
-     "fieldtype": "Section Break",
-     "options": "fa fa-user"
-    },
-    {
-     "allow_on_submit": 1,
-     "default": "{customer_name}",
-     "fieldname": "title",
-     "fieldtype": "Data",
-     "hidden": 1,
-     "label": "Title",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "bold": 1,
-     "fieldname": "naming_series",
-     "fieldtype": "Select",
-     "label": "Series",
-     "no_copy": 1,
-     "oldfieldname": "naming_series",
-     "oldfieldtype": "Select",
-     "options": "ACC-SINV-.YYYY.-",
-     "print_hide": 1,
-     "reqd": 1,
-     "set_only_once": 1
-    },
-    {
-     "bold": 1,
-     "fieldname": "customer",
-     "fieldtype": "Link",
-     "in_standard_filter": 1,
-     "label": "Customer",
-     "oldfieldname": "customer",
-     "oldfieldtype": "Link",
-     "options": "Customer",
-     "print_hide": 1,
-     "search_index": 1
-    },
-    {
-     "bold": 1,
-     "depends_on": "customer",
-     "fetch_from": "customer.customer_name",
-     "fieldname": "customer_name",
-     "fieldtype": "Data",
-     "in_global_search": 1,
-     "label": "Customer Name",
-     "oldfieldname": "customer_name",
-     "oldfieldtype": "Data",
-     "read_only": 1
-    },
-    {
-     "fieldname": "tax_id",
-     "fieldtype": "Data",
-     "label": "Tax Id",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "project",
-     "fieldtype": "Link",
-     "in_global_search": 1,
-     "label": "Project",
-     "oldfieldname": "project_name",
-     "oldfieldtype": "Link",
-     "options": "Project",
-     "print_hide": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "is_pos",
-     "fieldtype": "Check",
-     "label": "Include Payment (POS)",
-     "oldfieldname": "is_pos",
-     "oldfieldtype": "Check",
-     "print_hide": 1
-    },
-    {
-     "depends_on": "is_pos",
-     "fieldname": "pos_profile",
-     "fieldtype": "Link",
-     "label": "POS Profile",
-     "options": "POS Profile",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "offline_pos_name",
-     "fieldtype": "Data",
-     "hidden": 1,
-     "label": "Offline POS Name",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "is_return",
-     "fieldtype": "Check",
-     "label": "Is Return (Credit Note)",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break1",
-     "fieldtype": "Column Break",
-     "oldfieldtype": "Column Break"
-    },
-    {
-     "fieldname": "company",
-     "fieldtype": "Link",
-     "in_standard_filter": 1,
-     "label": "Company",
-     "oldfieldname": "company",
-     "oldfieldtype": "Link",
-     "options": "Company",
-     "print_hide": 1,
-     "remember_last_selected_value": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "cost_center",
-     "fieldtype": "Link",
-     "label": "Cost Center",
-     "options": "Cost Center"
-    },
-    {
-     "bold": 1,
-     "default": "Today",
-     "fieldname": "posting_date",
-     "fieldtype": "Date",
-     "label": "Date",
-     "no_copy": 1,
-     "oldfieldname": "posting_date",
-     "oldfieldtype": "Date",
-     "reqd": 1,
-     "search_index": 1
-    },
-    {
-     "fieldname": "posting_time",
-     "fieldtype": "Time",
-     "label": "Posting Time",
-     "no_copy": 1,
-     "oldfieldname": "posting_time",
-     "oldfieldtype": "Time",
-     "print_hide": 1
-    },
-    {
-     "default": "0",
-     "depends_on": "eval:doc.docstatus==0",
-     "fieldname": "set_posting_time",
-     "fieldtype": "Check",
-     "label": "Edit Posting Date and Time",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "due_date",
-     "fieldtype": "Date",
-     "label": "Payment Due Date",
-     "no_copy": 1,
-     "oldfieldname": "due_date",
-     "oldfieldtype": "Date"
-    },
-    {
-     "fieldname": "amended_from",
-     "fieldtype": "Link",
-     "ignore_user_permissions": 1,
-     "label": "Amended From",
-     "no_copy": 1,
-     "oldfieldname": "amended_from",
-     "oldfieldtype": "Link",
-     "options": "Sales Invoice",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "depends_on": "return_against",
-     "fieldname": "returns",
-     "fieldtype": "Section Break",
-     "label": "Returns"
-    },
-    {
-     "depends_on": "return_against",
-     "fieldname": "return_against",
-     "fieldtype": "Link",
-     "label": "Return Against Sales Invoice",
-     "no_copy": 1,
-     "options": "Sales Invoice",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_21",
-     "fieldtype": "Column Break"
-    },
-    {
-     "default": "0",
-     "depends_on": "eval: doc.is_return && doc.return_against",
-     "fieldname": "update_billed_amount_in_sales_order",
-     "fieldtype": "Check",
-     "label": "Update Billed Amount in Sales Order"
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "po_no",
-     "fieldname": "customer_po_details",
-     "fieldtype": "Section Break",
-     "label": "Customer PO Details"
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "po_no",
-     "fieldtype": "Data",
-     "label": "Customer's Purchase Order",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break_23",
-     "fieldtype": "Column Break"
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "po_date",
-     "fieldtype": "Date",
-     "label": "Customer's Purchase Order Date"
-    },
-    {
-     "collapsible": 1,
-     "fieldname": "address_and_contact",
-     "fieldtype": "Section Break",
-     "label": "Address and Contact"
-    },
-    {
-     "fieldname": "customer_address",
-     "fieldtype": "Link",
-     "label": "Customer Address",
-     "options": "Address",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "address_display",
-     "fieldtype": "Small Text",
-     "label": "Address",
-     "read_only": 1
-    },
-    {
-     "fieldname": "contact_person",
-     "fieldtype": "Link",
-     "in_global_search": 1,
-     "label": "Contact Person",
-     "options": "Contact",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "contact_display",
-     "fieldtype": "Small Text",
-     "label": "Contact",
-     "read_only": 1
-    },
-    {
-     "fieldname": "contact_mobile",
-     "fieldtype": "Small Text",
-     "hidden": 1,
-     "label": "Mobile No",
-     "read_only": 1
-    },
-    {
-     "fieldname": "contact_email",
-     "fieldtype": "Data",
-     "hidden": 1,
-     "label": "Contact Email",
-     "options": "Email",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "territory",
-     "fieldtype": "Link",
-     "label": "Territory",
-     "options": "Territory",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "col_break4",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "shipping_address_name",
-     "fieldtype": "Link",
-     "label": "Shipping Address Name",
-     "options": "Address",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "shipping_address",
-     "fieldtype": "Small Text",
-     "label": "Shipping Address",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "company_address",
-     "fieldtype": "Link",
-     "label": "Company Address Name",
-     "options": "Address",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "company_address_display",
-     "fieldtype": "Small Text",
-     "hidden": 1,
-     "label": "Company Address",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "collapsible": 1,
-     "depends_on": "customer",
-     "fieldname": "currency_and_price_list",
-     "fieldtype": "Section Break",
-     "label": "Currency and Price List"
-    },
-    {
-     "fieldname": "currency",
-     "fieldtype": "Link",
-     "label": "Currency",
-     "oldfieldname": "currency",
-     "oldfieldtype": "Select",
-     "options": "Currency",
-     "print_hide": 1,
-     "reqd": 1
-    },
-    {
-     "description": "Rate at which Customer Currency is converted to customer's base currency",
-     "fieldname": "conversion_rate",
-     "fieldtype": "Float",
-     "label": "Exchange Rate",
-     "oldfieldname": "conversion_rate",
-     "oldfieldtype": "Currency",
-     "precision": "9",
-     "print_hide": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "column_break2",
-     "fieldtype": "Column Break",
-     "width": "50%"
-    },
-    {
-     "fieldname": "selling_price_list",
-     "fieldtype": "Link",
-     "label": "Price List",
-     "oldfieldname": "price_list_name",
-     "oldfieldtype": "Select",
-     "options": "Price List",
-     "print_hide": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "price_list_currency",
-     "fieldtype": "Link",
-     "label": "Price List Currency",
-     "options": "Currency",
-     "print_hide": 1,
-     "read_only": 1,
-     "reqd": 1
-    },
-    {
-     "description": "Rate at which Price list currency is converted to customer's base currency",
-     "fieldname": "plc_conversion_rate",
-     "fieldtype": "Float",
-     "label": "Price List Exchange Rate",
-     "precision": "9",
-     "print_hide": 1,
-     "reqd": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "ignore_pricing_rule",
-     "fieldtype": "Check",
-     "label": "Ignore Pricing Rule",
-     "no_copy": 1,
-     "permlevel": 1,
-     "print_hide": 1
-    },
-    {
-     "fieldname": "sec_warehouse",
-     "fieldtype": "Section Break"
-    },
-    {
-     "depends_on": "update_stock",
-     "fieldname": "set_warehouse",
-     "fieldtype": "Link",
-     "label": "Set Source Warehouse",
-     "options": "Warehouse",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "items_section",
-     "fieldtype": "Section Break",
-     "oldfieldtype": "Section Break",
-     "options": "fa fa-shopping-cart"
-    },
-    {
-     "default": "0",
-     "fieldname": "update_stock",
-     "fieldtype": "Check",
-     "label": "Update Stock",
-     "oldfieldname": "update_stock",
-     "oldfieldtype": "Check",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "scan_barcode",
-     "fieldtype": "Data",
-     "label": "Scan Barcode"
-    },
-    {
-     "allow_bulk_edit": 1,
-     "fieldname": "items",
-     "fieldtype": "Table",
-     "label": "Items",
-     "oldfieldname": "entries",
-     "oldfieldtype": "Table",
-     "options": "Sales Invoice Item",
-     "reqd": 1
-    },
-    {
-     "fieldname": "pricing_rule_details",
-     "fieldtype": "Section Break",
-     "label": "Pricing Rules"
-    },
-    {
-     "fieldname": "pricing_rules",
-     "fieldtype": "Table",
-     "label": "Pricing Rule Detail",
-     "options": "Pricing Rule Detail",
-     "read_only": 1
-    },
-    {
-     "fieldname": "packing_list",
-     "fieldtype": "Section Break",
-     "label": "Packing List",
-     "options": "fa fa-suitcase",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "packed_items",
-     "fieldtype": "Table",
-     "label": "Packed Items",
-     "options": "Packed Item",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "product_bundle_help",
-     "fieldtype": "HTML",
-     "label": "Product Bundle Help",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "eval:doc.total_billing_amount > 0",
-     "fieldname": "time_sheet_list",
-     "fieldtype": "Section Break",
-     "label": "Time Sheet List"
-    },
-    {
-     "fieldname": "timesheets",
-     "fieldtype": "Table",
-     "label": "Time Sheets",
-     "options": "Sales Invoice Timesheet",
-     "print_hide": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "total_billing_amount",
-     "fieldtype": "Currency",
-     "label": "Total Billing Amount",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "section_break_30",
-     "fieldtype": "Section Break"
-    },
-    {
-     "fieldname": "total_qty",
-     "fieldtype": "Float",
-     "label": "Total Quantity",
-     "read_only": 1
-    },
-    {
-     "fieldname": "base_total",
-     "fieldtype": "Currency",
-     "label": "Total (Company Currency)",
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "base_net_total",
-     "fieldtype": "Currency",
-     "label": "Net Total (Company Currency)",
-     "oldfieldname": "net_total",
-     "oldfieldtype": "Currency",
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "column_break_32",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "total",
-     "fieldtype": "Currency",
-     "label": "Total",
-     "options": "currency",
-     "read_only": 1
-    },
-    {
-     "fieldname": "net_total",
-     "fieldtype": "Currency",
-     "label": "Net Total",
-     "options": "currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "total_net_weight",
-     "fieldtype": "Float",
-     "label": "Total Net Weight",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "taxes_section",
-     "fieldtype": "Section Break",
-     "oldfieldtype": "Section Break",
-     "options": "fa fa-money"
-    },
-    {
-     "fieldname": "taxes_and_charges",
-     "fieldtype": "Link",
-     "label": "Sales Taxes and Charges Template",
-     "oldfieldname": "charge",
-     "oldfieldtype": "Link",
-     "options": "Sales Taxes and Charges Template",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break_38",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "shipping_rule",
-     "fieldtype": "Link",
-     "label": "Shipping Rule",
-     "oldfieldtype": "Button",
-     "options": "Shipping Rule",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "tax_category",
-     "fieldtype": "Link",
-     "label": "Tax Category",
-     "options": "Tax Category",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "section_break_40",
-     "fieldtype": "Section Break"
-    },
-    {
-     "fieldname": "taxes",
-     "fieldtype": "Table",
-     "label": "Sales Taxes and Charges",
-     "oldfieldname": "other_charges",
-     "oldfieldtype": "Table",
-     "options": "Sales Taxes and Charges"
-    },
-    {
-     "collapsible": 1,
-     "fieldname": "sec_tax_breakup",
-     "fieldtype": "Section Break",
-     "label": "Tax Breakup"
-    },
-    {
-     "fieldname": "other_charges_calculation",
-     "fieldtype": "Text",
-     "label": "Taxes and Charges Calculation",
-     "no_copy": 1,
-     "oldfieldtype": "HTML",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "section_break_43",
-     "fieldtype": "Section Break"
-    },
-    {
-     "fieldname": "base_total_taxes_and_charges",
-     "fieldtype": "Currency",
-     "label": "Total Taxes and Charges (Company Currency)",
-     "oldfieldname": "other_charges_total",
-     "oldfieldtype": "Currency",
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_47",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "total_taxes_and_charges",
-     "fieldtype": "Currency",
-     "label": "Total Taxes and Charges",
-     "options": "currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "collapsible": 1,
-     "fieldname": "loyalty_points_redemption",
-     "fieldtype": "Section Break",
-     "label": "Loyalty Points Redemption"
-    },
-    {
-     "depends_on": "redeem_loyalty_points",
-     "fieldname": "loyalty_points",
-     "fieldtype": "Int",
-     "label": "Loyalty Points",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "depends_on": "redeem_loyalty_points",
-     "fieldname": "loyalty_amount",
-     "fieldtype": "Currency",
-     "label": "Loyalty Amount",
-     "no_copy": 1,
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "redeem_loyalty_points",
-     "fieldtype": "Check",
-     "label": "Redeem Loyalty Points",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break_77",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fetch_from": "customer.loyalty_program",
-     "fieldname": "loyalty_program",
-     "fieldtype": "Link",
-     "label": "Loyalty Program",
-     "no_copy": 1,
-     "options": "Loyalty Program",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "depends_on": "redeem_loyalty_points",
-     "fieldname": "loyalty_redemption_account",
-     "fieldtype": "Link",
-     "label": "Redemption Account",
-     "no_copy": 1,
-     "options": "Account"
-    },
-    {
-     "depends_on": "redeem_loyalty_points",
-     "fieldname": "loyalty_redemption_cost_center",
-     "fieldtype": "Link",
-     "label": "Redemption Cost Center",
-     "no_copy": 1,
-     "options": "Cost Center"
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "discount_amount",
-     "fieldname": "section_break_49",
-     "fieldtype": "Section Break",
-     "label": "Additional Discount"
-    },
-    {
-     "default": "Grand Total",
-     "fieldname": "apply_discount_on",
-     "fieldtype": "Select",
-     "label": "Apply Additional Discount On",
-     "options": "\nGrand Total\nNet Total",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "base_discount_amount",
-     "fieldtype": "Currency",
-     "label": "Additional Discount Amount (Company Currency)",
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_51",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "additional_discount_percentage",
-     "fieldtype": "Float",
-     "label": "Additional Discount Percentage",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "discount_amount",
-     "fieldtype": "Currency",
-     "label": "Additional Discount Amount",
-     "options": "currency",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "totals",
-     "fieldtype": "Section Break",
-     "oldfieldtype": "Section Break",
-     "options": "fa fa-money",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "base_grand_total",
-     "fieldtype": "Currency",
-     "label": "Grand Total (Company Currency)",
-     "oldfieldname": "grand_total",
-     "oldfieldtype": "Currency",
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "base_rounding_adjustment",
-     "fieldtype": "Currency",
-     "label": "Rounding Adjustment (Company Currency)",
-     "no_copy": 1,
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "base_rounded_total",
-     "fieldtype": "Currency",
-     "label": "Rounded Total (Company Currency)",
-     "oldfieldname": "rounded_total",
-     "oldfieldtype": "Currency",
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "description": "In Words will be visible once you save the Sales Invoice.",
-     "fieldname": "base_in_words",
-     "fieldtype": "Data",
-     "label": "In Words (Company Currency)",
-     "oldfieldname": "in_words",
-     "oldfieldtype": "Data",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break5",
-     "fieldtype": "Column Break",
-     "oldfieldtype": "Column Break",
-     "print_hide": 1,
-     "width": "50%"
-    },
-    {
-     "bold": 1,
-     "fieldname": "grand_total",
-     "fieldtype": "Currency",
-     "in_list_view": 1,
-     "label": "Grand Total",
-     "oldfieldname": "grand_total_export",
-     "oldfieldtype": "Currency",
-     "options": "currency",
-     "read_only": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "rounding_adjustment",
-     "fieldtype": "Currency",
-     "label": "Rounding Adjustment",
-     "no_copy": 1,
-     "options": "currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "bold": 1,
-     "fieldname": "rounded_total",
-     "fieldtype": "Currency",
-     "label": "Rounded Total",
-     "oldfieldname": "rounded_total_export",
-     "oldfieldtype": "Currency",
-     "options": "currency",
-     "read_only": 1
-    },
-    {
-     "fieldname": "in_words",
-     "fieldtype": "Data",
-     "label": "In Words",
-     "oldfieldname": "in_words_export",
-     "oldfieldtype": "Data",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "total_advance",
-     "fieldtype": "Currency",
-     "label": "Total Advance",
-     "oldfieldname": "total_advance",
-     "oldfieldtype": "Currency",
-     "options": "party_account_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "outstanding_amount",
-     "fieldtype": "Currency",
-     "label": "Outstanding Amount",
-     "no_copy": 1,
-     "oldfieldname": "outstanding_amount",
-     "oldfieldtype": "Currency",
-     "options": "party_account_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "advances",
-     "fieldname": "advances_section",
-     "fieldtype": "Section Break",
-     "label": "Advance Payments",
-     "oldfieldtype": "Section Break",
-     "options": "fa fa-money",
-     "print_hide": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "allocate_advances_automatically",
-     "fieldtype": "Check",
-     "label": "Allocate Advances Automatically (FIFO)"
-    },
-    {
-     "depends_on": "eval:!doc.allocate_advances_automatically",
-     "fieldname": "get_advances",
-     "fieldtype": "Button",
-     "label": "Get Advances Received",
-     "options": "set_advances"
-    },
-    {
-     "fieldname": "advances",
-     "fieldtype": "Table",
-     "label": "Advances",
-     "oldfieldname": "advance_adjustment_details",
-     "oldfieldtype": "Table",
-     "options": "Sales Invoice Advance",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "eval:(!doc.is_pos && !doc.is_return)",
-     "fieldname": "payment_schedule_section",
-     "fieldtype": "Section Break",
-     "label": "Payment Terms"
-    },
-    {
-     "depends_on": "eval:(!doc.is_pos && !doc.is_return)",
-     "fieldname": "payment_terms_template",
-     "fieldtype": "Link",
-     "label": "Payment Terms Template",
-     "no_copy": 1,
-     "options": "Payment Terms Template",
-     "print_hide": 1
-    },
-    {
-     "depends_on": "eval:(!doc.is_pos && !doc.is_return)",
-     "fieldname": "payment_schedule",
-     "fieldtype": "Table",
-     "label": "Payment Schedule",
-     "no_copy": 1,
-     "options": "Payment Schedule",
-     "print_hide": 1
-    },
-    {
-     "depends_on": "eval:doc.is_pos===1||(doc.advances && doc.advances.length>0)",
-     "fieldname": "payments_section",
-     "fieldtype": "Section Break",
-     "label": "Payments",
-     "options": "fa fa-money"
-    },
-    {
-     "depends_on": "is_pos",
-     "fieldname": "cash_bank_account",
-     "fieldtype": "Link",
-     "hidden": 1,
-     "label": "Cash/Bank Account",
-     "oldfieldname": "cash_bank_account",
-     "oldfieldtype": "Link",
-     "options": "Account",
-     "print_hide": 1
-    },
-    {
-     "depends_on": "eval:doc.is_pos===1",
-     "fieldname": "payments",
-     "fieldtype": "Table",
-     "label": "Sales Invoice Payment",
-     "options": "Sales Invoice Payment",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "section_break_84",
-     "fieldtype": "Section Break"
-    },
-    {
-     "fieldname": "base_paid_amount",
-     "fieldtype": "Currency",
-     "label": "Paid Amount (Company Currency)",
-     "no_copy": 1,
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_86",
-     "fieldtype": "Column Break"
-    },
-    {
-     "depends_on": "eval: doc.is_pos || doc.redeem_loyalty_points",
-     "fieldname": "paid_amount",
-     "fieldtype": "Currency",
-     "label": "Paid Amount",
-     "no_copy": 1,
-     "oldfieldname": "paid_amount",
-     "oldfieldtype": "Currency",
-     "options": "currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "section_break_88",
-     "fieldtype": "Section Break"
-    },
-    {
-     "depends_on": "is_pos",
-     "fieldname": "base_change_amount",
-     "fieldtype": "Currency",
-     "label": "Base Change Amount (Company Currency)",
-     "no_copy": 1,
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_90",
-     "fieldtype": "Column Break"
-    },
-    {
-     "depends_on": "is_pos",
-     "fieldname": "change_amount",
-     "fieldtype": "Currency",
-     "label": "Change Amount",
-     "no_copy": 1,
-     "options": "currency",
-     "print_hide": 1
-    },
-    {
-     "depends_on": "is_pos",
-     "fieldname": "account_for_change_amount",
-     "fieldtype": "Link",
-     "label": "Account for Change Amount",
-     "options": "Account",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "write_off_amount",
-     "depends_on": "grand_total",
-     "fieldname": "column_break4",
-     "fieldtype": "Section Break",
-     "label": "Write Off",
-     "width": "50%"
-    },
-    {
-     "fieldname": "write_off_amount",
-     "fieldtype": "Currency",
-     "label": "Write Off Amount",
-     "no_copy": 1,
-     "options": "currency",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "base_write_off_amount",
-     "fieldtype": "Currency",
-     "label": "Write Off Amount (Company Currency)",
-     "no_copy": 1,
-     "options": "Company:company:default_currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "default": "0",
-     "depends_on": "is_pos",
-     "fieldname": "write_off_outstanding_amount_automatically",
-     "fieldtype": "Check",
-     "label": "Write Off Outstanding Amount",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break_74",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "write_off_account",
-     "fieldtype": "Link",
-     "label": "Write Off Account",
-     "options": "Account",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "write_off_cost_center",
-     "fieldtype": "Link",
-     "label": "Write Off Cost Center",
-     "options": "Cost Center",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "terms",
-     "fieldname": "terms_section_break",
-     "fieldtype": "Section Break",
-     "label": "Terms",
-     "oldfieldtype": "Section Break"
-    },
-    {
-     "fieldname": "tc_name",
-     "fieldtype": "Link",
-     "label": "Terms",
-     "oldfieldname": "tc_name",
-     "oldfieldtype": "Link",
-     "options": "Terms and Conditions",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "terms",
-     "fieldtype": "Text Editor",
-     "label": "Terms and Conditions Details",
-     "oldfieldname": "terms",
-     "oldfieldtype": "Text Editor"
-    },
-    {
-     "collapsible": 1,
-     "fieldname": "edit_printing_settings",
-     "fieldtype": "Section Break",
-     "label": "Printing Settings"
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "letter_head",
-     "fieldtype": "Link",
-     "label": "Letter Head",
-     "oldfieldname": "letter_head",
-     "oldfieldtype": "Select",
-     "options": "Letter Head",
-     "print_hide": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "default": "0",
-     "fieldname": "group_same_items",
-     "fieldtype": "Check",
-     "label": "Group same items",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "language",
-     "fieldtype": "Data",
-     "label": "Print Language",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_84",
-     "fieldtype": "Column Break"
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "select_print_heading",
-     "fieldtype": "Link",
-     "label": "Print Heading",
-     "no_copy": 1,
-     "oldfieldname": "select_print_heading",
-     "oldfieldtype": "Link",
-     "options": "Print Heading",
-     "print_hide": 1,
-     "report_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "depends_on": "customer",
-     "fieldname": "more_information",
-     "fieldtype": "Section Break",
-     "label": "More Information"
-    },
-    {
-     "fieldname": "inter_company_invoice_reference",
-     "fieldtype": "Link",
-     "label": "Inter Company Invoice Reference",
-     "options": "Purchase Invoice",
-     "read_only": 1
-    },
-    {
-     "fieldname": "customer_group",
-     "fieldtype": "Link",
-     "hidden": 1,
-     "label": "Customer Group",
-     "options": "Customer Group",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "campaign",
-     "fieldtype": "Link",
-     "label": "Campaign",
-     "oldfieldname": "campaign",
-     "oldfieldtype": "Link",
-     "options": "Campaign",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "is_discounted",
-     "fieldtype": "Check",
-     "label": "Is Discounted",
-     "no_copy": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "col_break23",
-     "fieldtype": "Column Break",
-     "width": "50%"
-    },
-    {
-     "default": "Draft",
-     "fieldname": "status",
-     "fieldtype": "Select",
-     "in_standard_filter": 1,
-     "label": "Status",
-     "no_copy": 1,
-     "options": "\nDraft\nReturn\nCredit Note Issued\nSubmitted\nPaid\nUnpaid\nUnpaid and Discounted\nOverdue and Discounted\nOverdue\nOverdue\nCancelled",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "source",
-     "fieldtype": "Link",
-     "label": "Source",
-     "oldfieldname": "source",
-     "oldfieldtype": "Select",
-     "options": "Lead Source",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "fieldname": "more_info",
-     "fieldtype": "Section Break",
-     "label": "Accounting Details",
-     "oldfieldtype": "Section Break",
-     "options": "fa fa-file-text",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "debit_to",
-     "fieldtype": "Link",
-     "label": "Debit To",
-     "oldfieldname": "debit_to",
-     "oldfieldtype": "Link",
-     "options": "Account",
-     "print_hide": 1,
-     "reqd": 1,
-     "search_index": 1
-    },
-    {
-     "fieldname": "party_account_currency",
-     "fieldtype": "Link",
-     "hidden": 1,
-     "label": "Party Account Currency",
-     "no_copy": 1,
-     "options": "Currency",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "default": "No",
-     "fieldname": "is_opening",
-     "fieldtype": "Select",
-     "label": "Is Opening Entry",
-     "oldfieldname": "is_opening",
-     "oldfieldtype": "Select",
-     "options": "No\nYes",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "c_form_applicable",
-     "fieldtype": "Select",
-     "label": "C-Form Applicable",
-     "no_copy": 1,
-     "options": "No\nYes",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "c_form_no",
-     "fieldtype": "Link",
-     "label": "C-Form No",
-     "no_copy": 1,
-     "options": "C-Form",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break8",
-     "fieldtype": "Column Break",
-     "oldfieldtype": "Column Break",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "remarks",
-     "fieldtype": "Small Text",
-     "label": "Remarks",
-     "no_copy": 1,
-     "oldfieldname": "remarks",
-     "oldfieldtype": "Text",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "sales_partner",
-     "fieldname": "sales_team_section_break",
-     "fieldtype": "Section Break",
-     "label": "Commission",
-     "oldfieldtype": "Section Break",
-     "options": "fa fa-group",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "sales_partner",
-     "fieldtype": "Link",
-     "label": "Sales Partner",
-     "oldfieldname": "sales_partner",
-     "oldfieldtype": "Link",
-     "options": "Sales Partner",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break10",
-     "fieldtype": "Column Break",
-     "oldfieldtype": "Column Break",
-     "print_hide": 1,
-     "width": "50%"
-    },
-    {
-     "fieldname": "commission_rate",
-     "fieldtype": "Float",
-     "label": "Commission Rate (%)",
-     "oldfieldname": "commission_rate",
-     "oldfieldtype": "Currency",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "total_commission",
-     "fieldtype": "Currency",
-     "label": "Total Commission",
-     "oldfieldname": "total_commission",
-     "oldfieldtype": "Currency",
-     "options": "Company:company:default_currency",
-     "print_hide": 1
-    },
-    {
-     "collapsible": 1,
-     "collapsible_depends_on": "sales_team",
-     "fieldname": "section_break2",
-     "fieldtype": "Section Break",
-     "label": "Sales Team",
-     "print_hide": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "sales_team",
-     "fieldtype": "Table",
-     "label": "Sales Team1",
-     "oldfieldname": "sales_team",
-     "oldfieldtype": "Table",
-     "options": "Sales Team",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "subscription_section",
-     "fieldtype": "Section Break",
-     "label": "Subscription Section"
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "from_date",
-     "fieldtype": "Date",
-     "label": "From Date",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "to_date",
-     "fieldtype": "Date",
-     "label": "To Date",
-     "no_copy": 1,
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break_140",
-     "fieldtype": "Column Break"
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "auto_repeat",
-     "fieldtype": "Link",
-     "label": "Auto Repeat",
-     "no_copy": 1,
-     "options": "Auto Repeat",
-     "print_hide": 1,
-     "read_only": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "depends_on": "eval: doc.auto_repeat",
-     "fieldname": "update_auto_repeat_reference",
-     "fieldtype": "Button",
-     "label": "Update Auto Repeat Reference"
-    },
-    {
-     "fieldname": "against_income_account",
-     "fieldtype": "Small Text",
-     "hidden": 1,
-     "label": "Against Income Account",
-     "no_copy": 1,
-     "oldfieldname": "against_income_account",
-     "oldfieldtype": "Small Text",
-     "print_hide": 1,
-     "report_hide": 1
-    },
-    {
-     "fieldname": "pos_total_qty",
-     "fieldtype": "Float",
-     "hidden": 1,
-     "label": "Total Qty",
-     "print_hide": 1,
-     "print_hide_if_no_value": 1,
-     "read_only": 1
-    },
-    {
-     "collapsible": 1,
-     "fieldname": "accounting_dimensions_section",
-     "fieldtype": "Section Break",
-     "label": "Accounting Dimensions"
-    },
-    {
-     "fieldname": "dimension_col_break",
-     "fieldtype": "Column Break"
-    }
-   ],
-   "icon": "fa fa-file-text",
-   "idx": 181,
-   "is_submittable": 1,
-   "modified": "2019-07-04 22:05:03.474745",
-   "modified_by": "Administrator",
-   "module": "Accounts",
-   "name": "Sales Invoice",
-   "name_case": "Title Case",
-   "owner": "Administrator",
-   "permissions": [
-    {
-     "amend": 1,
-     "cancel": 1,
-     "create": 1,
-     "delete": 1,
-     "email": 1,
-     "print": 1,
-     "read": 1,
-     "report": 1,
-     "role": "Accounts Manager",
-     "share": 1,
-     "submit": 1,
-     "write": 1
-    },
-    {
-     "amend": 1,
-     "create": 1,
-     "email": 1,
-     "print": 1,
-     "read": 1,
-     "report": 1,
-     "role": "Accounts User",
-     "share": 1,
-     "submit": 1,
-     "write": 1
-    },
-    {
-     "permlevel": 1,
-     "read": 1,
-     "role": "Accounts Manager",
-     "write": 1
-    },
-    {
-     "permlevel": 1,
-     "read": 1,
-     "role": "All"
-    }
-   ],
-   "quick_entry": 1,
-   "search_fields": "posting_date, due_date, customer, base_grand_total, outstanding_amount",
-   "show_name_in_global_search": 1,
-   "sort_field": "modified",
-   "sort_order": "DESC",
-   "timeline_field": "customer",
-   "title_field": "title",
-   "track_changes": 1,
-   "track_seen": 1
+ "allow_import": 1,
+ "autoname": "naming_series:",
+ "creation": "2013-05-24 19:29:05",
+ "doctype": "DocType",
+ "engine": "InnoDB",
+ "field_order": [
+  "customer_section",
+  "title",
+  "naming_series",
+  "customer",
+  "customer_name",
+  "tax_id",
+  "is_pos",
+  "pos_profile",
+  "offline_pos_name",
+  "is_return",
+  "column_break1",
+  "company",
+  "posting_date",
+  "posting_time",
+  "set_posting_time",
+  "due_date",
+  "amended_from",
+  "returns",
+  "return_against",
+  "column_break_21",
+  "update_billed_amount_in_sales_order",
+  "accounting_dimensions_section",
+  "project",
+  "dimension_col_break",
+  "cost_center",
+  "customer_po_details",
+  "po_no",
+  "column_break_23",
+  "po_date",
+  "address_and_contact",
+  "customer_address",
+  "address_display",
+  "contact_person",
+  "contact_display",
+  "contact_mobile",
+  "contact_email",
+  "territory",
+  "col_break4",
+  "shipping_address_name",
+  "shipping_address",
+  "company_address",
+  "company_address_display",
+  "currency_and_price_list",
+  "currency",
+  "conversion_rate",
+  "column_break2",
+  "selling_price_list",
+  "price_list_currency",
+  "plc_conversion_rate",
+  "ignore_pricing_rule",
+  "sec_warehouse",
+  "set_warehouse",
+  "items_section",
+  "update_stock",
+  "scan_barcode",
+  "items",
+  "pricing_rule_details",
+  "pricing_rules",
+  "packing_list",
+  "packed_items",
+  "product_bundle_help",
+  "time_sheet_list",
+  "timesheets",
+  "total_billing_amount",
+  "section_break_30",
+  "total_qty",
+  "base_total",
+  "base_net_total",
+  "column_break_32",
+  "total",
+  "net_total",
+  "total_net_weight",
+  "taxes_section",
+  "taxes_and_charges",
+  "column_break_38",
+  "shipping_rule",
+  "tax_category",
+  "section_break_40",
+  "taxes",
+  "sec_tax_breakup",
+  "other_charges_calculation",
+  "section_break_43",
+  "base_total_taxes_and_charges",
+  "column_break_47",
+  "total_taxes_and_charges",
+  "loyalty_points_redemption",
+  "loyalty_points",
+  "loyalty_amount",
+  "redeem_loyalty_points",
+  "column_break_77",
+  "loyalty_program",
+  "loyalty_redemption_account",
+  "loyalty_redemption_cost_center",
+  "section_break_49",
+  "apply_discount_on",
+  "base_discount_amount",
+  "column_break_51",
+  "additional_discount_percentage",
+  "discount_amount",
+  "totals",
+  "base_grand_total",
+  "base_rounding_adjustment",
+  "base_rounded_total",
+  "base_in_words",
+  "column_break5",
+  "grand_total",
+  "rounding_adjustment",
+  "rounded_total",
+  "in_words",
+  "total_advance",
+  "outstanding_amount",
+  "advances_section",
+  "allocate_advances_automatically",
+  "get_advances",
+  "advances",
+  "payment_schedule_section",
+  "payment_terms_template",
+  "payment_schedule",
+  "payments_section",
+  "cash_bank_account",
+  "payments",
+  "section_break_84",
+  "base_paid_amount",
+  "column_break_86",
+  "paid_amount",
+  "section_break_88",
+  "base_change_amount",
+  "column_break_90",
+  "change_amount",
+  "account_for_change_amount",
+  "column_break4",
+  "write_off_amount",
+  "base_write_off_amount",
+  "write_off_outstanding_amount_automatically",
+  "column_break_74",
+  "write_off_account",
+  "write_off_cost_center",
+  "terms_section_break",
+  "tc_name",
+  "terms",
+  "edit_printing_settings",
+  "letter_head",
+  "group_same_items",
+  "language",
+  "column_break_84",
+  "select_print_heading",
+  "more_information",
+  "inter_company_invoice_reference",
+  "customer_group",
+  "campaign",
+  "is_discounted",
+  "col_break23",
+  "status",
+  "source",
+  "more_info",
+  "debit_to",
+  "party_account_currency",
+  "is_opening",
+  "c_form_applicable",
+  "c_form_no",
+  "column_break8",
+  "remarks",
+  "sales_team_section_break",
+  "sales_partner",
+  "column_break10",
+  "commission_rate",
+  "total_commission",
+  "section_break2",
+  "sales_team",
+  "subscription_section",
+  "from_date",
+  "to_date",
+  "column_break_140",
+  "auto_repeat",
+  "update_auto_repeat_reference",
+  "against_income_account",
+  "pos_total_qty"
+ ],
+ "fields": [
+  {
+   "fieldname": "customer_section",
+   "fieldtype": "Section Break",
+   "options": "fa fa-user"
+  },
+  {
+   "allow_on_submit": 1,
+   "default": "{customer_name}",
+   "fieldname": "title",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Title",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "bold": 1,
+   "fieldname": "naming_series",
+   "fieldtype": "Select",
+   "label": "Series",
+   "no_copy": 1,
+   "oldfieldname": "naming_series",
+   "oldfieldtype": "Select",
+   "options": "ACC-SINV-.YYYY.-",
+   "print_hide": 1,
+   "reqd": 1,
+   "set_only_once": 1
+  },
+  {
+   "bold": 1,
+   "fieldname": "customer",
+   "fieldtype": "Link",
+   "in_standard_filter": 1,
+   "label": "Customer",
+   "oldfieldname": "customer",
+   "oldfieldtype": "Link",
+   "options": "Customer",
+   "print_hide": 1,
+   "search_index": 1
+  },
+  {
+   "bold": 1,
+   "depends_on": "customer",
+   "fetch_from": "customer.customer_name",
+   "fieldname": "customer_name",
+   "fieldtype": "Data",
+   "in_global_search": 1,
+   "label": "Customer Name",
+   "oldfieldname": "customer_name",
+   "oldfieldtype": "Data",
+   "read_only": 1
+  },
+  {
+   "fieldname": "tax_id",
+   "fieldtype": "Data",
+   "label": "Tax Id",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "project",
+   "fieldtype": "Link",
+   "in_global_search": 1,
+   "label": "Project",
+   "oldfieldname": "project_name",
+   "oldfieldtype": "Link",
+   "options": "Project",
+   "print_hide": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "is_pos",
+   "fieldtype": "Check",
+   "label": "Include Payment (POS)",
+   "oldfieldname": "is_pos",
+   "oldfieldtype": "Check",
+   "print_hide": 1
+  },
+  {
+   "depends_on": "is_pos",
+   "fieldname": "pos_profile",
+   "fieldtype": "Link",
+   "label": "POS Profile",
+   "options": "POS Profile",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "offline_pos_name",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Offline POS Name",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "is_return",
+   "fieldtype": "Check",
+   "label": "Is Return (Credit Note)",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break1",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break"
+  },
+  {
+   "fieldname": "company",
+   "fieldtype": "Link",
+   "in_standard_filter": 1,
+   "label": "Company",
+   "oldfieldname": "company",
+   "oldfieldtype": "Link",
+   "options": "Company",
+   "print_hide": 1,
+   "remember_last_selected_value": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "cost_center",
+   "fieldtype": "Link",
+   "label": "Cost Center",
+   "options": "Cost Center"
+  },
+  {
+   "bold": 1,
+   "default": "Today",
+   "fieldname": "posting_date",
+   "fieldtype": "Date",
+   "label": "Date",
+   "no_copy": 1,
+   "oldfieldname": "posting_date",
+   "oldfieldtype": "Date",
+   "reqd": 1,
+   "search_index": 1
+  },
+  {
+   "fieldname": "posting_time",
+   "fieldtype": "Time",
+   "label": "Posting Time",
+   "no_copy": 1,
+   "oldfieldname": "posting_time",
+   "oldfieldtype": "Time",
+   "print_hide": 1
+  },
+  {
+   "default": "0",
+   "depends_on": "eval:doc.docstatus==0",
+   "fieldname": "set_posting_time",
+   "fieldtype": "Check",
+   "label": "Edit Posting Date and Time",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "due_date",
+   "fieldtype": "Date",
+   "label": "Payment Due Date",
+   "no_copy": 1,
+   "oldfieldname": "due_date",
+   "oldfieldtype": "Date"
+  },
+  {
+   "fieldname": "amended_from",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Amended From",
+   "no_copy": 1,
+   "oldfieldname": "amended_from",
+   "oldfieldtype": "Link",
+   "options": "Sales Invoice",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "depends_on": "return_against",
+   "fieldname": "returns",
+   "fieldtype": "Section Break",
+   "label": "Returns"
+  },
+  {
+   "depends_on": "return_against",
+   "fieldname": "return_against",
+   "fieldtype": "Link",
+   "label": "Return Against Sales Invoice",
+   "no_copy": 1,
+   "options": "Sales Invoice",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_21",
+   "fieldtype": "Column Break"
+  },
+  {
+   "default": "0",
+   "depends_on": "eval: doc.is_return && doc.return_against",
+   "fieldname": "update_billed_amount_in_sales_order",
+   "fieldtype": "Check",
+   "label": "Update Billed Amount in Sales Order"
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "po_no",
+   "fieldname": "customer_po_details",
+   "fieldtype": "Section Break",
+   "label": "Customer PO Details"
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "po_no",
+   "fieldtype": "Data",
+   "label": "Customer's Purchase Order",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break_23",
+   "fieldtype": "Column Break"
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "po_date",
+   "fieldtype": "Date",
+   "label": "Customer's Purchase Order Date"
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "address_and_contact",
+   "fieldtype": "Section Break",
+   "label": "Address and Contact"
+  },
+  {
+   "fieldname": "customer_address",
+   "fieldtype": "Link",
+   "label": "Customer Address",
+   "options": "Address",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "address_display",
+   "fieldtype": "Small Text",
+   "label": "Address",
+   "read_only": 1
+  },
+  {
+   "fieldname": "contact_person",
+   "fieldtype": "Link",
+   "in_global_search": 1,
+   "label": "Contact Person",
+   "options": "Contact",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "contact_display",
+   "fieldtype": "Small Text",
+   "label": "Contact",
+   "read_only": 1
+  },
+  {
+   "fieldname": "contact_mobile",
+   "fieldtype": "Small Text",
+   "hidden": 1,
+   "label": "Mobile No",
+   "read_only": 1
+  },
+  {
+   "fieldname": "contact_email",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Contact Email",
+   "options": "Email",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "territory",
+   "fieldtype": "Link",
+   "label": "Territory",
+   "options": "Territory",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "col_break4",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "shipping_address_name",
+   "fieldtype": "Link",
+   "label": "Shipping Address Name",
+   "options": "Address",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "shipping_address",
+   "fieldtype": "Small Text",
+   "label": "Shipping Address",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "company_address",
+   "fieldtype": "Link",
+   "label": "Company Address Name",
+   "options": "Address",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "company_address_display",
+   "fieldtype": "Small Text",
+   "hidden": 1,
+   "label": "Company Address",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "collapsible": 1,
+   "depends_on": "customer",
+   "fieldname": "currency_and_price_list",
+   "fieldtype": "Section Break",
+   "label": "Currency and Price List"
+  },
+  {
+   "fieldname": "currency",
+   "fieldtype": "Link",
+   "label": "Currency",
+   "oldfieldname": "currency",
+   "oldfieldtype": "Select",
+   "options": "Currency",
+   "print_hide": 1,
+   "reqd": 1
+  },
+  {
+   "description": "Rate at which Customer Currency is converted to customer's base currency",
+   "fieldname": "conversion_rate",
+   "fieldtype": "Float",
+   "label": "Exchange Rate",
+   "oldfieldname": "conversion_rate",
+   "oldfieldtype": "Currency",
+   "precision": "9",
+   "print_hide": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "column_break2",
+   "fieldtype": "Column Break",
+   "width": "50%"
+  },
+  {
+   "fieldname": "selling_price_list",
+   "fieldtype": "Link",
+   "label": "Price List",
+   "oldfieldname": "price_list_name",
+   "oldfieldtype": "Select",
+   "options": "Price List",
+   "print_hide": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "price_list_currency",
+   "fieldtype": "Link",
+   "label": "Price List Currency",
+   "options": "Currency",
+   "print_hide": 1,
+   "read_only": 1,
+   "reqd": 1
+  },
+  {
+   "description": "Rate at which Price list currency is converted to customer's base currency",
+   "fieldname": "plc_conversion_rate",
+   "fieldtype": "Float",
+   "label": "Price List Exchange Rate",
+   "precision": "9",
+   "print_hide": 1,
+   "reqd": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "ignore_pricing_rule",
+   "fieldtype": "Check",
+   "label": "Ignore Pricing Rule",
+   "no_copy": 1,
+   "permlevel": 1,
+   "print_hide": 1
+  },
+  {
+   "fieldname": "sec_warehouse",
+   "fieldtype": "Section Break"
+  },
+  {
+   "depends_on": "update_stock",
+   "fieldname": "set_warehouse",
+   "fieldtype": "Link",
+   "label": "Set Source Warehouse",
+   "options": "Warehouse",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "items_section",
+   "fieldtype": "Section Break",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-shopping-cart"
+  },
+  {
+   "default": "0",
+   "fieldname": "update_stock",
+   "fieldtype": "Check",
+   "label": "Update Stock",
+   "oldfieldname": "update_stock",
+   "oldfieldtype": "Check",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "scan_barcode",
+   "fieldtype": "Data",
+   "label": "Scan Barcode"
+  },
+  {
+   "allow_bulk_edit": 1,
+   "fieldname": "items",
+   "fieldtype": "Table",
+   "label": "Items",
+   "oldfieldname": "entries",
+   "oldfieldtype": "Table",
+   "options": "Sales Invoice Item",
+   "reqd": 1
+  },
+  {
+   "fieldname": "pricing_rule_details",
+   "fieldtype": "Section Break",
+   "label": "Pricing Rules"
+  },
+  {
+   "fieldname": "pricing_rules",
+   "fieldtype": "Table",
+   "label": "Pricing Rule Detail",
+   "options": "Pricing Rule Detail",
+   "read_only": 1
+  },
+  {
+   "fieldname": "packing_list",
+   "fieldtype": "Section Break",
+   "label": "Packing List",
+   "options": "fa fa-suitcase",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "packed_items",
+   "fieldtype": "Table",
+   "label": "Packed Items",
+   "options": "Packed Item",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "product_bundle_help",
+   "fieldtype": "HTML",
+   "label": "Product Bundle Help",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "eval:doc.total_billing_amount > 0",
+   "fieldname": "time_sheet_list",
+   "fieldtype": "Section Break",
+   "label": "Time Sheet List"
+  },
+  {
+   "fieldname": "timesheets",
+   "fieldtype": "Table",
+   "label": "Time Sheets",
+   "options": "Sales Invoice Timesheet",
+   "print_hide": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "total_billing_amount",
+   "fieldtype": "Currency",
+   "label": "Total Billing Amount",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "section_break_30",
+   "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "total_qty",
+   "fieldtype": "Float",
+   "label": "Total Quantity",
+   "read_only": 1
+  },
+  {
+   "fieldname": "base_total",
+   "fieldtype": "Currency",
+   "label": "Total (Company Currency)",
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "base_net_total",
+   "fieldtype": "Currency",
+   "label": "Net Total (Company Currency)",
+   "oldfieldname": "net_total",
+   "oldfieldtype": "Currency",
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "column_break_32",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "total",
+   "fieldtype": "Currency",
+   "label": "Total",
+   "options": "currency",
+   "read_only": 1
+  },
+  {
+   "fieldname": "net_total",
+   "fieldtype": "Currency",
+   "label": "Net Total",
+   "options": "currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "total_net_weight",
+   "fieldtype": "Float",
+   "label": "Total Net Weight",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "taxes_section",
+   "fieldtype": "Section Break",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-money"
+  },
+  {
+   "fieldname": "taxes_and_charges",
+   "fieldtype": "Link",
+   "label": "Sales Taxes and Charges Template",
+   "oldfieldname": "charge",
+   "oldfieldtype": "Link",
+   "options": "Sales Taxes and Charges Template",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break_38",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "shipping_rule",
+   "fieldtype": "Link",
+   "label": "Shipping Rule",
+   "oldfieldtype": "Button",
+   "options": "Shipping Rule",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "tax_category",
+   "fieldtype": "Link",
+   "label": "Tax Category",
+   "options": "Tax Category",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "section_break_40",
+   "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "taxes",
+   "fieldtype": "Table",
+   "label": "Sales Taxes and Charges",
+   "oldfieldname": "other_charges",
+   "oldfieldtype": "Table",
+   "options": "Sales Taxes and Charges"
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "sec_tax_breakup",
+   "fieldtype": "Section Break",
+   "label": "Tax Breakup"
+  },
+  {
+   "fieldname": "other_charges_calculation",
+   "fieldtype": "Text",
+   "label": "Taxes and Charges Calculation",
+   "no_copy": 1,
+   "oldfieldtype": "HTML",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "section_break_43",
+   "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "base_total_taxes_and_charges",
+   "fieldtype": "Currency",
+   "label": "Total Taxes and Charges (Company Currency)",
+   "oldfieldname": "other_charges_total",
+   "oldfieldtype": "Currency",
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_47",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "total_taxes_and_charges",
+   "fieldtype": "Currency",
+   "label": "Total Taxes and Charges",
+   "options": "currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "loyalty_points_redemption",
+   "fieldtype": "Section Break",
+   "label": "Loyalty Points Redemption"
+  },
+  {
+   "depends_on": "redeem_loyalty_points",
+   "fieldname": "loyalty_points",
+   "fieldtype": "Int",
+   "label": "Loyalty Points",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "depends_on": "redeem_loyalty_points",
+   "fieldname": "loyalty_amount",
+   "fieldtype": "Currency",
+   "label": "Loyalty Amount",
+   "no_copy": 1,
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "redeem_loyalty_points",
+   "fieldtype": "Check",
+   "label": "Redeem Loyalty Points",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break_77",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fetch_from": "customer.loyalty_program",
+   "fieldname": "loyalty_program",
+   "fieldtype": "Link",
+   "label": "Loyalty Program",
+   "no_copy": 1,
+   "options": "Loyalty Program",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "depends_on": "redeem_loyalty_points",
+   "fieldname": "loyalty_redemption_account",
+   "fieldtype": "Link",
+   "label": "Redemption Account",
+   "no_copy": 1,
+   "options": "Account"
+  },
+  {
+   "depends_on": "redeem_loyalty_points",
+   "fieldname": "loyalty_redemption_cost_center",
+   "fieldtype": "Link",
+   "label": "Redemption Cost Center",
+   "no_copy": 1,
+   "options": "Cost Center"
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "discount_amount",
+   "fieldname": "section_break_49",
+   "fieldtype": "Section Break",
+   "label": "Additional Discount"
+  },
+  {
+   "default": "Grand Total",
+   "fieldname": "apply_discount_on",
+   "fieldtype": "Select",
+   "label": "Apply Additional Discount On",
+   "options": "\nGrand Total\nNet Total",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "base_discount_amount",
+   "fieldtype": "Currency",
+   "label": "Additional Discount Amount (Company Currency)",
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_51",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "additional_discount_percentage",
+   "fieldtype": "Float",
+   "label": "Additional Discount Percentage",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "discount_amount",
+   "fieldtype": "Currency",
+   "label": "Additional Discount Amount",
+   "options": "currency",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "totals",
+   "fieldtype": "Section Break",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-money",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "base_grand_total",
+   "fieldtype": "Currency",
+   "label": "Grand Total (Company Currency)",
+   "oldfieldname": "grand_total",
+   "oldfieldtype": "Currency",
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "base_rounding_adjustment",
+   "fieldtype": "Currency",
+   "label": "Rounding Adjustment (Company Currency)",
+   "no_copy": 1,
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "base_rounded_total",
+   "fieldtype": "Currency",
+   "label": "Rounded Total (Company Currency)",
+   "oldfieldname": "rounded_total",
+   "oldfieldtype": "Currency",
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "description": "In Words will be visible once you save the Sales Invoice.",
+   "fieldname": "base_in_words",
+   "fieldtype": "Data",
+   "label": "In Words (Company Currency)",
+   "oldfieldname": "in_words",
+   "oldfieldtype": "Data",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break5",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break",
+   "print_hide": 1,
+   "width": "50%"
+  },
+  {
+   "bold": 1,
+   "fieldname": "grand_total",
+   "fieldtype": "Currency",
+   "in_list_view": 1,
+   "label": "Grand Total",
+   "oldfieldname": "grand_total_export",
+   "oldfieldtype": "Currency",
+   "options": "currency",
+   "read_only": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "rounding_adjustment",
+   "fieldtype": "Currency",
+   "label": "Rounding Adjustment",
+   "no_copy": 1,
+   "options": "currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "bold": 1,
+   "fieldname": "rounded_total",
+   "fieldtype": "Currency",
+   "label": "Rounded Total",
+   "oldfieldname": "rounded_total_export",
+   "oldfieldtype": "Currency",
+   "options": "currency",
+   "read_only": 1
+  },
+  {
+   "fieldname": "in_words",
+   "fieldtype": "Data",
+   "label": "In Words",
+   "oldfieldname": "in_words_export",
+   "oldfieldtype": "Data",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "total_advance",
+   "fieldtype": "Currency",
+   "label": "Total Advance",
+   "oldfieldname": "total_advance",
+   "oldfieldtype": "Currency",
+   "options": "party_account_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "outstanding_amount",
+   "fieldtype": "Currency",
+   "label": "Outstanding Amount",
+   "no_copy": 1,
+   "oldfieldname": "outstanding_amount",
+   "oldfieldtype": "Currency",
+   "options": "party_account_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "advances",
+   "fieldname": "advances_section",
+   "fieldtype": "Section Break",
+   "label": "Advance Payments",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-money",
+   "print_hide": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "allocate_advances_automatically",
+   "fieldtype": "Check",
+   "label": "Allocate Advances Automatically (FIFO)"
+  },
+  {
+   "depends_on": "eval:!doc.allocate_advances_automatically",
+   "fieldname": "get_advances",
+   "fieldtype": "Button",
+   "label": "Get Advances Received",
+   "options": "set_advances"
+  },
+  {
+   "fieldname": "advances",
+   "fieldtype": "Table",
+   "label": "Advances",
+   "oldfieldname": "advance_adjustment_details",
+   "oldfieldtype": "Table",
+   "options": "Sales Invoice Advance",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "eval:(!doc.is_pos && !doc.is_return)",
+   "fieldname": "payment_schedule_section",
+   "fieldtype": "Section Break",
+   "label": "Payment Terms"
+  },
+  {
+   "depends_on": "eval:(!doc.is_pos && !doc.is_return)",
+   "fieldname": "payment_terms_template",
+   "fieldtype": "Link",
+   "label": "Payment Terms Template",
+   "no_copy": 1,
+   "options": "Payment Terms Template",
+   "print_hide": 1
+  },
+  {
+   "depends_on": "eval:(!doc.is_pos && !doc.is_return)",
+   "fieldname": "payment_schedule",
+   "fieldtype": "Table",
+   "label": "Payment Schedule",
+   "no_copy": 1,
+   "options": "Payment Schedule",
+   "print_hide": 1
+  },
+  {
+   "depends_on": "eval:doc.is_pos===1||(doc.advances && doc.advances.length>0)",
+   "fieldname": "payments_section",
+   "fieldtype": "Section Break",
+   "label": "Payments",
+   "options": "fa fa-money"
+  },
+  {
+   "depends_on": "is_pos",
+   "fieldname": "cash_bank_account",
+   "fieldtype": "Link",
+   "hidden": 1,
+   "label": "Cash/Bank Account",
+   "oldfieldname": "cash_bank_account",
+   "oldfieldtype": "Link",
+   "options": "Account",
+   "print_hide": 1
+  },
+  {
+   "depends_on": "eval:doc.is_pos===1",
+   "fieldname": "payments",
+   "fieldtype": "Table",
+   "label": "Sales Invoice Payment",
+   "options": "Sales Invoice Payment",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "section_break_84",
+   "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "base_paid_amount",
+   "fieldtype": "Currency",
+   "label": "Paid Amount (Company Currency)",
+   "no_copy": 1,
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_86",
+   "fieldtype": "Column Break"
+  },
+  {
+   "depends_on": "eval: doc.is_pos || doc.redeem_loyalty_points",
+   "fieldname": "paid_amount",
+   "fieldtype": "Currency",
+   "label": "Paid Amount",
+   "no_copy": 1,
+   "oldfieldname": "paid_amount",
+   "oldfieldtype": "Currency",
+   "options": "currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "section_break_88",
+   "fieldtype": "Section Break"
+  },
+  {
+   "depends_on": "is_pos",
+   "fieldname": "base_change_amount",
+   "fieldtype": "Currency",
+   "label": "Base Change Amount (Company Currency)",
+   "no_copy": 1,
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_90",
+   "fieldtype": "Column Break"
+  },
+  {
+   "depends_on": "is_pos",
+   "fieldname": "change_amount",
+   "fieldtype": "Currency",
+   "label": "Change Amount",
+   "no_copy": 1,
+   "options": "currency",
+   "print_hide": 1
+  },
+  {
+   "depends_on": "is_pos",
+   "fieldname": "account_for_change_amount",
+   "fieldtype": "Link",
+   "label": "Account for Change Amount",
+   "options": "Account",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "write_off_amount",
+   "depends_on": "grand_total",
+   "fieldname": "column_break4",
+   "fieldtype": "Section Break",
+   "label": "Write Off",
+   "width": "50%"
+  },
+  {
+   "fieldname": "write_off_amount",
+   "fieldtype": "Currency",
+   "label": "Write Off Amount",
+   "no_copy": 1,
+   "options": "currency",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "base_write_off_amount",
+   "fieldtype": "Currency",
+   "label": "Write Off Amount (Company Currency)",
+   "no_copy": 1,
+   "options": "Company:company:default_currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "default": "0",
+   "depends_on": "is_pos",
+   "fieldname": "write_off_outstanding_amount_automatically",
+   "fieldtype": "Check",
+   "label": "Write Off Outstanding Amount",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break_74",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "write_off_account",
+   "fieldtype": "Link",
+   "label": "Write Off Account",
+   "options": "Account",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "write_off_cost_center",
+   "fieldtype": "Link",
+   "label": "Write Off Cost Center",
+   "options": "Cost Center",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "terms",
+   "fieldname": "terms_section_break",
+   "fieldtype": "Section Break",
+   "label": "Terms and Conditions",
+   "oldfieldtype": "Section Break"
+  },
+  {
+   "fieldname": "tc_name",
+   "fieldtype": "Link",
+   "label": "Terms",
+   "oldfieldname": "tc_name",
+   "oldfieldtype": "Link",
+   "options": "Terms and Conditions",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "terms",
+   "fieldtype": "Text Editor",
+   "label": "Terms and Conditions Details",
+   "oldfieldname": "terms",
+   "oldfieldtype": "Text Editor"
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "edit_printing_settings",
+   "fieldtype": "Section Break",
+   "label": "Printing Settings"
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "letter_head",
+   "fieldtype": "Link",
+   "label": "Letter Head",
+   "oldfieldname": "letter_head",
+   "oldfieldtype": "Select",
+   "options": "Letter Head",
+   "print_hide": 1
+  },
+  {
+   "allow_on_submit": 1,
+   "default": "0",
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
+   "label": "Group same items",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "language",
+   "fieldtype": "Data",
+   "label": "Print Language",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_84",
+   "fieldtype": "Column Break"
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "select_print_heading",
+   "fieldtype": "Link",
+   "label": "Print Heading",
+   "no_copy": 1,
+   "oldfieldname": "select_print_heading",
+   "oldfieldtype": "Link",
+   "options": "Print Heading",
+   "print_hide": 1,
+   "report_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "depends_on": "customer",
+   "fieldname": "more_information",
+   "fieldtype": "Section Break",
+   "label": "More Information"
+  },
+  {
+   "fieldname": "inter_company_invoice_reference",
+   "fieldtype": "Link",
+   "label": "Inter Company Invoice Reference",
+   "options": "Purchase Invoice",
+   "read_only": 1
+  },
+  {
+   "fieldname": "customer_group",
+   "fieldtype": "Link",
+   "hidden": 1,
+   "label": "Customer Group",
+   "options": "Customer Group",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "campaign",
+   "fieldtype": "Link",
+   "label": "Campaign",
+   "oldfieldname": "campaign",
+   "oldfieldtype": "Link",
+   "options": "Campaign",
+   "print_hide": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "is_discounted",
+   "fieldtype": "Check",
+   "label": "Is Discounted",
+   "no_copy": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "col_break23",
+   "fieldtype": "Column Break",
+   "width": "50%"
+  },
+  {
+   "default": "Draft",
+   "fieldname": "status",
+   "fieldtype": "Select",
+   "in_standard_filter": 1,
+   "label": "Status",
+   "no_copy": 1,
+   "options": "\nDraft\nReturn\nCredit Note Issued\nSubmitted\nPaid\nUnpaid\nUnpaid and Discounted\nOverdue and Discounted\nOverdue\nCancelled",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "source",
+   "fieldtype": "Link",
+   "label": "Source",
+   "oldfieldname": "source",
+   "oldfieldtype": "Select",
+   "options": "Lead Source",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "more_info",
+   "fieldtype": "Section Break",
+   "label": "Accounting Details",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-file-text",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "debit_to",
+   "fieldtype": "Link",
+   "label": "Debit To",
+   "oldfieldname": "debit_to",
+   "oldfieldtype": "Link",
+   "options": "Account",
+   "print_hide": 1,
+   "reqd": 1,
+   "search_index": 1
+  },
+  {
+   "fieldname": "party_account_currency",
+   "fieldtype": "Link",
+   "hidden": 1,
+   "label": "Party Account Currency",
+   "no_copy": 1,
+   "options": "Currency",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "default": "No",
+   "fieldname": "is_opening",
+   "fieldtype": "Select",
+   "label": "Is Opening Entry",
+   "oldfieldname": "is_opening",
+   "oldfieldtype": "Select",
+   "options": "No\nYes",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "c_form_applicable",
+   "fieldtype": "Select",
+   "label": "C-Form Applicable",
+   "no_copy": 1,
+   "options": "No\nYes",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "c_form_no",
+   "fieldtype": "Link",
+   "label": "C-Form No",
+   "no_copy": 1,
+   "options": "C-Form",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break8",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "remarks",
+   "fieldtype": "Small Text",
+   "label": "Remarks",
+   "no_copy": 1,
+   "oldfieldname": "remarks",
+   "oldfieldtype": "Text",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "sales_partner",
+   "fieldname": "sales_team_section_break",
+   "fieldtype": "Section Break",
+   "label": "Commission",
+   "oldfieldtype": "Section Break",
+   "options": "fa fa-group",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "sales_partner",
+   "fieldtype": "Link",
+   "label": "Sales Partner",
+   "oldfieldname": "sales_partner",
+   "oldfieldtype": "Link",
+   "options": "Sales Partner",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break10",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break",
+   "print_hide": 1,
+   "width": "50%"
+  },
+  {
+   "fieldname": "commission_rate",
+   "fieldtype": "Float",
+   "label": "Commission Rate (%)",
+   "oldfieldname": "commission_rate",
+   "oldfieldtype": "Currency",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "total_commission",
+   "fieldtype": "Currency",
+   "label": "Total Commission",
+   "oldfieldname": "total_commission",
+   "oldfieldtype": "Currency",
+   "options": "Company:company:default_currency",
+   "print_hide": 1
+  },
+  {
+   "collapsible": 1,
+   "collapsible_depends_on": "sales_team",
+   "fieldname": "section_break2",
+   "fieldtype": "Section Break",
+   "label": "Sales Team",
+   "print_hide": 1
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "sales_team",
+   "fieldtype": "Table",
+   "label": "Sales Team1",
+   "oldfieldname": "sales_team",
+   "oldfieldtype": "Table",
+   "options": "Sales Team",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "subscription_section",
+   "fieldtype": "Section Break",
+   "label": "Subscription Section"
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "from_date",
+   "fieldtype": "Date",
+   "label": "From Date",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "to_date",
+   "fieldtype": "Date",
+   "label": "To Date",
+   "no_copy": 1,
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break_140",
+   "fieldtype": "Column Break"
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "auto_repeat",
+   "fieldtype": "Link",
+   "label": "Auto Repeat",
+   "no_copy": 1,
+   "options": "Auto Repeat",
+   "print_hide": 1,
+   "read_only": 1
+  },
+  {
+   "allow_on_submit": 1,
+   "depends_on": "eval: doc.auto_repeat",
+   "fieldname": "update_auto_repeat_reference",
+   "fieldtype": "Button",
+   "label": "Update Auto Repeat Reference"
+  },
+  {
+   "fieldname": "against_income_account",
+   "fieldtype": "Small Text",
+   "hidden": 1,
+   "label": "Against Income Account",
+   "no_copy": 1,
+   "oldfieldname": "against_income_account",
+   "oldfieldtype": "Small Text",
+   "print_hide": 1,
+   "report_hide": 1
+  },
+  {
+   "fieldname": "pos_total_qty",
+   "fieldtype": "Float",
+   "hidden": 1,
+   "label": "Total Qty",
+   "print_hide": 1,
+   "print_hide_if_no_value": 1,
+   "read_only": 1
+  },
+  {
+   "collapsible": 1,
+   "fieldname": "accounting_dimensions_section",
+   "fieldtype": "Section Break",
+   "label": "Accounting Dimensions"
+  },
+  {
+   "fieldname": "dimension_col_break",
+   "fieldtype": "Column Break"
   }
+ ],
+ "icon": "fa fa-file-text",
+ "idx": 181,
+ "is_submittable": 1,
+ "modified": "2019-10-05 21:39:49.235990",
+ "modified_by": "Administrator",
+ "module": "Accounts",
+ "name": "Sales Invoice",
+ "name_case": "Title Case",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "amend": 1,
+   "cancel": 1,
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Accounts Manager",
+   "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "amend": 1,
+   "create": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Accounts User",
+   "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "permlevel": 1,
+   "read": 1,
+   "role": "Accounts Manager",
+   "write": 1
+  },
+  {
+   "permlevel": 1,
+   "read": 1,
+   "role": "All"
+  }
+ ],
+ "quick_entry": 1,
+ "search_fields": "posting_date, due_date, customer, base_grand_total, outstanding_amount",
+ "show_name_in_global_search": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "timeline_field": "customer",
+ "title_field": "title",
+ "track_changes": 1,
+ "track_seen": 1
+}
\ No newline at end of file
diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js
index 5e994b5..426caaa 100644
--- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js
+++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js
@@ -16,8 +16,8 @@
 			fieldname:"status",
 			label: __("Status"),
 			fieldtype: "Select",
-			options: "In Store\nDisposed",
-			default: 'In Store',
+			options: "In Location\nDisposed",
+			default: 'In Location',
 			reqd: 1
 		},
 		{
diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
index eac0e2a..2c9e48a 100644
--- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
+++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
@@ -101,7 +101,7 @@
 
 	# In Store assets are those that are not sold or scrapped
 	operand = 'not in'
-	if status not in 'In Store':
+	if status not in 'In Location':
 		operand = 'in'
 
 	conditions['status'] = (operand, ['Sold', 'Scrapped'])
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 31a78c3..1d4a25e 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -606,8 +606,13 @@
 
 					max_allowed_amt = flt(ref_amt * (100 + allowance) / 100)
 
+					if total_billed_amt < 0 and max_allowed_amt < 0:
+						# while making debit note against purchase return entry(purchase receipt) getting overbill error
+						total_billed_amt = abs(total_billed_amt)
+						max_allowed_amt = abs(max_allowed_amt)
+
 					if total_billed_amt - max_allowed_amt > 0.01:
-						frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set in Stock Settings")
+						frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings")
 							.format(item.item_code, item.idx, max_allowed_amt))
 
 	def get_company_default(self, fieldname):
@@ -1195,10 +1200,22 @@
 			child_item.rate = flt(d.get("rate"))
 
 		if flt(child_item.price_list_rate):
-			discount = flt((1 - flt(child_item.rate) / flt(child_item.price_list_rate)) * 100.0,
-				child_item.precision("discount_percentage"))
-			if discount > 0:
-				child_item.discount_percentage = discount
+			if flt(child_item.rate) > flt(child_item.price_list_rate):
+				#  if rate is greater than price_list_rate, set margin
+				#  or set discount
+				child_item.discount_percentage = 0
+				child_item.margin_type = "Amount"
+				child_item.margin_rate_or_amount = flt(child_item.rate - child_item.price_list_rate,
+					child_item.precision("margin_rate_or_amount"))
+				child_item.rate_with_margin = child_item.rate
+			else:
+				child_item.discount_percentage = flt((1 - flt(child_item.rate) / flt(child_item.price_list_rate)) * 100.0,
+					child_item.precision("discount_percentage"))
+				child_item.discount_amount = flt(
+					child_item.price_list_rate) - flt(child_item.rate)
+				child_item.margin_type = ""
+				child_item.margin_rate_or_amount = 0
+				child_item.rate_with_margin = 0
 
 		child_item.flags.ignore_validate_update_after_submit = True
 		if new_child_flag:
diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py
index 64d49b4..9d1389c 100644
--- a/erpnext/controllers/status_updater.py
+++ b/erpnext/controllers/status_updater.py
@@ -37,9 +37,9 @@
 	"Sales Order": [
 		["Draft", None],
 		["To Deliver and Bill", "eval:self.per_delivered < 100 and self.per_billed < 100 and self.docstatus == 1"],
-		["To Bill", "eval:self.per_delivered == 100 and self.per_billed < 100 and self.docstatus == 1"],
-		["To Deliver", "eval:self.per_delivered < 100 and self.per_billed == 100 and self.docstatus == 1"],
-		["Completed", "eval:self.per_delivered == 100 and self.per_billed == 100 and self.docstatus == 1"],
+		["To Bill", "eval:(self.per_delivered == 100 or self.skip_delivery_note) and self.per_billed < 100 and self.docstatus == 1"],
+		["To Deliver", "eval:self.per_delivered < 100 and self.per_billed == 100 and self.docstatus == 1 and not self.skip_delivery_note"],
+		["Completed", "eval:(self.per_delivered == 100 or self.skip_delivery_note) and self.per_billed == 100 and self.docstatus == 1"],
 		["Cancelled", "eval:self.docstatus==2"],
 		["Closed", "eval:self.status=='Closed'"],
 		["On Hold", "eval:self.status=='On Hold'"],
diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js
index ec17629..6e4d3ed 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.js
+++ b/erpnext/crm/doctype/opportunity/opportunity.js
@@ -100,6 +100,10 @@
 				});
 			}
 		}
+
+		if (frm.doc.opportunity_from && frm.doc.party_name && !frm.doc.contact_person) {
+			frm.trigger("party_name");
+		}
 	},
 
 	set_contact_link: function(frm) {
diff --git a/erpnext/hr/doctype/driver/driver.js b/erpnext/hr/doctype/driver/driver.js
index 6867892..b3c24c1 100644
--- a/erpnext/hr/doctype/driver/driver.js
+++ b/erpnext/hr/doctype/driver/driver.js
@@ -1,14 +1,36 @@
 // Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
 // For license information, please see license.txt
 
-frappe.ui.form.on('Driver', {
+frappe.ui.form.on("Driver", {
 	setup: function(frm) {
-		frm.set_query('transporter', function(){
+		frm.set_query("transporter", function() {
 			return {
 				filters: {
-					'is_transporter': 1
+					is_transporter: 1
 				}
 			};
 		});
+	},
+
+	refresh: function(frm) {
+		frm.set_query("address", function() {
+			return {
+				filters: {
+					is_your_company_address: !frm.doc.transporter ? 1 : 0
+				}
+			};
+		});
+	},
+
+	transporter: function(frm, cdt, cdn) {
+		// this assumes that supplier's address has same title as supplier's name
+		frappe.db
+			.get_doc("Address", null, { address_title: frm.doc.transporter })
+			.then(r => {
+				frappe.model.set_value(cdt, cdn, "address", r.name);
+			})
+			.catch(err => {
+				console.log(err);
+			});
 	}
 });
diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
index f3fc011..2e2a9ce 100644
--- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
+++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
@@ -4,6 +4,17 @@
 frappe.provide("erpnext.maintenance");
 
 frappe.ui.form.on('Maintenance Visit', {
+	refresh: function(frm) {
+		//filters for serial_no based on item_code
+		frm.set_query('serial_no', 'purposes', function(frm, cdt, cdn) {
+			let item = locals[cdt][cdn];
+			return {
+				filters: {
+					'item_code': item.item_code
+				}
+			};
+		});
+	},
 	setup: function(frm) {
 		frm.set_query('contact_person', erpnext.queries.contact_query);
 		frm.set_query('customer_address', erpnext.queries.address_query);
diff --git a/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json b/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json
index d2a0ffa..84dc72c 100644
--- a/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json
+++ b/erpnext/maintenance/doctype/maintenance_visit_purpose/maintenance_visit_purpose.json
@@ -1,348 +1,137 @@
 {
- "allow_copy": 0, 
- "allow_import": 0, 
- "allow_rename": 0, 
- "autoname": "hash", 
- "beta": 0, 
- "creation": "2013-02-22 01:28:06", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Document", 
- "editable_grid": 1, 
- "engine": "InnoDB", 
+ "autoname": "hash",
+ "creation": "2013-02-22 01:28:06",
+ "doctype": "DocType",
+ "document_type": "Document",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "item_code",
+  "item_name",
+  "serial_no",
+  "description",
+  "work_details",
+  "service_person",
+  "work_done",
+  "prevdoc_doctype",
+  "prevdoc_docname",
+  "prevdoc_detail_docname"
+ ],
  "fields": [
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "item_code", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Item Code", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "item_code", 
-   "oldfieldtype": "Link", 
-   "options": "Item", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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
-  }, 
+   "fieldname": "item_code",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Item Code",
+   "oldfieldname": "item_code",
+   "oldfieldtype": "Link",
+   "options": "Item"
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "item_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 1, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Item Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "item_name", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
+   "fetch_from": "item_code.item_name",
+   "fieldname": "item_name",
+   "fieldtype": "Data",
+   "in_global_search": 1,
+   "in_list_view": 1,
+   "label": "Item Name",
+   "oldfieldname": "item_name",
+   "oldfieldtype": "Data",
+   "read_only": 1
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "serial_no", 
-   "fieldtype": "Small Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Serial No", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "serial_no", 
-   "oldfieldtype": "Small Text", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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
-  }, 
+   "fieldname": "serial_no",
+   "fieldtype": "Link",
+   "label": "Serial No",
+   "oldfieldname": "serial_no",
+   "oldfieldtype": "Small Text",
+   "options": "Serial No"
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "description", 
-   "fieldtype": "Text Editor", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Description", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "description", 
-   "oldfieldtype": "Small Text", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "print_width": "300px", 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0, 
+   "fieldname": "description",
+   "fieldtype": "Text Editor",
+   "in_list_view": 1,
+   "label": "Description",
+   "oldfieldname": "description",
+   "oldfieldtype": "Small Text",
+   "print_width": "300px",
+   "reqd": 1,
    "width": "300px"
-  }, 
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "work_details", 
-   "fieldtype": "Section Break", 
-   "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": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "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
-  }, 
+   "fieldname": "work_details",
+   "fieldtype": "Section Break"
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "service_person", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Sales Person", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "service_person", 
-   "oldfieldtype": "Link", 
-   "options": "Sales Person", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "service_person",
+   "fieldtype": "Link",
+   "in_list_view": 1,
+   "label": "Sales Person",
+   "oldfieldname": "service_person",
+   "oldfieldtype": "Link",
+   "options": "Sales Person",
+   "reqd": 1
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "work_done", 
-   "fieldtype": "Small Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_global_search": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Work Done", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "work_done", 
-   "oldfieldtype": "Small Text", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
+   "fieldname": "work_done",
+   "fieldtype": "Small Text",
+   "in_list_view": 1,
+   "label": "Work Done",
+   "oldfieldname": "work_done",
+   "oldfieldtype": "Small Text",
+   "reqd": 1
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "prevdoc_doctype", 
-   "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": "Document Type", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "prevdoc_doctype", 
-   "oldfieldtype": "Data", 
-   "options": "DocType", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "print_width": "150px", 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 1, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0, 
+   "fieldname": "prevdoc_doctype",
+   "fieldtype": "Link",
+   "label": "Document Type",
+   "no_copy": 1,
+   "oldfieldname": "prevdoc_doctype",
+   "oldfieldtype": "Data",
+   "options": "DocType",
+   "print_hide": 1,
+   "print_width": "150px",
+   "read_only": 1,
+   "report_hide": 1,
    "width": "150px"
-  }, 
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "prevdoc_docname", 
-   "fieldtype": "Dynamic 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": "Against Document No", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "prevdoc_docname", 
-   "oldfieldtype": "Data", 
-   "options": "prevdoc_doctype", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "print_width": "160px", 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 1, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0, 
+   "fieldname": "prevdoc_docname",
+   "fieldtype": "Dynamic Link",
+   "label": "Against Document No",
+   "no_copy": 1,
+   "oldfieldname": "prevdoc_docname",
+   "oldfieldtype": "Data",
+   "options": "prevdoc_doctype",
+   "print_hide": 1,
+   "print_width": "160px",
+   "read_only": 1,
+   "report_hide": 1,
    "width": "160px"
-  }, 
+  },
   {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "prevdoc_detail_docname", 
-   "fieldtype": "Data", 
-   "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": "Against Document Detail No", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "prevdoc_detail_docname", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "print_width": "160px", 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 1, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0, 
+   "fieldname": "prevdoc_detail_docname",
+   "fieldtype": "Data",
+   "hidden": 1,
+   "label": "Against Document Detail No",
+   "no_copy": 1,
+   "oldfieldname": "prevdoc_detail_docname",
+   "oldfieldtype": "Data",
+   "print_hide": 1,
+   "print_width": "160px",
+   "read_only": 1,
+   "report_hide": 1,
    "width": "160px"
   }
- ], 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "idx": 1, 
- "image_view": 0, 
- "in_create": 0, 
-
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 1, 
- "max_attachments": 0, 
- "modified": "2017-02-17 17:06:11.910266", 
- "modified_by": "Administrator", 
- "module": "Maintenance", 
- "name": "Maintenance Visit Purpose", 
- "owner": "ashwini@webnotestech.com", 
- "permissions": [], 
- "quick_entry": 0, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "show_name_in_global_search": 0, 
- "track_changes": 1, 
- "track_seen": 0
+ ],
+ "idx": 1,
+ "istable": 1,
+ "modified": "2019-10-03 14:55:52.786805",
+ "modified_by": "Administrator",
+ "module": "Maintenance",
+ "name": "Maintenance Visit Purpose",
+ "owner": "ashwini@webnotestech.com",
+ "permissions": [],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
 }
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 04359e3..4dc98e7 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -558,7 +558,7 @@
 		item_filter += " and so_item.item_code = %(item)s"
 
 	open_so = frappe.db.sql("""
-		select distinct so.name, so.transaction_date, so.customer, so.base_grand_total
+		select distinct so.name, so.transaction_date, so.customer, so.base_grand_total as grand_total
 		from `tabSales Order` so, `tabSales Order Item` so_item
 		where so_item.parent = so.name
 			and so.docstatus = 1 and so.status not in ("Stopped", "Closed")
diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py
index 678e709..b57548e 100644
--- a/erpnext/manufacturing/doctype/work_order/work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/work_order.py
@@ -64,7 +64,8 @@
 				from `tabSales Order` so
 				inner join `tabSales Order Item` so_item on so_item.parent = so.name
 				left join `tabProduct Bundle Item` pk_item on so_item.item_code = pk_item.parent
-				where so.name=%s and so.docstatus = 1 and (
+				where so.name=%s and so.docstatus = 1
+					and so.skip_delivery_note  = 0 and (
 					so_item.item_code=%s or
 					pk_item.item_code=%s )
 			""", (self.sales_order, self.production_item, self.production_item), as_dict=1)
@@ -78,6 +79,7 @@
 					where so.name=%s
 						and so.name=so_item.parent
 						and so.name=packed_item.parent
+						and so.skip_delivery_note = 0
 						and so_item.item_code = packed_item.parent_item
 						and so.docstatus = 1 and packed_item.item_code=%s
 				""", (self.sales_order, self.production_item), as_dict=1)
@@ -477,6 +479,9 @@
 						'include_item_in_manufacturing': item.include_item_in_manufacturing
 					})
 
+					if not self.project:
+						self.project = item.get("project")
+
 			self.set_available_qty()
 
 	def update_transaferred_qty_for_required_items(self):
diff --git a/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py b/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py
index 9f4c445..412f320 100644
--- a/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py
+++ b/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py
@@ -41,7 +41,9 @@
 		item = frappe.get_doc("Item", item_code)
 		item.set("taxes", [])
 		item.append("taxes", {"item_tax_template": item_tax_template_name, "tax_category": ""})
-		item.save()
+		frappe.db.sql("delete from `tabItem Tax` where parent=%s and parenttype='Item'", item_code)
+		for d in item.taxes:
+			d.db_insert()
 
 	doctypes = [
 		'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice',
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index a9b19ed..5a2f3bc 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -1233,7 +1233,8 @@
 			"is_return": cint(me.frm.doc.is_return),
 			"update_stock": in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0,
 			"conversion_factor": me.frm.doc.conversion_factor,
-			"pos_profile": me.frm.doc.doctype == 'Sales Invoice' ? me.frm.doc.pos_profile : ''
+			"pos_profile": me.frm.doc.doctype == 'Sales Invoice' ? me.frm.doc.pos_profile : '',
+			"coupon_code": me.frm.doc.coupon_code
 		};
 	},
 
@@ -1742,6 +1743,15 @@
 				frappe.model.set_value(me.frm.doctype + " Item", item.name, "warehouse", me.frm.doc.set_warehouse);
 			});
 		}
+	},
+	coupon_code: function() {
+		var me = this;
+		frappe.run_serially([
+			() => this.frm.doc.ignore_pricing_rule=1,
+			() => me.ignore_pricing_rule(),
+			() => this.frm.doc.ignore_pricing_rule=0,
+			() => me.apply_pricing_rule()
+		]);
 	}
 });
 
diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js
index 5a05268..44a8cd0 100644
--- a/erpnext/public/js/shopping_cart.js
+++ b/erpnext/public/js/shopping_cart.js
@@ -5,6 +5,19 @@
 frappe.provide("erpnext.shopping_cart");
 var shopping_cart = erpnext.shopping_cart;
 
+var getParams = function (url) {
+	var params = [];
+	var parser = document.createElement('a');
+	parser.href = url;
+	var query = parser.search.substring(1);
+	var vars = query.split('&');
+	for (var i = 0; i < vars.length; i++) {
+		var pair = vars[i].split('=');
+		params[pair[0]] = decodeURIComponent(pair[1]);
+	}
+	return params;
+};
+
 frappe.ready(function() {
 	var full_name = frappe.session && frappe.session.user_fullname;
 	// update user
@@ -12,7 +25,32 @@
 		$('.navbar li[data-label="User"] a')
 			.html('<i class="fa fa-fixed-width fa fa-user"></i> ' + full_name);
 	}
+	// set coupon code and sales partner code
 
+	var url_args = getParams(window.location.href);
+
+	var referral_coupon_code = url_args['cc'];
+	var referral_sales_partner = url_args['sp'];
+
+	var d = new Date();
+	// expires within 30 minutes
+	d.setTime(d.getTime() + (0.02 * 24 * 60 * 60 * 1000));
+	var expires = "expires="+d.toUTCString();
+	if (referral_coupon_code) {
+		document.cookie = "referral_coupon_code=" + referral_coupon_code + ";" + expires + ";path=/";
+	}
+	if (referral_sales_partner) {
+		document.cookie = "referral_sales_partner=" + referral_sales_partner + ";" + expires + ";path=/";
+	}
+	referral_coupon_code=frappe.get_cookie("referral_coupon_code");
+	referral_sales_partner=frappe.get_cookie("referral_sales_partner");
+
+	if (referral_coupon_code && $(".tot_quotation_discount").val()==undefined ) {
+		$(".txtcoupon").val(referral_coupon_code);
+	}
+	if (referral_sales_partner) {
+		$(".txtreferral_sales_partner").val(referral_sales_partner);
+	}
 	// update login
 	shopping_cart.show_shoppingcart_dropdown();
 	shopping_cart.set_cart_count();
diff --git a/erpnext/regional/india/address_template.html b/erpnext/regional/india/address_template.html
index 1bcc5ad..55cc9af 100644
--- a/erpnext/regional/india/address_template.html
+++ b/erpnext/regional/india/address_template.html
@@ -1,6 +1,6 @@
 {{ address_line1 }}<br>{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}{{ city }}<br>
-{% if gst_state %}{{ gst_state }}{% endif -%},
-{% if gst_state_number %}State Code: {{ gst_state_number }}<br>{% endif -%}
+{% if gst_state %}{{ gst_state }}{% endif -%}
+{% if gst_state_number %}, State Code: {{ gst_state_number }}<br>{% endif -%}
 {% if pincode %}PIN: {{ pincode }}<br>{% endif -%}
 {{ country }}<br>
 {% if phone %}Phone: {{ phone }}<br>{% endif -%}
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 12f3260..fb5336b 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -23,6 +23,9 @@
 	refresh: function(frm) {
 		frm.trigger("set_label");
 		frm.trigger("set_dynamic_field_label");
+		if (frm.doc.quotation_to && frm.doc.party_name && !frm.doc.contact_person) {
+			frm.trigger("party_name");
+		}
 	},
 
 	quotation_to: function(frm) {
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 1b89545..ea04715 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -1904,7 +1904,7 @@
      "in_global_search": 0,
      "in_list_view": 0,
      "in_standard_filter": 0,
-     "label": "Additional Discount",
+     "label": "Additional Discount and Coupon Code",
      "length": 0,
      "no_copy": 0,
      "permlevel": 0,
@@ -1921,6 +1921,74 @@
      "unique": 0
     },
     {
+     "allow_bulk_edit": 0, 
+     "allow_in_quick_entry": 0, 
+     "allow_on_submit": 0, 
+     "bold": 0, 
+     "collapsible": 0, 
+     "columns": 0, 
+     "fetch_if_empty": 0, 
+     "fieldname": "coupon_code", 
+     "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": "Coupon Code", 
+     "length": 0, 
+     "no_copy": 0, 
+     "options": "Coupon Code", 
+     "permlevel": 0, 
+     "precision": "", 
+     "print_hide": 0, 
+     "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, 
+     "translatable": 0, 
+     "unique": 0
+    },
+    {
+     "allow_bulk_edit": 0, 
+     "allow_in_quick_entry": 0, 
+     "allow_on_submit": 0, 
+     "bold": 0, 
+     "collapsible": 0, 
+     "columns": 0, 
+     "fetch_if_empty": 0, 
+     "fieldname": "referral_sales_partner", 
+     "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": "Referral Sales Partner", 
+     "length": 0, 
+     "no_copy": 0, 
+     "options": "Sales Partner", 
+     "permlevel": 0, 
+     "precision": "", 
+     "print_hide": 0, 
+     "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, 
+     "translatable": 0, 
+     "unique": 0
+    },
+    {
      "allow_bulk_edit": 0,
      "allow_in_quick_entry": 0,
      "allow_on_submit": 0,
@@ -3263,7 +3331,7 @@
    "istable": 0,
    "max_attachments": 1,
    "menu_index": 0,
-   "modified": "2019-06-26 01:00:21.545591",
+   "modified": "2019-10-14 01:00:21.545591",
    "modified_by": "Administrator",
    "module": "Selling",
    "name": "Quotation",
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 46009f4..4a56e40 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -142,6 +142,9 @@
 		if customer:
 			target.customer = customer.name
 			target.customer_name = customer.customer_name
+		if source.referral_sales_partner:
+			target.sales_partner=source.referral_sales_partner
+			target.commission_rate=frappe.get_value('Sales Partner', source.referral_sales_partner, 'commission_rate')
 		target.ignore_pricing_rule = 1
 		target.flags.ignore_permissions = ignore_permissions
 		target.run_method("set_missing_values")
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index d6fd8a1..a2b8544 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -136,7 +136,8 @@
 			if(doc.status !== 'Closed') {
 				if(doc.status !== 'On Hold') {
 
-					allow_delivery = this.frm.doc.items.some(item => item.delivered_by_supplier === 0 && item.qty > flt(item.delivered_qty))
+					allow_delivery = this.frm.doc.items.some(item => item.delivered_by_supplier === 0 && item.qty > flt(item.delivered_qty)) 
+						&& !this.frm.doc.skip_delivery_note
 
 					if (this.frm.has_perm("submit")) {
 						if(flt(doc.per_delivered, 6) < 100 || flt(doc.per_billed) < 100) {
@@ -341,7 +342,7 @@
 	},
 
 	order_type: function() {
-		this.frm.fields_dict.items.grid.toggle_reqd("delivery_date", this.frm.doc.order_type == "Sales");
+		this.toggle_delivery_date();
 	},
 
 	tc_name: function() {
@@ -355,6 +356,15 @@
 		})
 	},
 
+	skip_delivery_note: function() {
+		this.toggle_delivery_date();
+	},
+
+	toggle_delivery_date: function() {
+		this.frm.fields_dict.items.grid.toggle_reqd("delivery_date", 
+			(this.frm.doc.order_type == "Sales" && !this.frm.doc.skip_delivery_note));
+	},
+
 	make_raw_material_request: function() {
 		var me = this;
 		this.frm.call({
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index cd6965a..78e7b4a 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -14,6 +14,7 @@
   "customer",
   "customer_name",
   "order_type",
+  "skip_delivery_note",
   "column_break1",
   "amended_from",
   "company",
@@ -78,6 +79,7 @@
   "loyalty_points",
   "loyalty_amount",
   "section_break_48",
+  "coupon_code",
   "apply_discount_on",
   "base_discount_amount",
   "column_break_50",
@@ -252,6 +254,7 @@
   },
   {
    "allow_on_submit": 1,
+   "depends_on": "eval:!doc.skip_delivery_note",
    "fieldname": "delivery_date",
    "fieldtype": "Date",
    "in_list_view": 1,
@@ -676,7 +679,13 @@
    "collapsible_depends_on": "discount_amount",
    "fieldname": "section_break_48",
    "fieldtype": "Section Break",
-   "label": "Additional Discount"
+   "label": "Additional Discount and Coupon Code"
+  },
+  {
+    "fieldname": "coupon_code",
+    "fieldtype": "Link",
+    "label": "Coupon Code",
+    "options": "Coupon Code"
   },
   {
    "default": "Grand Total",
@@ -1023,7 +1032,7 @@
    "print_hide": 1
   },
   {
-   "depends_on": "eval:!doc.__islocal",
+   "depends_on": "eval:!doc.__islocal && !doc.skip_delivery_note_creation",
    "description": "% of materials delivered against this Sales Order",
    "fieldname": "per_delivered",
    "fieldtype": "Percent",
@@ -1171,12 +1180,19 @@
    "fieldtype": "Data",
    "label": "Phone",
    "read_only": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "skip_delivery_note",
+   "fieldtype": "Check",
+   "label": "Skip Delivery Note",
+   "print_hide": 1
   }
  ],
  "icon": "fa fa-file-text",
  "idx": 105,
  "is_submittable": 1,
- "modified": "2019-09-27 14:23:52.233323",
+ "modified": "2019-10-14 08:46:07.540565",
  "modified_by": "Administrator",
  "module": "Selling",
  "name": "Sales Order",
@@ -1253,4 +1269,4 @@
  "title_field": "title",
  "track_changes": 1,
  "track_seen": 1
-}
\ No newline at end of file
+}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index e60be5a..af78ab2 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -46,6 +46,10 @@
 		self.validate_serial_no_based_delivery()
 		validate_inter_company_party(self.doctype, self.customer, self.company, self.inter_company_order_reference)
 
+		if self.coupon_code:
+			from erpnext.accounts.doctype.pricing_rule.utils import validate_coupon_code
+			validate_coupon_code(self.coupon_code)
+
 		from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
 		make_packing_list(self)
 
@@ -57,13 +61,13 @@
 
 	def validate_po(self):
 		# validate p.o date v/s delivery date
-		if self.po_date:
+		if self.po_date and not self.skip_delivery_note:
 			for d in self.get("items"):
 				if d.delivery_date and getdate(self.po_date) > getdate(d.delivery_date):
 					frappe.throw(_("Row #{0}: Expected Delivery Date cannot be before Purchase Order Date")
 						.format(d.idx))
 
-		if self.po_no and self.customer:
+		if self.po_no and self.customer and not self.skip_delivery_note:
 			so = frappe.db.sql("select name from `tabSales Order` \
 				where ifnull(po_no, '') = %s and name != %s and docstatus < 2\
 				and customer = %s", (self.po_no, self.name, self.customer))
@@ -100,7 +104,7 @@
 		super(SalesOrder, self).validate_order_type()
 
 	def validate_delivery_date(self):
-		if self.order_type == 'Sales':
+		if self.order_type == 'Sales' and not self.skip_delivery_note:
 			delivery_date_list = [d.delivery_date for d in self.get("items") if d.delivery_date]
 			max_delivery_date = max(delivery_date_list) if delivery_date_list else None
 			if not self.delivery_date:
@@ -177,6 +181,9 @@
 		self.update_blanket_order()
 
 		update_linked_doc(self.doctype, self.name, self.inter_company_order_reference)
+		if self.coupon_code:
+			from erpnext.accounts.doctype.pricing_rule.utils import update_coupon_code_count
+			update_coupon_code_count(self.coupon_code,'used')
 
 	def on_cancel(self):
 		super(SalesOrder, self).on_cancel()
@@ -195,7 +202,10 @@
 		self.update_blanket_order()
 
 		unlink_inter_company_doc(self.doctype, self.name, self.inter_company_order_reference)
-
+		if self.coupon_code:
+			from erpnext.accounts.doctype.pricing_rule.utils import update_coupon_code_count
+			update_coupon_code_count(self.coupon_code,'cancelled')
+			
 	def update_project(self):
 		if frappe.db.get_single_value('Selling Settings', 'sales_update_frequency') != "Each Transaction":
 			return
@@ -760,6 +770,7 @@
 		from
 			`tabSales Order`, `tabSales Order Item`
 		where `tabSales Order`.name = `tabSales Order Item`.parent
+			and `tabSales Order`.skip_delivery_note = 0
 			and (ifnull(`tabSales Order Item`.delivery_date, '0000-00-00')!= '0000-00-00') \
 			and (`tabSales Order Item`.delivery_date between %(start)s and %(end)s)
 			and `tabSales Order`.docstatus < 2
diff --git a/erpnext/selling/doctype/sales_order/sales_order_list.js b/erpnext/selling/doctype/sales_order/sales_order_list.js
index 301ecde..26d96d5 100644
--- a/erpnext/selling/doctype/sales_order/sales_order_list.js
+++ b/erpnext/selling/doctype/sales_order/sales_order_list.js
@@ -1,58 +1,41 @@
 frappe.listview_settings['Sales Order'] = {
 	add_fields: ["base_grand_total", "customer_name", "currency", "delivery_date",
-		"per_delivered", "per_billed", "status", "order_type", "name"],
+		"per_delivered", "per_billed", "status", "order_type", "name", "skip_delivery_note"],
 	get_indicator: function (doc) {
 		if (doc.status === "Closed") {
+			// Closed
 			return [__("Closed"), "green", "status,=,Closed"];
-
 		} else if (doc.status === "On Hold") {
 			// on hold
 			return [__("On Hold"), "orange", "status,=,On Hold"];
-		} else if (doc.order_type !== "Maintenance"
-			&& flt(doc.per_delivered, 6) < 100 && frappe.datetime.get_diff(doc.delivery_date) < 0) {
+		} else if (doc.status === "Completed") {
+			return [__("Completed"), "green", "status,=,Completed"];
+		} else if (!doc.skip_delivery_note && flt(doc.per_delivered, 6) < 100) {
+			if (frappe.datetime.get_diff(doc.delivery_date) < 0) {
 			// not delivered & overdue
-			return [__("Overdue"), "red", "per_delivered,<,100|delivery_date,<,Today|status,!=,Closed"];
-
-		} else if (doc.order_type !== "Maintenance"
-			&& flt(doc.per_delivered, 6) < 100 && doc.status !== "Closed") {
-			// not delivered
-
-			if (flt(doc.grand_total) === 0) {
+				return [__("Overdue"), "red",
+					"per_delivered,<,100|delivery_date,<,Today|status,!=,Closed"];
+			} else if (flt(doc.grand_total) === 0) {
 				// not delivered (zero-amount order)
-
 				return [__("To Deliver"), "orange",
 					"per_delivered,<,100|grand_total,=,0|status,!=,Closed"];
 			} else if (flt(doc.per_billed, 6) < 100) {
 				// not delivered & not billed
-
 				return [__("To Deliver and Bill"), "orange",
 					"per_delivered,<,100|per_billed,<,100|status,!=,Closed"];
 			} else {
 				// not billed
-
 				return [__("To Deliver"), "orange",
 					"per_delivered,<,100|per_billed,=,100|status,!=,Closed"];
 			}
-
-		} else if ((flt(doc.per_delivered, 6) === 100)
-			&& flt(doc.grand_total) !== 0 && flt(doc.per_billed, 6) < 100 && doc.status !== "Closed") {
+		} else if ((flt(doc.per_delivered, 6) === 100) && flt(doc.grand_total) !== 0
+			&& flt(doc.per_billed, 6) < 100) {
 			// to bill
-
-			return [__("To Bill"), "orange", "per_delivered,=,100|per_billed,<,100|status,!=,Closed"];
-
-		} else if ((flt(doc.per_delivered, 6) === 100)
-			&& (flt(doc.grand_total) === 0 || flt(doc.per_billed, 6) == 100) && doc.status !== "Closed") {
-			return [__("Completed"), "green", "per_delivered,=,100|per_billed,=,100|status,!=,Closed"];
-
-		}else if (doc.order_type === "Maintenance" && flt(doc.per_delivered, 6) < 100 && doc.status !== "Closed"){
-
-			if(flt(doc.per_billed, 6) < 100 ){
-				return [__("To Deliver and Bill"), "orange", "per_delivered,=,100|per_billed,<,100|status,!=,Closed"];
-			}else if(flt(doc.per_billed, 6) === 100){
-				return [__("To Deliver"), "orange", "per_delivered,=,100|per_billed,=,100|status,!=,Closed"];
-			}
+			return [__("To Bill"), "orange",
+				"per_delivered,=,100|per_billed,<,100|status,!=,Closed"];
+		} else if (doc.skip_delivery_note && flt(doc.per_billed, 6) < 100){
+			return [__("To Bill"), "orange", "per_billed,<,100|status,!=,Closed"];
 		}
-
 	},
 	onload: function(listview) {
 		var method = "erpnext.selling.doctype.sales_order.sales_order.close_or_unclose_sales_orders";
diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
index b94dce1..3fd1e64 100644
--- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json
+++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json
@@ -149,6 +149,7 @@
   },
   {
    "columns": 2,
+   "depends_on": "eval: !parent.skip_delivery_note",
    "fieldname": "delivery_date",
    "fieldtype": "Date",
    "in_list_view": 1,
@@ -693,6 +694,7 @@
    "description": "For Production",
    "fieldname": "produced_qty",
    "fieldtype": "Float",
+   "hidden": 1,
    "label": "Produced Quantity",
    "oldfieldname": "produced_qty",
    "oldfieldtype": "Currency",
@@ -743,7 +745,7 @@
  ],
  "idx": 1,
  "istable": 1,
- "modified": "2019-09-13 12:18:54.903107",
+ "modified": "2019-10-10 08:46:26.244823",
  "modified_by": "Administrator",
  "module": "Selling",
  "name": "Sales Order Item",
diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.js b/erpnext/selling/report/sales_analytics/sales_analytics.js
index 149c923..80874c1 100644
--- a/erpnext/selling/report/sales_analytics/sales_analytics.js
+++ b/erpnext/selling/report/sales_analytics/sales_analytics.js
@@ -80,10 +80,14 @@
 
 					var tree_type = frappe.query_report.filters[0].value;
 
-					if(tree_type == "Customer" || tree_type == "Item") {
+					if(tree_type == "Customer") {
 						row_values = data.slice(4,length-1).map(function (column) {
 							return column.content;
 						})
+					} else if (tree_type == "Item") {
+						row_values = data.slice(5,length-1).map(function (column) {
+							return column.content;
+						})
 					}
 					else {
 						row_values = data.slice(3,length-1).map(function (column) {
diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.py b/erpnext/selling/report/sales_analytics/sales_analytics.py
index 72767f0..f1726ab 100644
--- a/erpnext/selling/report/sales_analytics/sales_analytics.py
+++ b/erpnext/selling/report/sales_analytics/sales_analytics.py
@@ -136,7 +136,7 @@
 		if self.filters["value_quantity"] == 'Value':
 			value_field = 'base_amount'
 		else:
-			value_field = 'qty'
+			value_field = 'stock_qty'
 
 		self.entries = frappe.db.sql("""
 			select i.item_code as entity, i.item_name as entity_name, i.stock_uom, i.{value_field} as value_field, s.{date_field}
@@ -338,8 +338,10 @@
 	def get_chart_data(self):
 		length = len(self.columns)
 
-		if self.filters.tree_type in ["Customer", "Supplier", "Item"]:
+		if self.filters.tree_type in ["Customer", "Supplier"]:
 			labels = [d.get("label") for d in self.columns[2:length - 1]]
+		elif self.filters.tree_type == "Item":
+			labels = [d.get("label") for d in self.columns[3:length - 1]]
 		else:
 			labels = [d.get("label") for d in self.columns[1:length - 1]]
 		self.chart = {
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.js b/erpnext/setup/doctype/sales_partner/sales_partner.js
index 7164add..5656d43 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.js
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.js
@@ -24,5 +24,11 @@
 				}
 			}
 		};
+	},
+	referral_code:function(frm){
+		if (frm.doc.referral_code) {
+			frm.doc.referral_code=frm.doc.referral_code.toUpperCase();
+			frm.refresh_field('referral_code');
+		}
 	}
 });
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.json b/erpnext/setup/doctype/sales_partner/sales_partner.json
index 28cdd3e..0bf9d71 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.json
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.json
@@ -517,6 +517,73 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fetch_if_empty": 0, 
+   "fieldname": "column_break_16", 
+   "fieldtype": "Column Break", 
+   "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, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "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, 
+   "translatable": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "", 
+   "description": "To Track inbound purchase", 
+   "fetch_if_empty": 0, 
+   "fieldname": "referral_code", 
+   "fieldtype": "Data", 
+   "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": "Referral Code", 
+   "length": 8, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "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, 
+   "translatable": 0, 
+   "unique": 1
+  },
+  {
+   "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "depends_on": "show_in_website", 
    "fetch_if_empty": 0, 
    "fieldname": "section_break_17", 
@@ -779,7 +846,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2019-03-21 16:26:45.447265", 
+ "modified": "2019-10-14 16:26:45.447265", 
  "modified_by": "Administrator", 
  "module": "Setup", 
  "name": "Sales Partner", 
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index 40cb7c8..f850bc1 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -537,3 +537,29 @@
 
 def show_terms(doc):
 	return doc.tc_name
+
+@frappe.whitelist(allow_guest=True)
+def apply_coupon_code(applied_code,applied_referral_sales_partner):
+	quotation = True
+	if applied_code:
+		coupon_list=frappe.get_all('Coupon Code', filters={"docstatus": ("<", "2"), 'coupon_code':applied_code }, fields=['name'])
+		if coupon_list:
+			coupon_name=coupon_list[0].name
+			from erpnext.accounts.doctype.pricing_rule.utils import validate_coupon_code
+			validate_coupon_code(coupon_name)
+			quotation = _get_cart_quotation()
+			quotation.coupon_code=coupon_name
+			quotation.flags.ignore_permissions = True
+			quotation.save()
+			if applied_referral_sales_partner:
+				sales_partner_list=frappe.get_all('Sales Partner', filters={'docstatus': 0, 'referral_code':applied_referral_sales_partner }, fields=['name'])
+				if sales_partner_list:
+					sales_partner_name=sales_partner_list[0].name
+					quotation.referral_sales_partner=sales_partner_name
+					quotation.flags.ignore_permissions = True
+					quotation.save()
+		else:
+			frappe.throw(_("Please enter valid coupon code !!"))
+	else:
+		frappe.throw(_("Please enter coupon code !!"))
+	return quotation
\ No newline at end of file
diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json
index 8b9299e..e828f54 100644
--- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json
+++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json
@@ -276,6 +276,40 @@
      "unique": 0
     },
     {
+     "allow_bulk_edit": 0, 
+     "allow_in_quick_entry": 0, 
+     "allow_on_submit": 0, 
+     "bold": 0, 
+     "collapsible": 0, 
+     "columns": 0, 
+     "depends_on": "", 
+     "fetch_if_empty": 0, 
+     "fieldname": "show_apply_coupon_code_in_website", 
+     "fieldtype": "Check", 
+     "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": "Show Apply Coupon Code", 
+     "length": 0, 
+     "no_copy": 0, 
+     "permlevel": 0, 
+     "precision": "", 
+     "print_hide": 0, 
+     "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, 
+     "translatable": 0, 
+     "unique": 0
+    },
+    {
      "allow_bulk_edit": 0,
      "allow_in_quick_entry": 0,
      "allow_on_submit": 0,
@@ -679,7 +713,7 @@
    "issingle": 1,
    "istable": 0,
    "max_attachments": 0,
-   "modified": "2019-01-26 13:54:24.575322",
+   "modified": "2019-10-14 13:54:24.575322",
    "modified_by": "Administrator",
    "module": "Shopping Cart",
    "name": "Shopping Cart Settings",
diff --git a/erpnext/stock/doctype/delivery_trip/delivery_trip.json b/erpnext/stock/doctype/delivery_trip/delivery_trip.json
index 4a3709a..0a52624 100644
--- a/erpnext/stock/doctype/delivery_trip/delivery_trip.json
+++ b/erpnext/stock/doctype/delivery_trip/delivery_trip.json
@@ -166,12 +166,11 @@
    "fieldname": "driver_address",
    "fieldtype": "Link",
    "label": "Driver Address",
-   "options": "Address",
-   "read_only": 1
+   "options": "Address"
   }
  ],
  "is_submittable": 1,
- "modified": "2019-07-18 16:38:44.112651",
+ "modified": "2019-09-27 15:43:01.975139",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Delivery Trip",
diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
index d001a91..3f37093 100644
--- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
+++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
@@ -129,7 +129,7 @@
 
 			# update stock & gl entries for submit state of PR
 			doc.docstatus = 1
-			doc.update_stock_ledger(via_landed_cost_voucher=True)
+			doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True)
 			doc.make_gl_entries()
 
 	def update_rate_in_serial_no(self, receipt_document):
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index a09a3a8..831381c 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -7,7 +7,6 @@
 import frappe, json
 from frappe.utils import cstr, flt
 from erpnext.stock.get_item_details import get_item_details
-
 from frappe.model.document import Document
 
 class PackedItem(Document):
@@ -31,6 +30,10 @@
 	return det and det[0] or frappe._dict()
 
 def update_packing_list_item(doc, packing_item_code, qty, main_item_row, description):
+	if doc.amended_from:
+		old_packed_items_map = get_old_packed_item_details(doc.packed_items)
+	else:
+		old_packed_items_map = False
 	item = get_packing_item_details(packing_item_code, doc.company)
 
 	# check if exists
@@ -52,21 +55,23 @@
 	pi.qty = flt(qty)
 	if description and not pi.description:
 		pi.description = description
-	if not pi.warehouse:
+	if not pi.warehouse and not doc.amended_from:
 		pi.warehouse = (main_item_row.warehouse if ((doc.get('is_pos') or item.is_stock_item \
 			or not item.default_warehouse) and main_item_row.warehouse) else item.default_warehouse)
-
-	if not pi.batch_no:
+	if not pi.batch_no and not doc.amended_from:
 		pi.batch_no = cstr(main_item_row.get("batch_no"))
 	if not pi.target_warehouse:
 		pi.target_warehouse = main_item_row.get("target_warehouse")
 	bin = get_bin_qty(packing_item_code, pi.warehouse)
 	pi.actual_qty = flt(bin.get("actual_qty"))
 	pi.projected_qty = flt(bin.get("projected_qty"))
+	if old_packed_items_map:
+		pi.batch_no = old_packed_items_map.get((packing_item_code, main_item_row.item_code))[0].batch_no
+		pi.serial_no = old_packed_items_map.get((packing_item_code, main_item_row.item_code))[0].serial_no
+		pi.warehouse = old_packed_items_map.get((packing_item_code, main_item_row.item_code))[0].warehouse
 
 def make_packing_list(doc):
 	"""make packing list for Product Bundle item"""
-
 	if doc.get("_action") and doc._action == "update_after_submit": return
 
 	parent_items = []
@@ -113,3 +118,9 @@
 
 def on_doctype_update():
 	frappe.db.add_index("Packed Item", ["item_code", "warehouse"])
+
+def get_old_packed_item_details(old_packed_items):
+	old_packed_items_map = {}
+	for items in old_packed_items:
+		old_packed_items_map.setdefault((items.item_code ,items.parent_item), []).append(items.as_dict())
+	return old_packed_items_map
diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py
index b748e3f..cdf5fed 100644
--- a/erpnext/support/doctype/issue/issue.py
+++ b/erpnext/support/doctype/issue/issue.py
@@ -22,6 +22,7 @@
 		return "{0}: {1}".format(_(self.status), self.subject)
 
 	def validate(self):
+		self.flags.ignore_disabled = 1
 		if self.is_new() and self.via_customer_portal:
 			self.flags.create_communication = True
 
diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js
index 4c35dd0..456bc7e 100644
--- a/erpnext/templates/includes/cart.js
+++ b/erpnext/templates/includes/cart.js
@@ -20,6 +20,7 @@
 		shopping_cart.bind_change_qty();
 		shopping_cart.bind_change_notes();
 		shopping_cart.bind_dropdown_cart_buttons();
+		shopping_cart.bind_coupon_code();
 	},
 
 	bind_address_select: function() {
@@ -193,6 +194,29 @@
 				}
 			}
 		});
+	},
+
+	bind_coupon_code: function() {
+		$(".bt-coupon").on("click", function() {
+			shopping_cart.apply_coupon_code(this);
+		});
+	},
+
+	apply_coupon_code: function(btn) {
+		return frappe.call({
+			type: "POST",
+			method: "erpnext.shopping_cart.cart.apply_coupon_code",
+			btn: btn,
+			args : {
+				applied_code : $('.txtcoupon').val(),
+				applied_referral_sales_partner: $('.txtreferral_sales_partner').val()
+			},
+			callback: function(r) {
+				if (r && r.message){
+					location.reload();
+				}
+			}
+		});
 	}
 });
 
diff --git a/erpnext/templates/includes/cart/cart_address.html b/erpnext/templates/includes/cart/cart_address.html
index 2c90f8c..e857ce1 100644
--- a/erpnext/templates/includes/cart/cart_address.html
+++ b/erpnext/templates/includes/cart/cart_address.html
@@ -4,6 +4,16 @@
 	{% set select_address = True %}
 {% endif %}
 
+{% set show_coupon_code = frappe.db.get_single_value('Shopping Cart Settings', 'show_apply_coupon_code_in_website') %}
+{% if show_coupon_code == 1%}
+<div class="mb-3">
+	<div class="row no-gutters">
+		<input type="text" class="txtcoupon form-control mr-3 w-25" placeholder="Enter Coupon Code" name="txtcouponcode"  ></input>
+		<button class="btn btn-primary btn-sm  bt-coupon">{{ _("Apply Coupon Code") }}</button>
+		<input type="hidden" class="txtreferral_sales_partner" placeholder="Enter Sales Partner" name="txtreferral_sales_partner" type="text"></input>
+		</div>
+</div>
+{% endif %}
 <div class="mb-3" data-section="shipping-address">
 	<h6 class="text-uppercase">{{ _("Shipping Address") }}</h6>
 	<div class="row no-gutters" data-fieldname="shipping_address_name">
diff --git a/erpnext/templates/includes/order/order_taxes.html b/erpnext/templates/includes/order/order_taxes.html
index 1d26700..4a32aa4 100644
--- a/erpnext/templates/includes/order/order_taxes.html
+++ b/erpnext/templates/includes/order/order_taxes.html
@@ -22,6 +22,71 @@
 {% endif %}
 {% endfor %}
 
+{% if doc.doctype == 'Quotation' %}
+{% if doc.coupon_code %}
+<tr>
+	<th class="text-right" colspan="2">
+		{{ _("Discount") }}
+	</th>
+	<th class="text-right tot_quotation_discount">
+        {% set tot_quotation_discount = [] %}
+        {%- for item in doc.items -%}
+        {% if tot_quotation_discount.append((((item.price_list_rate * item.qty)
+            * item.discount_percentage) / 100)) %}{% endif %}
+         {% endfor %}
+         {{ frappe.utils.fmt_money((tot_quotation_discount | sum),currency=doc.currency) }}
+	</th>
+</tr>
+{% endif %}
+{% endif %}
+
+{% if doc.doctype == 'Sales Order' %}
+{% if doc.coupon_code %}
+<tr>
+	<th class="text-right" colspan="2">
+		{{ _("Total Amount") }}
+	</th>
+	<th class="text-right">
+        <span>
+        {% set total_amount = [] %}
+        {%- for item in doc.items -%}
+        {% if total_amount.append((item.price_list_rate * item.qty)) %}{% endif %}
+        {% endfor %}
+        {{ frappe.utils.fmt_money((total_amount | sum),currency=doc.currency) }}
+        </span>
+	</th>
+</tr>
+<tr>
+    <th class="text-right" colspan="2">
+        {{ _("Applied Coupon Code") }}
+    </th>
+    <th class="text-right">
+        <span>
+        {%- for row in frappe.get_all(doctype="Coupon Code",
+        fields=["coupon_code"], filters={ "name":doc.coupon_code}) -%}
+            <span>{{ row.coupon_code }}</span>
+        {% endfor %}
+        </span>
+    </th>
+</tr>
+<tr>
+    <th class="text-right" colspan="2">
+        {{ _("Discount") }}
+    </th>
+    <th class="text-right">
+        <span>
+        {% set tot_SO_discount = [] %}
+        {%- for item in doc.items -%}
+        {% if tot_SO_discount.append((((item.price_list_rate * item.qty)
+            * item.discount_percentage) / 100)) %}{% endif %}
+        {% endfor %}
+        {{ frappe.utils.fmt_money((tot_SO_discount | sum),currency=doc.currency) }}
+        </span>
+    </th>
+</tr>
+{% endif %}
+{% endif %}
+
 <tr>
 	<th class="text-right" colspan="2">
 		{{ _("Grand Total") }}
diff --git a/erpnext/utilities/web_form/addresses/addresses.json b/erpnext/utilities/web_form/addresses/addresses.json
index 1d3acc5..2f5e180 100644
--- a/erpnext/utilities/web_form/addresses/addresses.json
+++ b/erpnext/utilities/web_form/addresses/addresses.json
@@ -1,166 +1,196 @@
 {
- "accept_payment": 0, 
- "allow_comments": 0, 
- "allow_delete": 0, 
- "allow_edit": 1, 
- "allow_incomplete": 0, 
- "allow_multiple": 1, 
- "allow_print": 0, 
- "amount": 0.0, 
- "creation": "2016-06-24 15:50:33.196990", 
- "doc_type": "Address", 
- "docstatus": 0, 
- "doctype": "Web Form", 
- "idx": 0, 
- "is_standard": 1, 
- "login_required": 1, 
- "max_attachment_size": 0, 
- "modified": "2016-12-07 04:17:02.020768", 
- "modified_by": "Administrator", 
- "module": "Utilities", 
- "name": "addresses", 
- "owner": "Administrator", 
- "published": 1, 
- "route": "address", 
- "show_sidebar": 0, 
- "sidebar_items": [], 
- "success_url": "/addresses", 
- "title": "Address", 
+ "accept_payment": 0,
+ "allow_comments": 0,
+ "allow_delete": 0,
+ "allow_edit": 1,
+ "allow_incomplete": 0,
+ "allow_multiple": 1,
+ "allow_print": 0,
+ "amount": 0.0,
+ "amount_based_on_field": 0,
+ "creation": "2016-06-24 15:50:33.196990",
+ "doc_type": "Address",
+ "docstatus": 0,
+ "doctype": "Web Form",
+ "idx": 0,
+ "is_standard": 1,
+ "login_required": 1,
+ "max_attachment_size": 0,
+ "modified": "2019-10-15 06:55:30.405119",
+ "modified_by": "Administrator",
+ "module": "Utilities",
+ "name": "addresses",
+ "owner": "Administrator",
+ "published": 1,
+ "route": "address",
+ "route_to_success_link": 0,
+ "show_attachments": 0,
+ "show_in_grid": 0,
+ "show_sidebar": 0,
+ "sidebar_items": [],
+ "success_url": "/addresses",
+ "title": "Address",
  "web_form_fields": [
   {
-   "description": "", 
-   "fieldname": "address_title", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "Address Title", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "description": "",
+   "fieldname": "address_title",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "Address Title",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "address_type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "label": "Address Type", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther", 
-   "read_only": 0, 
-   "reqd": 1
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "address_type",
+   "fieldtype": "Select",
+   "hidden": 0,
+   "label": "Address Type",
+   "max_length": 0,
+   "max_value": 0,
+   "options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther",
+   "read_only": 0,
+   "reqd": 1,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "address_line1", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "Address Line 1", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 1
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "address_line1",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "Address Line 1",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 1,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "address_line2", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "Address Line 2", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "address_line2",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "Address Line 2",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "city", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "City/Town", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 1
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "city",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "City/Town",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 1,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "state", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "State", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "state",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "State",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "pincode", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "Postal Code", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "pincode",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "Postal Code",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "country", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "label": "Country", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "options": "Country", 
-   "read_only": 0, 
-   "reqd": 1
-  }, 
+   "allow_read_on_all_link_options": 1,
+   "fieldname": "country",
+   "fieldtype": "Link",
+   "hidden": 0,
+   "label": "Country",
+   "max_length": 0,
+   "max_value": 0,
+   "options": "Country",
+   "read_only": 0,
+   "reqd": 1,
+   "show_in_filter": 0
+  },
   {
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldtype": "Column Break",
+   "hidden": 0,
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "email_id", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "Email Address", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "email_id",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "Email Address",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "fieldname": "phone", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "label": "Phone", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 1
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "fieldname": "phone",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "label": "Phone",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 1,
+   "show_in_filter": 0
+  },
   {
-   "default": "0", 
-   "description": "", 
-   "fieldname": "is_primary_address", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "label": "Preferred Billing Address", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
-  }, 
+   "allow_read_on_all_link_options": 0,
+   "default": "0",
+   "description": "",
+   "fieldname": "is_primary_address",
+   "fieldtype": "Check",
+   "hidden": 0,
+   "label": "Preferred Billing Address",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
+  },
   {
-   "default": "0", 
-   "description": "", 
-   "fieldname": "is_shipping_address", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "label": "Preferred Shipping Address", 
-   "max_length": 0, 
-   "max_value": 0, 
-   "read_only": 0, 
-   "reqd": 0
+   "allow_read_on_all_link_options": 0,
+   "default": "0",
+   "description": "",
+   "fieldname": "is_shipping_address",
+   "fieldtype": "Check",
+   "hidden": 0,
+   "label": "Preferred Shipping Address",
+   "max_length": 0,
+   "max_value": 0,
+   "read_only": 0,
+   "reqd": 0,
+   "show_in_filter": 0
   }
  ]
 }
\ No newline at end of file