Merge pull request #4433 from nabinhait/expense_allow_import

[fix] Allowed import for Expense Claim
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 4b33f10..7ad50d5 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -64,6 +64,7 @@
 			self.validate_pos()
 
 		if cint(self.update_stock):
+			self.validate_dropship_item()
 			self.validate_item_code()
 			self.validate_warehouse()
 			self.update_current_stock()
@@ -409,6 +410,12 @@
 		if self.c_form_applicable == 'Yes' and self.c_form_no:
 			msgprint(_("Please remove this Invoice {0} from C-Form {1}")
 				.format(self.name, self.c_form_no), raise_exception = 1)
+	
+	def validate_dropship_item(self):
+		for item in self.items:
+			if item.sales_order:
+				if frappe.db.get_value("Sales Order Item", item.so_detail, "delivered_by_supplier"):
+					frappe.throw(_("Could not update stock, invoice contains drop shipping item."))
 
 	def update_current_stock(self):
 		for d in self.get('items'):
diff --git a/erpnext/buying/print_format/drop_shipping/drop_shipping.json b/erpnext/buying/print_format/drop_shipping/drop_shipping.json
deleted file mode 100644
index 0af9a24..0000000
--- a/erpnext/buying/print_format/drop_shipping/drop_shipping.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "creation": "2015-10-20 16:46:39.382799", 
- "custom_format": 0, 
- "disabled": 0, 
- "doc_type": "Purchase Order", 
- "docstatus": 0, 
- "doctype": "Print Format", 
- "font": "Default", 
- "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"HTML\", \"options\": \"<h1 style=\\\"text-align: center;\\\">Purchase Order</h1><div style=\\\"text-align: center;\\\">{{doc.name}}</div><div style=\\\"text-align: center;\\\"><hr></div>\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"title\"}, {\"print_hide\": 0, \"fieldname\": \"supplier\"}, {\"print_hide\": 0, \"fieldname\": \"supplier_name\"}, {\"print_hide\": 0, \"fieldname\": \"address_display\"}, {\"print_hide\": 0, \"fieldname\": \"contact_display\"}, {\"print_hide\": 0, \"fieldname\": \"contact_mobile\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"transaction_date\"}, {\"print_hide\": 0, \"fieldname\": \"customer\"}, {\"print_hide\": 0, \"fieldname\": \"customer_name\"}, {\"print_hide\": 0, \"fieldname\": \"customer_address_display\"}, {\"print_hide\": 0, \"fieldname\": \"customer_contact_display\"}, {\"print_hide\": 0, \"fieldname\": \"customer_contact_mobile\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"item_code\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"image\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"qty\", \"print_width\": \"60px\"}, {\"print_hide\": 0, \"fieldname\": \"uom\", \"print_width\": \"100px\"}, {\"print_hide\": 0, \"fieldname\": \"discount_percentage\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"pricing_rule\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"supplier_quotation\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"supplier_quotation_item\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"items\"}, {\"print_hide\": 0, \"fieldname\": \"get_last_purchase_rate\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"total\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"visible_columns\": [{\"print_hide\": 0, \"fieldname\": \"category\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"add_deduct_tax\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"charge_type\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"row_id\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"included_in_print_rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"account_head\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"cost_center\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"description\", \"print_width\": \"300px\"}, {\"print_hide\": 0, \"fieldname\": \"rate\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"tax_amount\", \"print_width\": \"\"}, {\"print_hide\": 0, \"fieldname\": \"total\", \"print_width\": \"\"}], \"print_hide\": 0, \"fieldname\": \"taxes\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"grand_total\"}, {\"print_hide\": 0, \"fieldname\": \"in_words\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"terms\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"customer_contact_person\"}, {\"fieldtype\": \"Section Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"print_hide\": 0, \"fieldname\": \"recurring_print_format\"}]", 
- "modified": "2015-10-20 17:21:45.810640", 
- "modified_by": "saurabh@erpnext.com", 
- "name": "Drop Shipping", 
- "owner": "Administrator", 
- "print_format_builder": 1, 
- "print_format_type": "Server", 
- "standard": "No"
-}
\ No newline at end of file
diff --git a/erpnext/buying/print_format/drop_shipping/__init__.py b/erpnext/buying/print_format/drop_shipping_format/__init__.py
similarity index 100%
rename from erpnext/buying/print_format/drop_shipping/__init__.py
rename to erpnext/buying/print_format/drop_shipping_format/__init__.py
diff --git a/erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json b/erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json
new file mode 100644
index 0000000..cd2e826
--- /dev/null
+++ b/erpnext/buying/print_format/drop_shipping_format/drop_shipping_format.json
@@ -0,0 +1,18 @@
+{
+ "creation": "2015-12-04 13:11:16.992997", 
+ "custom_format": 1, 
+ "disabled": 0, 
+ "doc_type": "Purchase Order", 
+ "docstatus": 0, 
+ "doctype": "Print Format", 
+ "font": "Default", 
+ "html": "<div class=\"page-break\">\n    <div class=\"print-heading\">\n\t\t<h2>Purchase Order<br>\n\t        <small>{{doc.name}}</small>\n        </h2>\n    </div>\n    <div class=\"row section-break\">\n        <div class=\"col-xs-6 column-break\">\n                <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>Supplier Name</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t{{doc.supplier_name}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t{% if doc.address_display %}\n\t                <div class=\"row\">\n\t\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t\t<label>Address</label>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t\t{{doc.address_display}}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{%- endif -%}\n\t\t\t\t{% if doc.contact_display %}\n\t                <div class=\"row\">\n\t\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t\t<label>Contact</label>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t\t{{doc.contact_display}}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{%- endif -%}\n\t\t\t\t{% if doc.contact_mobile %}\n\t                <div class=\"row\">\n\t\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t\t<label>Mobile No</label>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t\t{{doc.contact_mobile}}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t{%- endif -%}\n        </div>\n        \n        <div class=\"col-xs-6 column-break\">\n            <div class=\"row\">\n\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t<label>Date</label>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t{{doc.transaction_date}}\n\t\t\t\t</div>\n\t\t\t</div>\n            <div class=\"row\">\n\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t<label>Customer Name</label>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t{{doc.customer_name}}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t{% if doc.customer_address_display %}\n\t            <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>Customer Address</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t{{doc.customer_address_display}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t{%- endif -%}\n\t\t\t{% if doc.customer_contact_display %}\n\t            <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>Customer Contact</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t{{doc.customer_contact_display}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t{%- endif -%}\n\t\t\t{% if doc.customer_contact_mobile %}\n\t            <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>Customer Mobile No</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7  value\">\n\t\t\t\t\t\t{{doc.customer_contact_mobile}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t{%- endif -%}\n        </div>\n    </div>\n\t<table class=\"table table-bordered\">\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<th>Sr</th>\n\t\t\t\t<th>Item Name</th>\n\t\t\t\t<th>Description</th>\n\t\t\t\t<th class=\"text-right\">Qty</th>\n\t\t\t\t<th class=\"text-right\">Rate</th>\n\t\t\t\t<th class=\"text-right\">Amount</th>\n\t\t\t</tr>\n\t\t\t{%- for row in doc.items -%}\n\t\t\t<tr>\n\t\t\t\t<td style=\"width: 3%;\">{{ row.idx }}</td>\n\t\t\t\t<td style=\"width: 20%;\">\n\t\t\t\t\t{{ row.item_name }}\n\t\t\t\t\t{% if row.item_code != row.item_name -%}\n\t\t\t\t\t<br>Item Code: {{ row.item_code}}\n\t\t\t\t\t{%- endif %}\n\t\t\t\t</td>\n\t\t\t\t<td style=\"width: 37%;\">\n\t\t\t\t\t<div style=\"border: 0px;\">{{ row.description }}</div></td>\n\t\t\t\t<td style=\"width: 10%; text-align: right;\">{{ row.qty }} {{ row.uom or row.stock_uom }}</td>\n\t\t\t\t<td style=\"width: 15%; text-align: right;\">{{\n\t\t\t\t\trow.get_formatted(\"rate\", doc) }}</td>\n\t\t\t\t<td style=\"width: 15%; text-align: right;\">{{\n\t\t\t\t\trow.get_formatted(\"amount\", doc) }}</td>\n\t\t\t</tr>\n\t\t\t{%- endfor -%}\n\t\t</tbody>\n\t</table>\n    <div class=\"row section-break\">\n        <div class=\"col-xs-6 column-break\">\n        </div>\n        <div class=\"col-xs-6 column-break\">\n                <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>Total</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7 text-right value\">\n\t\t\t\t\t\t{{doc.total}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n                <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>Grand Total</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7 text-right value\">\n\t\t\t\t\t\t{{doc.grand_total}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n                <div class=\"row\">\n\t\t\t\t\t<div class=\"col-xs-5 text-right\">\n\t\t\t\t\t\t<label>In Words</label>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col-xs-7 text-right value\">\n\t\t\t\t\t\t{{doc.in_words}}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n        </div>\n    </div>\n</div>", 
+ "idx": 0, 
+ "modified": "2015-12-04 13:47:55.157482", 
+ "modified_by": "Administrator", 
+ "name": "Drop Shipping Format", 
+ "owner": "Administrator", 
+ "print_format_builder": 0, 
+ "print_format_type": "Server", 
+ "standard": "Yes"
+}
\ 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 66ca31e..05cb50c 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -531,8 +531,14 @@
 		default_price_list = frappe.get_value("Supplier", for_supplier, "default_price_list")
 		if default_price_list:
 			target.buying_price_list = default_price_list
+			
+		if source.shipping_address_name:
+			target.customer_address = source.shipping_address_name
+			target.customer_address_display = source.shipping_address
+		else:
+			target.customer_address = source.customer_address
+			target.customer_address_display = source.address_display
 
-		target.delivered_by_supplier = 1
 		target.run_method("set_missing_values")
 		target.run_method("calculate_taxes_and_totals")
 
@@ -544,9 +550,7 @@
 		"Sales Order": {
 			"doctype": "Purchase Order",
 			"field_map": {
-				"customer_address": "customer_address",
 				"contact_person": "customer_contact_person",
-				"address_display": "customer_address_display",
 				"contact_display": "customer_contact_display",
 				"contact_mobile": "customer_contact_mobile",
 				"contact_email": "customer_contact_email",
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index f89561c..0d95c58 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -88,6 +88,7 @@
 	else:
 		frappe.msgprint(_("Item {0} ignored since it is not a stock item").format(args.get("item_code")))
 
+@frappe.whitelist()
 def get_incoming_rate(args):
 	"""Get Incoming Rate based on valuation method"""
 	from erpnext.stock.stock_ledger import get_previous_sle