Merge pull request #4338 from anandpdoshi/fix/salary-slip-earning-deduction

[fix] pull earning and deduction on change of employee
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 1a90aab..4b359f7 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -28,7 +28,7 @@
 		self.validate_entries_for_advance()
 		self.validate_multi_currency()
 		self.set_amounts_in_company_currency()
-		self.validate_debit_and_credit()
+		self.validate_total_debit_and_credit()
 		self.validate_against_jv()
 		self.validate_reference_doc()
 		self.set_against_account()
@@ -252,7 +252,13 @@
 			if flt(d.debit > 0): d.against_account = ", ".join(list(set(accounts_credited)))
 			if flt(d.credit > 0): d.against_account = ", ".join(list(set(accounts_debited)))
 
-	def validate_debit_and_credit(self):
+	def validate_total_debit_and_credit(self):
+		self.set_total_debit_credit()
+		if self.difference:
+			frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
+				.format(self.difference))
+				
+	def set_total_debit_credit(self):
 		self.total_debit, self.total_credit, self.difference = 0, 0, 0
 		for d in self.get("accounts"):
 			if d.debit and d.credit:
@@ -264,10 +270,6 @@
 		self.difference = flt(self.total_debit, self.precision("total_debit")) - \
 			flt(self.total_credit, self.precision("total_credit"))
 
-		if self.difference:
-			frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
-				.format(self.difference))
-
 	def validate_multi_currency(self):
 		alternate_currency = []
 		for d in self.get("accounts"):
@@ -404,7 +406,7 @@
 					blank_row.debit_in_account_currency = abs(diff)
 					blank_row.debit = abs(diff)
 
-			self.validate_debit_and_credit()
+			self.validate_total_debit_and_credit()
 
 	def get_outstanding_invoices(self):
 		self.set('accounts', [])
@@ -432,7 +434,7 @@
 		elif self.write_off_based_on == 'Accounts Payable':
 			jd2.credit = total
 
-		self.validate_debit_and_credit()
+		self.validate_total_debit_and_credit()
 
 
 	def get_values(self):
@@ -562,11 +564,16 @@
 	if dt == "Sales Invoice":
 		party_type = "Customer"
 		party_account = ref_doc.debit_to
-		amount_field_party = "credit_in_account_currency"
-		amount_field_bank = "debit_in_account_currency"
 	else:
 		party_type = "Supplier"
 		party_account = ref_doc.credit_to
+		
+		
+	if (dt=="Sales Invoice" and ref_doc.outstanding_amount > 0) \
+		or (dt=="Purchase Invoice" and ref_doc.outstanding_amount < 0):
+			amount_field_party = "credit_in_account_currency"
+			amount_field_bank = "debit_in_account_currency"
+	else:
 		amount_field_party = "debit_in_account_currency"
 		amount_field_bank = "credit_in_account_currency"
 
@@ -576,7 +583,7 @@
 		"party_account_currency": ref_doc.party_account_currency,
 		"amount_field_party": amount_field_party,
 		"amount_field_bank": amount_field_bank,
-		"amount": ref_doc.outstanding_amount,
+		"amount": abs(ref_doc.outstanding_amount),
 		"remarks": 'Payment received against {0} {1}. {2}'.format(dt, dn, ref_doc.remarks),
 		"is_advance": "No"
 	})
@@ -601,7 +608,7 @@
 		"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"),
 		"account_currency": args.get("party_account_currency") or \
 			get_account_currency(args.get("party_account")),
-		"account_balance": get_balance_on(args.get("party_account")),
+		"balance": get_balance_on(args.get("party_account")),
 		"party_balance": get_balance_on(party=args.get("party"), party_type=args.get("party_type")),
 		"exchange_rate": exchange_rate,
 		args.get("amount_field_party"): args.get("amount"),
@@ -630,6 +637,7 @@
 			jv.multi_currency = 1
 
 	jv.set_amounts_in_company_currency()
+	jv.set_total_debit_credit()
 
 	return jv.as_dict()
 
diff --git a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py
index e827e48..36d54b6 100644
--- a/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py
+++ b/erpnext/accounts/doctype/mode_of_payment/mode_of_payment.py
@@ -5,6 +5,24 @@
 import frappe
 
 from frappe.model.document import Document
+from frappe import _
 
 class ModeofPayment(Document):
-	pass
+	def validate(self):
+		self.validate_accounts()
+		self.validate_repeating_companies()
+	
+	def validate_repeating_companies(self):
+		"""Error when Same Company is entered multiple times in accounts"""
+		accounts_list = []
+		for entry in self.accounts:
+			accounts_list.append(entry.company)
+
+		if len(accounts_list)!= len(set(accounts_list)):
+			frappe.throw(_("Same Company is entered more than once"))
+
+	def validate_accounts(self):
+		for entry in self.accounts:
+			"""Error when Company of Ledger account doesn't match with Company Selected"""
+			if frappe.db.get_value("Account", entry.default_account, "company") != entry.company:
+				frappe.throw(_("Account does not match with Company"))
diff --git a/erpnext/accounts/doctype/payment_tool/payment_tool.py b/erpnext/accounts/doctype/payment_tool/payment_tool.py
index aa7b127..d6629b6 100644
--- a/erpnext/accounts/doctype/payment_tool/payment_tool.py
+++ b/erpnext/accounts/doctype/payment_tool/payment_tool.py
@@ -8,6 +8,7 @@
 from frappe.model.document import Document
 import json
 from erpnext.accounts.utils import get_account_currency
+from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate
 
 class PaymentTool(Document):
 	def make_journal_entry(self):
@@ -19,7 +20,15 @@
 		jv.company = self.company
 		jv.cheque_no = self.reference_no
 		jv.cheque_date = self.reference_date
-
+		
+		party_account_currency, party_account_type = frappe.db.get_value("Account", self.party_account, 
+			["account_currency", "account_type"])
+		
+		bank_account_currency, bank_account_type = None, None
+		if self.payment_account:
+			bank_account_currency, bank_account_type = frappe.db.get_value("Account", self.payment_account, 
+				["account_currency", "account_type"])
+		
 		if not self.total_payment_amount:
 			frappe.throw(_("Please enter Payment Amount in atleast one row"))
 
