Merge branch 'UAE-VAT-Format' of https://github.com/hasnain2808/erpnext into UAE-VAT-Format
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js
index b953b8a..f523cf2 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.js
@@ -21,6 +21,19 @@
 				}
 			};
 		});
+
+		frm.set_query('warehouse', () => {
+			return {
+				filters: {
+					company: frm.doc.company
+				}
+			};
+		});
+	},
+
+	patient: function(frm) {
+		if (frm.doc.patient)
+			frm.set_value('service_unit', '');
 	},
 
 	get_medication_orders: function(frm) {
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json
index 5d80251..dd4c423 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.json
@@ -67,6 +67,7 @@
   },
   {
    "collapsible": 1,
+   "collapsible_depends_on": "eval: doc.__islocal",
    "fieldname": "filters_section",
    "fieldtype": "Section Break",
    "label": "Filters"
@@ -93,6 +94,7 @@
    "options": "Patient"
   },
   {
+   "depends_on": "eval:!doc.patient",
    "fieldname": "service_unit",
    "fieldtype": "Link",
    "label": "Healthcare Service Unit",
@@ -178,7 +180,7 @@
  "index_web_pages_for_search": 1,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-09-30 23:40:45.528715",
+ "modified": "2020-11-03 13:22:37.820707",
  "modified_by": "Administrator",
  "module": "Healthcare",
  "name": "Inpatient Medication Entry",
diff --git a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
index 2385893..23e7519 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
+++ b/erpnext/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
@@ -199,6 +199,7 @@
 
 def get_pending_medication_orders(entry):
 	filters, values = get_filters(entry)
+	to_remove = []
 
 	data = frappe.db.sql("""
 		SELECT
@@ -225,7 +226,10 @@
 		doc['service_unit'] = get_current_healthcare_service_unit(inpatient_record)
 
 		if entry.service_unit and doc.service_unit != entry.service_unit:
-			data.remove(doc)
+			to_remove.append(doc)
+
+	for doc in to_remove:
+		data.remove(doc)
 
 	return data
 
diff --git a/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js b/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js
index c51f3cf..690e2e7 100644
--- a/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js
+++ b/erpnext/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js
@@ -12,7 +12,8 @@
 		frm.set_query('patient', () => {
 			return {
 				filters: {
-					'inpatient_record': ['!=', '']
+					'inpatient_record': ['!=', ''],
+					'inpatient_status': 'Admitted'
 				}
 			};
 		});
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index 69e47a4..dd87f0f 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -139,7 +139,7 @@
 	if not frappe.get_meta('Address').has_field('gst_state'): return
 
 	if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"):
-		address_name = party_details.shipping_address_name or party_details.customer_address
+		address_name = party_details.customer_address or party_details.shipping_address_name
 	elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"):
 		address_name = party_details.shipping_address or party_details.supplier_address
 
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py
index 6b9939e..a690050 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.py
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.py
@@ -14,11 +14,9 @@
 def get_items(start, page_length, price_list, item_group, pos_profile, search_value=""):
 	data = dict()
 	result = []
-	warehouse, hide_unavailable_items = "", False
 
 	allow_negative_stock = frappe.db.get_single_value('Stock Settings', 'allow_negative_stock')
-	if not allow_negative_stock:
-		warehouse, hide_unavailable_items = frappe.db.get_value('POS Profile', pos_profile, ['warehouse', 'hide_unavailable_items'])
+	warehouse, hide_unavailable_items = frappe.db.get_value('POS Profile', pos_profile, ['warehouse', 'hide_unavailable_items'])
 
 	if not frappe.db.exists('Item Group', item_group):
 		item_group = get_root_of('Item Group')
@@ -97,7 +95,7 @@
 		for item in items_data:
 			item_code = item.item_code
 			item_price = item_prices.get(item_code) or {}
-			if not allow_negative_stock:
+			if allow_negative_stock:
 				item_stock_qty = frappe.db.sql("""select ifnull(sum(actual_qty), 0) from `tabBin` where item_code = %s""", item_code)[0][0]
 			else:
 				item_stock_qty = get_stock_availability(item_code, warehouse)
@@ -231,13 +229,31 @@
 		frappe.db.set_value('Customer', customer, 'loyalty_program', value)
 
 	contact = frappe.get_cached_value('Customer', customer, 'customer_primary_contact')
+	if not contact:
+		contact = frappe.db.sql("""
+			SELECT parent FROM `tabDynamic Link`
+			WHERE
+				parenttype = 'Contact' AND
+				parentfield = 'links' AND
+				link_doctype = 'Customer' AND
+				link_name = %s
+			""", (customer), as_dict=1)
+		contact = contact[0].get('parent') if contact else None
 
-	if contact:
-		contact_doc = frappe.get_doc('Contact', contact)
-		if fieldname == 'email_id':
-			contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}])
-			frappe.db.set_value('Customer', customer, 'email_id', value)
-		elif fieldname == 'mobile_no':
-			contact_doc.set('phone_nos', [{ 'phone': value, 'is_primary_mobile_no': 1}])
-			frappe.db.set_value('Customer', customer, 'mobile_no', value)
-		contact_doc.save()
\ No newline at end of file
+	if not contact:
+		new_contact = frappe.new_doc('Contact')
+		new_contact.is_primary_contact = 1
+		new_contact.first_name = customer
+		new_contact.set('links', [{'link_doctype': 'Customer', 'link_name': customer}])
+		new_contact.save()
+		contact = new_contact.name
+		frappe.db.set_value('Customer', customer, 'customer_primary_contact', contact)
+
+	contact_doc = frappe.get_doc('Contact', contact)
+	if fieldname == 'email_id':
+		contact_doc.set('email_ids', [{ 'email_id': value, 'is_primary': 1}])
+		frappe.db.set_value('Customer', customer, 'email_id', value)
+	elif fieldname == 'mobile_no':
+		contact_doc.set('phone_nos', [{ 'phone': value, 'is_primary_mobile_no': 1}])
+		frappe.db.set_value('Customer', customer, 'mobile_no', value)
+	contact_doc.save()
\ No newline at end of file
diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js
index 3d00546..f7d1fa4 100644
--- a/erpnext/selling/page/point_of_sale/pos_controller.js
+++ b/erpnext/selling/page/point_of_sale/pos_controller.js
@@ -637,7 +637,7 @@
 		if (!(available_qty > 0)) {
 			frappe.model.clear_doc(item_row.doctype, item_row.name);
 			frappe.throw({
-				title: _("Not Available"),
+				title: __("Not Available"),
 				message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse])
 			})
 		} else if (available_qty < qty_needed) {
diff --git a/erpnext/selling/page/point_of_sale/pos_item_selector.js b/erpnext/selling/page/point_of_sale/pos_item_selector.js
index 4139e29..49d4281 100644
--- a/erpnext/selling/page/point_of_sale/pos_item_selector.js
+++ b/erpnext/selling/page/point_of_sale/pos_item_selector.js
@@ -81,7 +81,7 @@
 		function get_item_image_html() {
 			if (item_image) {
 				return `<div class="flex items-center justify-center h-32 border-b-grey text-6xl text-grey-100">
-							<img class="h-full" src="${item_image}" alt="${item_image}" style="object-fit: cover;">
+							<img class="h-full" src="${item_image}" alt="${frappe.get_abbr(item.item_name)}" style="object-fit: cover;">
 						</div>`
 			} else {
 				return `<div class="flex items-center justify-center h-32 bg-light-grey text-6xl text-grey-100">
diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js
index e89cf01..e4d8965 100644
--- a/erpnext/selling/page/point_of_sale/pos_payment.js
+++ b/erpnext/selling/page/point_of_sale/pos_payment.js
@@ -409,7 +409,7 @@
 				${
 					shortcuts.map(s => {
 						return `<div class="shortcut rounded bg-light-grey text-dark-grey pt-2 pb-2 no-select pointer" data-value="${s}">
-									${format_currency(s, currency)}
+									${format_currency(s, currency, 0)}
 								</div>`
 					}).join('')
 				}