@@ -27,27 +36,56 @@
 			if not frappe.db.get_value(v.against_voucher_type, {"name": v.against_voucher_no}):
 				frappe.throw(_("Row {0}: {1} is not a valid {2}").format(v.idx, v.against_voucher_no,
 					v.against_voucher_type))
-
+			
 			if v.payment_amount:
+				exchange_rate = get_exchange_rate(self.party_account, party_account_currency,
+					self.company, v.against_voucher_type, v.against_voucher_no)
+				
 				d1 = jv.append("accounts")
 				d1.account = self.party_account
 				d1.party_type = self.party_type
 				d1.party = self.party
+				d1.account_currency = party_account_currency
+				d1.account_type = party_account_type
 				d1.balance = get_balance_on(self.party_account)
+				d1.party_balance = get_balance_on(party=self.party, party_type=self.party_type)
+				d1.exchange_rate = exchange_rate
 				d1.set("debit_in_account_currency" if self.received_or_paid=="Paid" \
 					else "credit_in_account_currency", flt(v.payment_amount))
-				d1.set("reference_type", v.against_voucher_type)
-				d1.set("reference_name", v.against_voucher_no)
-				d1.set('is_advance', 'Yes' if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No')
-				total_payment_amount = flt(total_payment_amount) + \
-					flt(d1.debit_in_account_currency) - flt(d1.credit_in_account_currency)
+				d1.reference_type = v.against_voucher_type
+				d1.reference_name = v.against_voucher_no
+				d1.is_advance = 'Yes' \
+					if v.against_voucher_type in ['Sales Order', 'Purchase Order'] else 'No'
+					
+				amount = flt(d1.debit_in_account_currency) - flt(d1.credit_in_account_currency)
+				if bank_account_currency == party_account_currency:
+					total_payment_amount += amount
+				else:
+					total_payment_amount += amount*exchange_rate
 
 		d2 = jv.append("accounts")
-		d2.account = self.payment_account
-		d2.set('debit_in_account_currency' if total_payment_amount < 0 \
-			else 'credit_in_account_currency', abs(total_payment_amount))
 		if self.payment_account:
-			d2.balance = get_balance_on(self.payment_account)
+			bank_account_currency, bank_account_type = frappe.db.get_value("Account", self.payment_account, 
+				["account_currency", "account_type"])
+				
+			d2.account = self.payment_account
+			d2.account_currency = bank_account_currency
+			d2.account_type = bank_account_type
+			d2.exchange_rate = get_exchange_rate(self.payment_account, self.company)
+			d2.account_balance = get_balance_on(self.payment_account)
+		
+		amount_field_bank = 'debit_in_account_currency' if total_payment_amount < 0 \
+			else 'credit_in_account_currency'
+		
+		d2.set(amount_field_bank, abs(total_payment_amount))
+		
+		company_currency = frappe.db.get_value("Company", self.company, "default_currency")
+		if party_account_currency != company_currency or \
+			(bank_account_currency and bank_account_currency != company_currency):
+				jv.multi_currency = 1
+			
+		jv.set_amounts_in_company_currency()
+		jv.set_total_debit_credit()
 
 		return jv.as_dict()
 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index c8f96d3..12934a1 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -176,9 +176,10 @@
 					 throw(_("Purchse Order number required for Item {0}").format(d.item_code))
 
 	def pr_required(self):
+		stock_items = self.get_stock_items()
 		if frappe.db.get_value("Buying Settings", None, "pr_required") == 'Yes':
 			 for d in self.get('items'):
-				 if not d.purchase_receipt:
+				 if not d.purchase_receipt and d.item_code in stock_items:
 					 throw(_("Purchase Receipt number required for Item {0}").format(d.item_code))
 
 	def validate_write_off_account(self):
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 6abf1ba..b9dfec8 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -379,6 +379,8 @@
 				msgprint(_("Item Code required at Row No {0}").format(d.idx), raise_exception=True)
 
 	def validate_warehouse(self):
+		super(SalesInvoice, self).validate_warehouse()
+		
 		for d in self.get('items'):
 			if not d.warehouse:
 				frappe.throw(_("Warehouse required at Row No {0}").format(d.idx))
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index e1b01a1..74936da 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -18,9 +18,27 @@
 		var me = this;
 		this._super();
 		// this.frm.dashboard.reset();
+		var allow_receipt = false;
+		var is_drop_ship = false;
 
+		for (var i in cur_frm.doc.items) {
+			var item = cur_frm.doc.items[i];
+			if(item.delivered_by_supplier !== 1) {
+				allow_receipt = true;
+			}
+			
+			else {
+				is_drop_ship = true
+			}
+			
+			if(is_drop_ship && allow_receipt) {
+				break;
+			}
+		}
+		
+		cur_frm.set_df_property("drop_ship", "hidden", !is_drop_ship);
+		
 		if(doc.docstatus == 1 && !in_list(["Stopped", "Closed", "Delivered"], doc.status)) {
-
 			if (this.frm.has_perm("submit")) {
 				if(flt(doc.per_billed, 2) < 100 || doc.per_received < 100) {
 					cur_frm.add_custom_button(__('Stop'), this.stop_purchase_order);
@@ -29,7 +47,7 @@
 				cur_frm.add_custom_button(__('Close'), this.close_purchase_order);
 			}
 
-			if(doc.delivered_by_supplier && doc.status!="Delivered"){
+			if(is_drop_ship && doc.status!="Delivered"){
 				cur_frm.add_custom_button(__('Mark as Delivered'), this.delivered_by_supplier);
 			}
 
@@ -37,7 +55,12 @@
 				cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry);
 			}
 
-			if(flt(doc.per_received, 2) < 100 && this.frm.doc.__onload.has_stock_item) {
+		} else if(doc.docstatus===0) {
+			cur_frm.cscript.add_from_mappers();
+		} 
+		
+		if(doc.docstatus == 1 && !in_list(["Stopped", "Closed"], doc.status)) {
+			if(flt(doc.per_received, 2) < 100 && this.frm.doc.__onload.has_stock_item && allow_receipt) {
 				cur_frm.add_custom_button(__('Receive'), this.make_purchase_receipt).addClass("btn-primary");
 
 				if(doc.is_subcontracted==="Yes") {
@@ -47,13 +70,9 @@
 			}
 
 			if(flt(doc.per_billed, 2) < 100)
-				cur_frm.add_custom_button(__('Invoice'), this.make_purchase_invoice);
-
-
-		} else if(doc.docstatus===0) {
-			cur_frm.cscript.add_from_mappers();
+				cur_frm.add_custom_button(__('Invoice'), this.make_purchase_invoice);	
 		}
-
+		
 		if(doc.docstatus == 1 && in_list(["Stopped", "Closed", "Delivered"], doc.status)) {
 			if (this.frm.has_perm("submit")) {
 				cur_frm.add_custom_button(__('Re-open'), this.unstop_purchase_order);
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 0b03319..0b24d01 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -330,8 +330,8 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
-   "collapsible": 1, 
-   "collapsible_depends_on": "delivered_by_supplier", 
+   "collapsible": 0, 
+   "collapsible_depends_on": "", 
    "fieldname": "drop_ship", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -354,7 +354,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "depends_on": "delivered_by_supplier", 
+   "depends_on": "", 
    "fieldname": "customer", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -378,7 +378,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "depends_on": "delivered_by_supplier", 
+   "depends_on": "", 
    "fieldname": "customer_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -401,28 +401,6 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "delivered_by_supplier", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "To be delivered to customer", 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "read_only": 1, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
    "fieldname": "column_break_19", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -444,7 +422,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "depends_on": "delivered_by_supplier", 
+   "depends_on": "", 
    "fieldname": "customer_address", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -468,7 +446,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "depends_on": "delivered_by_supplier", 
+   "depends_on": "", 
    "fieldname": "customer_contact_person", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2283,7 +2261,7 @@
  "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
- "modified": "2015-11-04 04:44:22.025827", 
+ "modified": "2015-11-17 14:40:16.374394", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index d069bc0..4670e35 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -51,6 +51,7 @@
 		self.validate_for_subcontracting()
 		self.validate_minimum_order_qty()
 		self.create_raw_materials_supplied("supplied_items")
+		self.set_received_qty_and_billed_amount_for_drop_ship_items()
 
 	def validate_with_previous_doc(self):
 		super(PurchaseOrder, self).validate_with_previous_doc({
@@ -137,9 +138,11 @@
 		"""update requested qty (before ordered_qty is updated)"""
 		item_wh_list = []
 		for d in self.get("items"):
-			if (not po_item_rows or d.name in po_item_rows) and [d.item_code, d.warehouse] not in item_wh_list \
-					and frappe.db.get_value("Item", d.item_code, "is_stock_item") and d.warehouse:
-				item_wh_list.append([d.item_code, d.warehouse])
+			if (not po_item_rows or d.name in po_item_rows) \
+				and [d.item_code, d.warehouse] not in item_wh_list \
+				and frappe.db.get_value("Item", d.item_code, "is_stock_item") \
+				and d.warehouse and not d.delivered_by_supplier:
+					item_wh_list.append([d.item_code, d.warehouse])
 
 		for item_code, warehouse in item_wh_list:
 			update_bin_qty(item_code, warehouse, {
@@ -164,13 +167,13 @@
 		clear_doctype_notifications(self)
 
 	def on_submit(self):
-		if self.delivered_by_supplier == 1:
+		if self.has_drop_ship_item():
 			self.update_status_updater()
 
 		super(PurchaseOrder, self).on_submit()
 
 		purchase_controller = frappe.get_doc("Purchase Common")
-
+		
 		self.update_prevdoc_status()
 		self.update_requested_qty()
 		self.update_ordered_qty()
@@ -181,7 +184,7 @@
 		purchase_controller.update_last_purchase_rate(self, is_submit = 1)
 
 	def on_cancel(self):
-		if self.delivered_by_supplier == 1:
+		if self.has_drop_ship_item():
 			self.update_status_updater()
 
 		pc_obj = frappe.get_doc('Purchase Common')
@@ -234,7 +237,7 @@
 		"""Update delivered qty in Sales Order for drop ship"""
 		sales_orders_to_update = []
 		for item in self.items:
-			if item.prevdoc_doctype == "Sales Order":
+			if item.prevdoc_doctype == "Sales Order" and item.delivered_by_supplier == 1:	
 				if item.prevdoc_docname not in sales_orders_to_update:
 					sales_orders_to_update.append(item.prevdoc_docname)
 
@@ -244,6 +247,21 @@
 			so.set_status(update=True)
 			so.notify_update()
 
+	def has_drop_ship_item(self):
+		is_drop_ship = False
+		
+		for item in self.items:
+			if item.delivered_by_supplier == 1:
+				is_drop_ship = True
+		
+		return is_drop_ship
+	
+	def set_received_qty_and_billed_amount_for_drop_ship_items(self):
+		for item in self.items:
+			if item.delivered_by_supplier == 1:
+				item.received_qty = item.qty
+				item.billed_amt = item.amount
+
 @frappe.whitelist()
 def stop_or_unstop_purchase_orders(names, status):
 	if not frappe.has_permission("Purchase Order", "write"):
@@ -262,7 +280,6 @@
 
 	frappe.local.message_log = []
 
-
 def set_missing_values(source, target):
 	target.ignore_pricing_rule = 1
 	target.run_method("set_missing_values")
@@ -292,7 +309,7 @@
 				"parenttype": "prevdoc_doctype",
 			},
 			"postprocess": update_item,
-			"condition": lambda doc: doc.received_qty < doc.qty
+			"condition": lambda doc: doc.received_qty < doc.qty and doc.delivered_by_supplier!=1
 		},
 		"Purchase Taxes and Charges": {
 			"doctype": "Purchase Taxes and Charges",
@@ -328,7 +345,7 @@
 				"parent": "purchase_order",
 			},
 			"postprocess": update_item,
-			"condition": lambda doc: doc.base_amount==0 or doc.billed_amt < doc.amount
+			"condition": lambda doc: (doc.base_amount==0 or doc.billed_amt < doc.amount) and doc.delivered_by_supplier!=1
 		},
 		"Purchase Taxes and Charges": {
 			"doctype": "Purchase Taxes and Charges",
diff --git a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
index af08473..9855571 100755
--- a/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
+++ b/erpnext/buying/doctype/purchase_order_item/purchase_order_item.json
@@ -1,1214 +1,1236 @@
 {
- "allow_copy": 0,
- "allow_import": 0,
- "allow_rename": 0,
- "autoname": "hash",
- "creation": "2013-05-24 19:29:06",
- "custom": 0,
- "docstatus": 0,
- "doctype": "DocType",
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "autoname": "hash", 
+ "creation": "2013-05-24 19:29:06", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
  "fields": [
   {
-   "allow_on_submit": 0,
-   "bold": 1,
-   "collapsible": 0,
-   "fieldname": "item_code",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Item Code",
-   "no_copy": 0,
-   "oldfieldname": "item_code",
-   "oldfieldtype": "Link",
-   "options": "Item",
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 1,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "fieldname": "item_code", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Item Code", 
+   "no_copy": 0, 
+   "oldfieldname": "item_code", 
+   "oldfieldtype": "Link", 
+   "options": "Item", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 1, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "description": "",
-   "fieldname": "supplier_part_no",
-   "fieldtype": "Data",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Supplier Part Number",
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "description": "", 
+   "fieldname": "supplier_part_no", 
+   "fieldtype": "Data", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Supplier Part Number", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "item_name",
-   "fieldtype": "Data",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Item Name",
-   "no_copy": 0,
-   "oldfieldname": "item_name",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 1,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "item_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Item Name", 
+   "no_copy": 0, 
+   "oldfieldname": "item_name", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 1, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "column_break_4",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "column_break_4", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 1,
-   "collapsible": 0,
-   "fieldname": "schedule_date",
-   "fieldtype": "Date",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 1,
-   "label": "Reqd By Date",
-   "no_copy": 0,
-   "oldfieldname": "schedule_date",
-   "oldfieldtype": "Date",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 1,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "fieldname": "schedule_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "label": "Reqd By Date", 
+   "no_copy": 0, 
+   "oldfieldname": "schedule_date", 
+   "oldfieldtype": "Date", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 1, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 1,
-   "fieldname": "section_break_5",
-   "fieldtype": "Section Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Description",
-   "no_copy": 0,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 1, 
+   "fieldname": "section_break_5", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Description", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "description",
-   "fieldtype": "Text Editor",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Description",
-   "no_copy": 0,
-   "oldfieldname": "description",
-   "oldfieldtype": "Small Text",
-   "permlevel": 0,
-   "print_hide": 0,
-   "print_width": "300px",
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "description", 
+   "fieldtype": "Text Editor", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Description", 
+   "no_copy": 0, 
+   "oldfieldname": "description", 
+   "oldfieldtype": "Small Text", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_width": "300px", 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "300px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "col_break1",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "col_break1", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "image",
-   "fieldtype": "Attach",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Image",
-   "no_copy": 0,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "image", 
+   "fieldtype": "Attach", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Image", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "image_view",
-   "fieldtype": "Image",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Image View",
-   "no_copy": 0,
-   "options": "image",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "image_view", 
+   "fieldtype": "Image", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Image View", 
+   "no_copy": 0, 
+   "options": "image", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "quantity_and_rate",
-   "fieldtype": "Section Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Quantity and Rate",
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "quantity_and_rate", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Quantity and Rate", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 1,
-   "collapsible": 0,
-   "fieldname": "qty",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "Quantity",
-   "no_copy": 0,
-   "oldfieldname": "qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 0,
-   "print_width": "60px",
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "fieldname": "qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Quantity", 
+   "no_copy": 0, 
+   "oldfieldname": "qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_width": "60px", 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "60px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "stock_uom",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "Stock UOM",
-   "no_copy": 0,
-   "oldfieldname": "stock_uom",
-   "oldfieldtype": "Data",
-   "options": "UOM",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "stock_uom", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Stock UOM", 
+   "no_copy": 0, 
+   "oldfieldname": "stock_uom", 
+   "oldfieldtype": "Data", 
+   "options": "UOM", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "col_break2",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "col_break2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "uom",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "UOM",
-   "no_copy": 0,
-   "oldfieldname": "uom",
-   "oldfieldtype": "Link",
-   "options": "UOM",
-   "permlevel": 0,
-   "print_hide": 0,
-   "print_width": "100px",
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "uom", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "UOM", 
+   "no_copy": 0, 
+   "oldfieldname": "uom", 
+   "oldfieldtype": "Link", 
+   "options": "UOM", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_width": "100px", 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "conversion_factor",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "UOM Conversion Factor",
-   "no_copy": 0,
-   "oldfieldname": "conversion_factor",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "conversion_factor", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "UOM Conversion Factor", 
+   "no_copy": 0, 
+   "oldfieldname": "conversion_factor", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "sec_break1",
-   "fieldtype": "Section Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "sec_break1", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "price_list_rate",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Price List Rate",
-   "no_copy": 0,
-   "options": "currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "price_list_rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Price List Rate", 
+   "no_copy": 0, 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "depends_on": "price_list_rate",
-   "fieldname": "discount_percentage",
-   "fieldtype": "Percent",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "Discount on Price List Rate (%)",
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "depends_on": "price_list_rate", 
+   "fieldname": "discount_percentage", 
+   "fieldtype": "Percent", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Discount on Price List Rate (%)", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "col_break3",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "col_break3", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "base_price_list_rate",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Price List Rate (Company Currency)",
-   "no_copy": 0,
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "base_price_list_rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Price List Rate (Company Currency)", 
+   "no_copy": 0, 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "sec_break2",
-   "fieldtype": "Section Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "sec_break2", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 1,
-   "collapsible": 0,
-   "fieldname": "rate",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "Rate ",
-   "no_copy": 0,
-   "oldfieldname": "import_rate",
-   "oldfieldtype": "Currency",
-   "options": "currency",
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "fieldname": "rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Rate ", 
+   "no_copy": 0, 
+   "oldfieldname": "import_rate", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "amount",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "Amount",
-   "no_copy": 0,
-   "oldfieldname": "import_amount",
-   "oldfieldtype": "Currency",
-   "options": "currency",
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Amount", 
+   "no_copy": 0, 
+   "oldfieldname": "import_amount", 
+   "oldfieldtype": "Currency", 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "col_break4",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "col_break4", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "base_rate",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Rate (Company Currency)",
-   "no_copy": 0,
-   "oldfieldname": "purchase_rate",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "base_rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Rate (Company Currency)", 
+   "no_copy": 0, 
+   "oldfieldname": "purchase_rate", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "base_amount",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Amount (Company Currency)",
-   "no_copy": 0,
-   "oldfieldname": "amount",
-   "oldfieldtype": "Currency",
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 1,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "base_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Amount (Company Currency)", 
+   "no_copy": 0, 
+   "oldfieldname": "amount", 
+   "oldfieldtype": "Currency", 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "pricing_rule",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Pricing Rule",
-   "no_copy": 0,
-   "options": "Pricing Rule",
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "pricing_rule", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Pricing Rule", 
+   "no_copy": 0, 
+   "options": "Pricing Rule", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "section_break_29",
-   "fieldtype": "Section Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "section_break_29", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "net_rate",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Net Rate",
-   "no_copy": 0,
-   "options": "currency",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "net_rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Net Rate", 
+   "no_copy": 0, 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "net_amount",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Net Amount",
-   "no_copy": 0,
-   "options": "currency",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "net_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Net Amount", 
+   "no_copy": 0, 
+   "options": "currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "column_break_32",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "column_break_32", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "base_net_rate",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Net Rate (Company Currency)",
-   "no_copy": 0,
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "base_net_rate", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Net Rate (Company Currency)", 
+   "no_copy": 0, 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "base_net_amount",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Net Amount (Company Currency)",
-   "no_copy": 0,
-   "options": "Company:company:default_currency",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "base_net_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Net Amount (Company Currency)", 
+   "no_copy": 0, 
+   "options": "Company:company:default_currency", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "warehouse_and_reference",
-   "fieldtype": "Section Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Warehouse and Reference",
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "warehouse_and_reference", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Warehouse and Reference", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "warehouse",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 1,
-   "label": "Warehouse",
-   "no_copy": 0,
-   "oldfieldname": "warehouse",
-   "oldfieldtype": "Link",
-   "options": "Warehouse",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "warehouse", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "label": "Warehouse", 
+   "no_copy": 0, 
+   "oldfieldname": "warehouse", 
+   "oldfieldtype": "Link", 
+   "options": "Warehouse", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "project_name",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 0,
-   "label": "Project Name",
-   "no_copy": 0,
-   "options": "Project",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "project_name", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Project Name", 
+   "no_copy": 0, 
+   "options": "Project", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "prevdoc_doctype",
-   "fieldtype": "Link",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Reference Document Type",
-   "no_copy": 1,
-   "oldfieldname": "prevdoc_doctype",
-   "oldfieldtype": "Data",
-   "options": "DocType",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "prevdoc_doctype", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Reference Document Type", 
+   "no_copy": 1, 
+   "oldfieldname": "prevdoc_doctype", 
+   "oldfieldtype": "Data", 
+   "options": "DocType", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "prevdoc_docname",
-   "fieldtype": "Dynamic Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 0,
-   "label": "Reference Name",
-   "no_copy": 1,
-   "oldfieldname": "prevdoc_docname",
-   "oldfieldtype": "Link",
-   "options": "prevdoc_doctype",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "120px",
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 1,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "prevdoc_docname", 
+   "fieldtype": "Dynamic Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Reference Name", 
+   "no_copy": 1, 
+   "oldfieldname": "prevdoc_docname", 
+   "oldfieldtype": "Link", 
+   "options": "prevdoc_doctype", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "120px", 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 1, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "120px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "prevdoc_detail_docname",
-   "fieldtype": "Data",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 0,
-   "label": "Material Request Detail No",
-   "no_copy": 1,
-   "oldfieldname": "prevdoc_detail_docname",
-   "oldfieldtype": "Data",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 1,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "prevdoc_detail_docname", 
+   "fieldtype": "Data", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Material Request Detail No", 
+   "no_copy": 1, 
+   "oldfieldname": "prevdoc_detail_docname", 
+   "oldfieldtype": "Data", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 1, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "supplier_quotation",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Supplier Quotation",
-   "no_copy": 1,
-   "options": "Supplier Quotation",
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "supplier_quotation", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Supplier Quotation", 
+   "no_copy": 1, 
+   "options": "Supplier Quotation", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "supplier_quotation_item",
-   "fieldtype": "Link",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Supplier Quotation Item",
-   "no_copy": 1,
-   "options": "Supplier Quotation Item",
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "supplier_quotation_item", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Supplier Quotation Item", 
+   "no_copy": 1, 
+   "options": "Supplier Quotation Item", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "col_break5",
-   "fieldtype": "Column Break",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "no_copy": 0,
-   "permlevel": 0,
-   "print_hide": 0,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "delivered_by_supplier", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "To be delivered to customer", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "description": "",
-   "fieldname": "item_group",
-   "fieldtype": "Link",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 1,
-   "in_list_view": 0,
-   "label": "Item Group",
-   "no_copy": 0,
-   "oldfieldname": "item_group",
-   "oldfieldtype": "Link",
-   "options": "Item Group",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "col_break5", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "brand",
-   "fieldtype": "Link",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Brand",
-   "no_copy": 0,
-   "oldfieldname": "brand",
-   "oldfieldtype": "Link",
-   "options": "Brand",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "description": "", 
+   "fieldname": "item_group", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "label": "Item Group", 
+   "no_copy": 0, 
+   "oldfieldname": "item_group", 
+   "oldfieldtype": "Link", 
+   "options": "Item Group", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "bom",
-   "fieldtype": "Link",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "BOM",
-   "no_copy": 1,
-   "options": "BOM",
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "brand", 
+   "fieldtype": "Link", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Brand", 
+   "no_copy": 0, 
+   "oldfieldname": "brand", 
+   "oldfieldtype": "Link", 
+   "options": "Brand", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "stock_qty",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Qty as per Stock UOM",
-   "no_copy": 1,
-   "oldfieldname": "stock_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "print_width": "100px",
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
-   "unique": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "bom", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "BOM", 
+   "no_copy": 1, 
+   "options": "BOM", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "stock_qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Qty as per Stock UOM", 
+   "no_copy": 1, 
+   "oldfieldname": "stock_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_width": "100px", 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0, 
    "width": "100px"
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "received_qty",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Received Qty",
-   "no_copy": 1,
-   "oldfieldname": "received_qty",
-   "oldfieldtype": "Currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "received_qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Received Qty", 
+   "no_copy": 1, 
+   "oldfieldname": "received_qty", 
+   "oldfieldtype": "Currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "depends_on": "returned_qty",
-   "fieldname": "returned_qty",
-   "fieldtype": "Float",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Returned Qty",
-   "no_copy": 1,
-   "permlevel": 0,
-   "precision": "",
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "depends_on": "returned_qty", 
+   "fieldname": "returned_qty", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Returned Qty", 
+   "no_copy": 1, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "billed_amt",
-   "fieldtype": "Currency",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Billed Amt",
-   "no_copy": 1,
-   "options": "currency",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "billed_amt", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Billed Amt", 
+   "no_copy": 1, 
+   "options": "currency", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 0,
-   "bold": 0,
-   "collapsible": 0,
-   "description": "Tax detail table fetched from item master as a string and stored in this field.\nUsed for Taxes and Charges",
-   "fieldname": "item_tax_rate",
-   "fieldtype": "Small Text",
-   "hidden": 1,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Item Tax Rate",
-   "no_copy": 0,
-   "oldfieldname": "item_tax_rate",
-   "oldfieldtype": "Small Text",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 1,
-   "report_hide": 1,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "description": "Tax detail table fetched from item master as a string and stored in this field.\nUsed for Taxes and Charges", 
+   "fieldname": "item_tax_rate", 
+   "fieldtype": "Small Text", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Item Tax Rate", 
+   "no_copy": 0, 
+   "oldfieldname": "item_tax_rate", 
+   "oldfieldtype": "Small Text", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 1, 
+   "report_hide": 1, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
-  },
+  }, 
   {
-   "allow_on_submit": 1,
-   "bold": 0,
-   "collapsible": 0,
-   "fieldname": "page_break",
-   "fieldtype": "Check",
-   "hidden": 0,
-   "ignore_user_permissions": 0,
-   "in_filter": 0,
-   "in_list_view": 0,
-   "label": "Page Break",
-   "no_copy": 1,
-   "oldfieldname": "page_break",
-   "oldfieldtype": "Check",
-   "permlevel": 0,
-   "print_hide": 1,
-   "read_only": 0,
-   "report_hide": 0,
-   "reqd": 0,
-   "search_index": 0,
-   "set_only_once": 0,
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "fieldname": "page_break", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Page Break", 
+   "no_copy": 1, 
+   "oldfieldname": "page_break", 
+   "oldfieldtype": "Check", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "read_only": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
    "unique": 0
   }
- ],
- "hide_heading": 0,
- "hide_toolbar": 0,
- "idx": 1,
- "in_create": 0,
- "in_dialog": 0,
- "is_submittable": 0,
- "issingle": 0,
- "istable": 1,
- "modified": "2015-10-19 03:04:51.773012",
- "modified_by": "Administrator",
- "module": "Buying",
- "name": "Purchase Order Item",
- "owner": "Administrator",
- "permissions": [],
- "read_only": 0,
- "read_only_onload": 0,
- "sort_field": "modified",
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 1, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 1, 
+ "modified": "2015-11-17 14:38:10.984627", 
+ "modified_by": "Administrator", 
+ "module": "Buying", 
+ "name": "Purchase Order Item", 
+ "owner": "Administrator", 
+ "permissions": [], 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
  "sort_order": "DESC"
-}
+}
\ No newline at end of file
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 5ccf29d..69561e1 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -52,15 +52,6 @@
 					self.supplier = supplier
 					break
 
-	def validate_warehouse(self):
-		from erpnext.stock.utils import validate_warehouse_company
-
-		warehouses = list(set([d.warehouse for d in
-			self.get("items") if getattr(d, "warehouse", None)]))
-
-		for w in warehouses:
-			validate_warehouse_company(w, self.company)
-
 	def validate_stock_or_nonstock_items(self):
 		if self.meta.get_field("taxes") and not self.get_stock_items():
 			tax_for_valuation = [d.account_head for d in self.get("taxes")
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 2a9fa17..5deb839 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -303,6 +303,15 @@
 						}))
 
 		self.make_sl_entries(sl_entries)
+		
+	def validate_warehouse(self):
+		from erpnext.stock.utils import validate_warehouse_company
+
+		warehouses = list(set([d.warehouse for d in
+			self.get("items") if getattr(d, "warehouse", None)]))
+
+		for w in warehouses:
+			validate_warehouse_company(w, self.company)
 
 def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for_items=None,
 		warehouse_account=None):
diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
index b3eee31..3b22eb2 100644
--- a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
@@ -4,7 +4,9 @@
 from frappe.utils import getdate
 
 class TestLeaveAllocation(unittest.TestCase):
-	def test_overlapping_allocation(self):		
+	def test_overlapping_allocation(self):
+		frappe.db.sql("delete from `tabLeave Allocation`")
+				
 		employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0])
 		leaves = [
 			{
diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py
index 9e21708..67e211e 100644
--- a/erpnext/hr/doctype/leave_application/test_leave_application.py
+++ b/erpnext/hr/doctype/leave_application/test_leave_application.py
@@ -44,7 +44,11 @@
 ]
 
 
-class TestLeaveApplication(unittest.TestCase):
+class TestLeaveApplication(unittest.TestCase):	
+	def setUp(self):
+		for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
+			frappe.db.sql("delete from `tab%s`" % dt)
+	
 	def tearDown(self):
 		frappe.set_user("Administrator")
 
@@ -97,6 +101,8 @@
 
 		frappe.db.set_value("Department", "_Test Department",
 			"leave_block_list", "_Test Leave Block List")
+			
+		make_allocation_record()
 
 		application = self.get_application(_test_records[0])
 		application.insert()
@@ -120,6 +126,9 @@
 		add_role("test2@example.com", "Leave Approver")
 
 		frappe.set_user("test@example.com")
+
+		make_allocation_record()
+		
 		application = self.get_application(_test_records[0])
 		application.leave_approver = "test2@example.com"
 		application.insert()
@@ -135,7 +144,9 @@
 		add_role("test1@example.com", "Employee")
 		add_role("test@example.com", "Leave Approver")
 		self._add_employee_leave_approver("_T-Employee-0002", "test@example.com")
-
+		
+		make_allocation_record(employee="_T-Employee-0002")
+		
 		application = self.get_application(_test_records[1])
 		application.leave_approver = "test@example.com"
 
@@ -175,6 +186,9 @@
 
 		# create leave application as Employee
 		frappe.set_user("test@example.com")
+		
+		make_allocation_record()
+		
 		application = self.get_application(_test_records[0])
 		application.leave_approver = "test1@example.com"
 		application.insert()
@@ -196,6 +210,8 @@
 		self._add_employee_leave_approver("_T-Employee-0001", "test2@example.com")
 		self._remove_employee_leave_approver("_T-Employee-0001", "test1@example.com")
 
+		make_allocation_record()
+
 		application = self.get_application(_test_records[0])
 		frappe.set_user("test@example.com")
 
@@ -212,6 +228,9 @@
 		# create leave application as employee
 		# but submit as invalid leave approver - should raise exception
 		frappe.set_user("test@example.com")
+		
+		make_allocation_record()
+		
 		application = self.get_application(_test_records[0])
 		application.leave_approver = "test2@example.com"
 		application.insert()
@@ -232,6 +251,9 @@
 		frappe.db.set_value("Employee", "_T-Employee-0001", "department", None)
 
 		frappe.set_user("test@example.com")
+		
+		make_allocation_record()
+		
 		application = self.get_application(_test_records[0])
 		application.leave_approver = "test2@example.com"
 		application.insert()
@@ -246,4 +268,19 @@
 		frappe.db.sql("""delete from `tabEmployee Leave Approver` where parent=%s""",
 			"_T-Employee-0001")
 
-		frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department)
\ No newline at end of file
+		frappe.db.set_value("Employee", "_T-Employee-0001", "department", original_department)
+		
+def make_allocation_record(employee=None, leave_type=None):
+	frappe.db.sql("delete from `tabLeave Allocation`")
+	
+	allocation = frappe.get_doc({
+		"doctype": "Leave Allocation",
+		"employee": employee or "_T-Employee-0001",
+		"leave_type": leave_type or "_Test Leave Type",
+		"from_date": "2013-01-01",
+		"to_date": "2015-12-31",
+		"new_leaves_allocated": 30
+	})
+	
+	allocation.insert(ignore_permissions=True)
+	allocation.submit()
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index fb69440..9eda231 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -7,23 +7,14 @@
 from frappe.utils import today
 from erpnext.hr.doctype.employee.employee import make_salary_structure
 from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
+from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record
 
 class TestSalarySlip(unittest.TestCase):
 	def setUp(self):
 		for dt in ["Leave Application", "Leave Allocation", "Salary Slip"]:
 			frappe.db.sql("delete from `tab%s`" % dt)
 		
-		allocation = frappe.get_doc({
-			"doctype": "Leave Allocation",
-			"employee": "_T-Employee-0001",
-			"leave_type": "_Test Leave Type LWP",
-			"from_date": "2013-01-01",
-			"to_date": "2015-12-31",
-			"new_leaves_allocated": 5
-		})
-		
-		allocation.insert()
-		allocation.submit()
+		make_allocation_record(leave_type="_Test Leave Type LWP")
 		
 		frappe.db.set_value("Holiday List", "_Test Holiday List", "is_default", 1)
 		
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 05723ca..1bf3e4b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -233,3 +233,4 @@
 erpnext.patches.v6_6.remove_fiscal_year_from_leave_allocation
 execute:frappe.delete_doc_if_exists("DocType", "Stock UOM Replace Utility")
 erpnext.patches.v6_8.make_webform_standard
+erpnext.patches.v6_8.move_drop_ship_to_po_items
diff --git a/erpnext/patches/v6_8/move_drop_ship_to_po_items.py b/erpnext/patches/v6_8/move_drop_ship_to_po_items.py
new file mode 100644
index 0000000..44ba3f0
--- /dev/null
+++ b/erpnext/patches/v6_8/move_drop_ship_to_po_items.py
@@ -0,0 +1,36 @@
+import frappe
+
+def execute():
+	for po in frappe.get_all("Purchase Order", filters={"delivered_by_supplier": 1}, fields=["name"]):
+		purchase_order = frappe.get_doc("Purchase Order", po)
+		
+		for item in purchase_order.items:
+			if item.prevdoc_doctype == "Sales Order":
+				delivered_by_supplier = frappe.get_value("Sales Order Item", item.prevdoc_detail_docname, 
+					"delivered_by_supplier")
+				
+				if delivered_by_supplier:
+					frappe.db.sql("""update `tabPurchase Order Item` 
+						set delivered_by_supplier=1, billed_amt=amount, received_qty=qty
+						where name=%s """, item.name)
+						
+		update_per_received(purchase_order)
+		update_per_billed(purchase_order)
+	
+def update_per_received(po):
+	frappe.db.sql(""" update `tabPurchase Order` 
+				set per_received = round((select sum(if(qty > ifnull(received_qty, 0), 
+					ifnull(received_qty, 0), qty)) / sum(qty) *100 
+				from `tabPurchase Order Item` 
+				where parent = %(name)s), 2) 
+			where name = %(name)s """, {"name": po.name})
+
+def update_per_billed(po):
+	frappe.db.sql(""" update `tabPurchase Order` 
+				set per_billed = round((select sum( if(amount > ifnull(billed_amt, 0), 
+					ifnull(billed_amt, 0), amount)) / sum(amount) *100 
+				from `tabPurchase Order Item` 
+				where parent = %(name)s), 2) 
+			where name = %(name)s """, {"name": po.name})
+
+				
\ 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 5ceeea8..d2b1653 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -66,12 +66,6 @@
 		for d in self.get('items'):
 			check_list.append(cstr(d.item_code))
 
-			if (frappe.db.get_value("Item", d.item_code, "is_stock_item")==1 or
-				(self.has_product_bundle(d.item_code) and self.product_bundle_has_stock_item(d.item_code))) \
-				and not d.warehouse and not cint(d.delivered_by_supplier):
-				frappe.throw(_("Delivery warehouse required for stock item {0}").format(d.item_code),
-					WarehouseRequired)
-
 			# used for production plan
 			d.transaction_date = self.transaction_date
 
@@ -116,14 +110,15 @@
 				frappe.throw(_("Customer {0} does not belong to project {1}").format(self.customer, self.project_name))
 
 	def validate_warehouse(self):
-		from erpnext.stock.utils import validate_warehouse_company
-
-		warehouses = list(set([d.warehouse for d in
-			self.get("items") if d.warehouse]))
-
-		for w in warehouses:
-			validate_warehouse_company(w, self.company)
-
+		super(SalesOrder, self).validate_warehouse()
+		
+		for d in self.get("items"):
+			if (frappe.db.get_value("Item", d.item_code, "is_stock_item")==1 or
+				(self.has_product_bundle(d.item_code) and self.product_bundle_has_stock_item(d.item_code))) \
+				and not d.warehouse and not cint(d.delivered_by_supplier):
+				frappe.throw(_("Delivery warehouse required for stock item {0}").format(d.item_code),
+					WarehouseRequired)
+			
 	def validate_with_previous_doc(self):
 		super(SalesOrder, self).validate_with_previous_doc({
 			"Quotation": {
@@ -236,13 +231,13 @@
 					item_wh_list.append([item_code, warehouse])
 
 		for d in self.get("items"):
-			if (not so_item_rows or d.name in so_item_rows):
-				_valid_for_reserve(d.item_code, d.warehouse)
-
+			if (not so_item_rows or d.name in so_item_rows) and not d.delivered_by_supplier:
 				if self.has_product_bundle(d.item_code):
 					for p in self.get("packed_items"):
 						if p.parent_detail_docname == d.name and p.parent_item == d.item_code:
 							_valid_for_reserve(p.item_code, p.warehouse)
+				else:
+					_valid_for_reserve(d.item_code, d.warehouse)
 
 		for item_code, warehouse in item_wh_list:
 			update_bin_qty(item_code, warehouse, {
diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py
index 61ee110..3501f52 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.py
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.py
@@ -355,10 +355,13 @@
 		self.assertEquals(dn.items[0].item_code, dn_item.item_code)
 
 		#test ordered_qty and reserved_qty
-		ordered_qty, reserved_qty = frappe.db.get_value("Bin",
-			{"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
+		bin = frappe.get_all("Bin", filters={"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"},
+			fields=["ordered_qty", "reserved_qty"])
 
-		self.assertEquals(abs(flt(ordered_qty)), existing_ordered_qty + so_items[0]['qty'])
+		ordered_qty = bin[0].ordered_qty if bin else 0.0
+		reserved_qty = bin[0].reserved_qty if bin else 0.0
+
+		self.assertEquals(abs(flt(ordered_qty)), existing_ordered_qty)
 		self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty)
 
 		reserved_qty = frappe.db.get_value("Bin",
@@ -384,8 +387,11 @@
 		so.db_set('status', "Closed")
 		so.update_reserved_qty()
 
-		ordered_qty, reserved_qty = frappe.db.get_value("Bin",
-			{"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"}, ["ordered_qty", "reserved_qty"])
+		bin = frappe.get_all("Bin", filters={"item_code": po_item.item_code, "warehouse": "_Test Warehouse - _TC"},
+			fields=["ordered_qty", "reserved_qty"])
+
+		ordered_qty = bin[0].ordered_qty if bin else 0.0
+		reserved_qty = bin[0].reserved_qty if bin else 0.0
 
 		self.assertEquals(abs(flt(ordered_qty)), existing_ordered_qty)
 		self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty)
@@ -393,7 +399,7 @@
 		reserved_qty = frappe.db.get_value("Bin",
 			{"item_code": dn_item.item_code, "warehouse": "_Test Warehouse - _TC"}, "reserved_qty")
 
-		self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty)
+		self.assertEquals(abs(flt(reserved_qty)), existing_reserved_qty_for_dn_item)
 
 	def test_reserved_qty_for_closing_so(self):
 		bin = frappe.get_all("Bin", filters={"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"},
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 60cc430..d653250 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -170,6 +170,8 @@
 					chk_dupl_itm.append(f)
 
 	def validate_warehouse(self):
+		super(DeliveryNote, self).validate_warehouse()
+		
 		for d in self.get_item_list():
 			if frappe.db.get_value("Item", d['item_code'], "is_stock_item") == 1:
 				if not d['warehouse']:
diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py
index 609c986..87e7fcd 100644
--- a/erpnext/stock/stock_balance.py
+++ b/erpnext/stock/stock_balance.py
@@ -76,10 +76,12 @@
 					(
 						select qty from `tabSales Order Item`
 						where name = dnpi.parent_detail_docname
+						and (delivered_by_supplier is null or delivered_by_supplier = 0)
 					) as so_item_qty,
 					(
 						select ifnull(delivered_qty, 0) from `tabSales Order Item`
-						where name = dnpi.parent_detail_docname
+						where name = dnpi.parent_detail_docname 
+						and (delivered_by_supplier is null or delivered_by_supplier = 0)
 					) as so_item_delivered_qty,
 					parent, name
 				from
@@ -96,7 +98,8 @@
 				(select qty as dnpi_qty, qty as so_item_qty,
 					ifnull(delivered_qty, 0) as so_item_delivered_qty, parent, name
 				from `tabSales Order Item` so_item
-				where item_code = %s and warehouse = %s
+				where item_code = %s and warehouse = %s 
+				and (so_item.delivered_by_supplier is null or so_item.delivered_by_supplier = 0)
 				and exists(select * from `tabSales Order` so
 					where so.name = so_item.parent and so.docstatus = 1
 					and so.status not in ('Stopped','Closed')))
@@ -122,7 +125,9 @@
 		from `tabPurchase Order Item` po_item, `tabPurchase Order` po
 		where po_item.item_code=%s and po_item.warehouse=%s
 		and po_item.qty > ifnull(po_item.received_qty, 0) and po_item.parent=po.name
-		and po.status not in ('Stopped', 'Closed', 'Delivered') and po.docstatus=1""", (item_code, warehouse))
+		and po.status not in ('Stopped', 'Closed', 'Delivered') and po.docstatus=1
+		and (po_item.delivered_by_supplier is null or po_item.delivered_by_supplier = 0)
+		""", (item_code, warehouse))
 
 	return flt(ordered_qty[0][0]) if ordered_qty else 0