Merge pull request #22233 from deepeshgarg007/pi_billing_address

fix: Billing address in for Purchase documents
diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js
index f62d076..28b090b 100644
--- a/erpnext/accounts/doctype/account/account_tree.js
+++ b/erpnext/accounts/doctype/account/account_tree.js
@@ -14,6 +14,9 @@
 			on_change: function() {
 				var me = frappe.treeview_settings['Account'].treeview;
 				var company = me.page.fields_dict.company.get_value();
+				if (!company) {
+					frappe.throw(__("Please set a Company"));
+				}
 				frappe.call({
 					method: "erpnext.accounts.doctype.account.account.get_root_company",
 					args: {
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json
index 9d50639..af2aa65 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.json
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json
@@ -191,6 +191,7 @@
   {
    "fieldname": "total_debit",
    "fieldtype": "Currency",
+   "in_list_view": 1,
    "label": "Total Debit",
    "no_copy": 1,
    "oldfieldname": "total_debit",
@@ -252,7 +253,6 @@
    "fieldname": "total_amount",
    "fieldtype": "Currency",
    "hidden": 1,
-   "in_list_view": 1,
    "label": "Total Amount",
    "no_copy": 1,
    "options": "total_amount_currency",
@@ -503,7 +503,7 @@
  "idx": 176,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-04-29 10:55:28.240916",
+ "modified": "2020-06-02 18:15:46.955697",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Journal Entry",
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index d2245d6..15e51bb 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -319,7 +319,7 @@
 				invoice_payment_amount_map.setdefault(key, 0.0)
 				invoice_payment_amount_map[key] += reference.allocated_amount
 
-				if not invoice_paid_amount_map.get(reference.reference_name):
+				if not invoice_paid_amount_map.get(key):
 					payment_schedule = frappe.get_all('Payment Schedule', filters={'parent': reference.reference_name},
 						fields=['paid_amount', 'payment_amount', 'payment_term'])
 					for term in payment_schedule:
@@ -332,12 +332,14 @@
 				frappe.db.sql(""" UPDATE `tabPayment Schedule` SET paid_amount = `paid_amount` - %s
 					WHERE parent = %s and payment_term = %s""", (amount, key[1], key[0]))
 			else:
-				outstanding = invoice_paid_amount_map.get(key)['outstanding']
+				outstanding = flt(invoice_paid_amount_map.get(key, {}).get('outstanding'))
+
 				if amount > outstanding:
 					frappe.throw(_('Cannot allocate more than {0} against payment term {1}').format(outstanding, key[0]))
 
-				frappe.db.sql(""" UPDATE `tabPayment Schedule` SET paid_amount = `paid_amount` + %s
-						WHERE parent = %s and payment_term = %s""", (amount, key[1], key[0]))
+				if amount and outstanding:
+					frappe.db.sql(""" UPDATE `tabPayment Schedule` SET paid_amount = `paid_amount` + %s
+							WHERE parent = %s and payment_term = %s""", (amount, key[1], key[0]))
 
 	def set_status(self):
 		if self.docstatus == 2:
@@ -1091,17 +1093,20 @@
 def get_reference_as_per_payment_terms(payment_schedule, dt, dn, doc, grand_total, outstanding_amount):
 	references = []
 	for payment_term in payment_schedule:
-		references.append({
-			'reference_doctype': dt,
-			'reference_name': dn,
-			'bill_no': doc.get('bill_no'),
-			'due_date': doc.get('due_date'),
-			'total_amount': grand_total,
-			'outstanding_amount': outstanding_amount,
-			'payment_term': payment_term.payment_term,
-			'allocated_amount': flt(payment_term.payment_amount - payment_term.paid_amount,
+		payment_term_outstanding = flt(payment_term.payment_amount - payment_term.paid_amount,
 				payment_term.precision('payment_amount'))
-		})
+
+		if payment_term_outstanding:
+			references.append({
+				'reference_doctype': dt,
+				'reference_name': dn,
+				'bill_no': doc.get('bill_no'),
+				'due_date': doc.get('due_date'),
+				'total_amount': grand_total,
+				'outstanding_amount': outstanding_amount,
+				'payment_term': payment_term.payment_term,
+				'allocated_amount': payment_term_outstanding
+			})
 
 	return references
 
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.json b/erpnext/accounts/doctype/payment_request/payment_request.json
index 7508683..eef6be1 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.json
+++ b/erpnext/accounts/doctype/payment_request/payment_request.json
@@ -349,9 +349,10 @@
    "read_only": 1
   }
  ],
+ "in_create": 1,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-05-08 10:23:02.815237",
+ "modified": "2020-05-29 17:38:49.392713",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Payment Request",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 57dc179..5e8279b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -582,14 +582,14 @@
 
 	def validate_item_code(self):
 		for d in self.get('items'):
-			if not d.item_code:
+			if not d.item_code and self.is_opening == "No":
 				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_item_list():
-			if not d.warehouse and frappe.get_cached_value("Item", d.item_code, "is_stock_item"):
+			if not d.warehouse and d.item_code and frappe.get_cached_value("Item", d.item_code, "is_stock_item"):
 				frappe.throw(_("Warehouse required for stock Item {0}").format(d.item_code))
 
 	def validate_delivery_note(self):
@@ -1450,11 +1450,17 @@
 		parties = frappe.db.get_all("Supplier", fields=["name"], filters={"disabled": 0, "is_internal_supplier": 1, "represents_company": doc.company})
 		company = frappe.get_cached_value("Customer", doc.customer, "represents_company")
 
+		if not parties:
+			frappe.throw(_('No Supplier found for Inter Company Transactions which represents company {0}').format(frappe.bold(doc.company)))
+
 		party = get_internal_party(parties, "Supplier", doc)
 	else:
 		parties = frappe.db.get_all("Customer", fields=["name"], filters={"disabled": 0, "is_internal_customer": 1, "represents_company": doc.company})
 		company = frappe.get_cached_value("Supplier", doc.supplier, "represents_company")
 
+		if not parties:
+			frappe.throw(_('No Customer found for Inter Company Transactions which represents company {0}').format(frappe.bold(doc.company)))
+
 		party = get_internal_party(parties, "Customer", doc)
 
 	return {
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 0339e49..533685d 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -56,9 +56,8 @@
 		to_date = add_months(start_date, months_to_add)
 		start_date = to_date
 
-		if to_date == get_first_day(to_date):
-			# if to_date is the first day, get the last day of previous month
-			to_date = add_days(to_date, -1)
+		# Subtract one day from to_date, as it may be first day in next fiscal year or month
+		to_date = add_days(to_date, -1)
 
 		if to_date <= year_end_date:
 			# the normal case
@@ -406,6 +405,7 @@
 				FROM `tabDistributed Cost Center`
 				WHERE cost_center IN %(cost_center)s
 				AND parent NOT IN %(cost_center)s
+				AND is_cancelled = 0
 				GROUP BY parent
 			) as DCC_allocation
 			WHERE company=%(company)s
@@ -418,6 +418,7 @@
 			where company=%(company)s
 			{additional_conditions}
 			and posting_date <= %(to_date)s
+			and is_cancelled = 0
 			{distributed_cost_center_query}
 			order by account, posting_date""".format(
 				additional_conditions=additional_conditions,
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 9777ed1..3445df7 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -265,13 +265,6 @@
 			'fieldtype': 'Currency',
 			'options': 'currency',
 			'width': 100
-		},
-		{
-			'fieldname': 'currency',
-			'label': _('Currency'),
-			'fieldtype': 'Currency',
-			'width': 80,
-			'hidden': 1
 		}
 	]
 
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index bb78ee2..a05dcd7 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -223,7 +223,7 @@
 		}
 	]
 
-	if filters.get('group_by') != 'Terriotory':
+	if filters.get('group_by') != 'Territory':
 		columns.extend([
 			{
 				'label': _("Territory"),
@@ -304,13 +304,6 @@
 			'fieldtype': 'Currency',
 			'options': 'currency',
 			'width': 100
-		},
-		{
-			'fieldname': 'currency',
-			'label': _('Currency'),
-			'fieldtype': 'Currency',
-			'width': 80,
-			'hidden': 1
 		}
 	]
 
@@ -536,6 +529,13 @@
 			'fieldtype': 'Currency',
 			'options': 'currency',
 			'width': 100
+		},
+		{
+			'fieldname': 'currency',
+			'label': _('Currency'),
+			'fieldtype': 'Currency',
+			'width': 80,
+			'hidden': 1
 		}
 	]
 
diff --git a/erpnext/buying/report/procurement_tracker/procurement_tracker.py b/erpnext/buying/report/procurement_tracker/procurement_tracker.py
index 3966879..88a865f 100644
--- a/erpnext/buying/report/procurement_tracker/procurement_tracker.py
+++ b/erpnext/buying/report/procurement_tracker/procurement_tracker.py
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
+from frappe.utils import flt
 
 def execute(filters=None):
 	columns = get_columns(filters)
@@ -54,15 +55,16 @@
 			"width": 140
 		},
 		{
-			"label": _("Description"),
-			"fieldname": "description",
-			"fieldtype": "Data",
-			"width": 200
+			"label": _("Item"),
+			"fieldname": "item_code",
+			"fieldtype": "Link",
+			"options": "Item",
+			"width": 150
 		},
 		{
 			"label": _("Quantity"),
 			"fieldname": "quantity",
-			"fieldtype": "Int",
+			"fieldtype": "Float",
 			"width": 140
 		},
 		{
@@ -118,7 +120,7 @@
 		},
 		{
 			"label": _("Purchase Order Amount(Company Currency)"),
-			"fieldname": "purchase_order_amt_usd",
+			"fieldname": "purchase_order_amt_in_company_currency",
 			"fieldtype": "Float",
 			"width": 140
 		},
@@ -175,17 +177,17 @@
 			"requesting_site": po.warehouse,
 			"requestor": po.owner,
 			"material_request_no": po.material_request,
-			"description": po.description,
-			"quantity": po.qty,
+			"item_code": po.item_code,
+			"quantity": flt(po.qty),
 			"unit_of_measurement": po.stock_uom,
 			"status": po.status,
 			"purchase_order_date": po.transaction_date,
 			"purchase_order": po.parent,
 			"supplier": po.supplier,
-			"estimated_cost": mr_record.get('amount'),
-			"actual_cost": pi_records.get(po.name),
-			"purchase_order_amt": po.amount,
-			"purchase_order_amt_in_company_currency": po.base_amount,
+			"estimated_cost": flt(mr_record.get('amount')),
+			"actual_cost": flt(pi_records.get(po.name)),
+			"purchase_order_amt": flt(po.amount),
+			"purchase_order_amt_in_company_currency": flt(po.base_amount),
 			"expected_delivery_date": po.schedule_date,
 			"actual_delivery_date": pr_records.get(po.name)
 		}
@@ -198,9 +200,14 @@
 		SELECT
 			par.transaction_date,
 			par.per_ordered,
+			par.owner,
 			child.name,
 			child.parent,
-			child.amount
+			child.amount,
+			child.qty,
+			child.item_code,
+			child.uom,
+			par.status
 		FROM `tabMaterial Request` par, `tabMaterial Request Item` child
 		WHERE
 			par.per_ordered>=0
@@ -217,7 +224,15 @@
 			procurement_record_details = dict(
 				material_request_date=record.transaction_date,
 				material_request_no=record.parent,
-				estimated_cost=record.amount
+				requestor=record.owner,
+				item_code=record.item_code,
+				estimated_cost=flt(record.amount),
+				quantity=flt(record.qty),
+				unit_of_measurement=record.uom,
+				status=record.status,
+				actual_cost=0,
+				purchase_order_amt=0,
+				purchase_order_amt_in_company_currency=0
 			)
 			procurement_record_against_mr.append(procurement_record_details)
 	return mr_records, procurement_record_against_mr
@@ -259,7 +274,7 @@
 			child.warehouse,
 			child.material_request,
 			child.material_request_item,
-			child.description,
+			child.item_code,
 			child.stock_uom,
 			child.qty,
 			child.amount,
diff --git a/erpnext/crm/doctype/opportunity/opportunity_dashboard.py b/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
index 9ed616a..68f0104 100644
--- a/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
+++ b/erpnext/crm/doctype/opportunity/opportunity_dashboard.py
@@ -3,11 +3,7 @@
 
 def get_data():
 	return {
-		'fieldname': 'prevdoc_docname',
-		'non_standard_fieldnames': {
-			'Supplier Quotation': 'opportunity',
-			'Quotation': 'opportunity'
-		},
+		'fieldname': 'opportunity',
 		'transactions': [
 			{
 				'items': ['Quotation', 'Supplier Quotation']
diff --git a/erpnext/crm/doctype/social_media_post/social_media_post.json b/erpnext/crm/doctype/social_media_post/social_media_post.json
index 2601c14..0a00dca 100644
--- a/erpnext/crm/doctype/social_media_post/social_media_post.json
+++ b/erpnext/crm/doctype/social_media_post/social_media_post.json
@@ -30,24 +30,32 @@
    "fieldname": "text",
    "fieldtype": "Small Text",
    "label": "Tweet",
-   "mandatory_depends_on": "eval:doc.twitter ==1"
+   "mandatory_depends_on": "eval:doc.twitter ==1",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "image",
    "fieldtype": "Attach Image",
-   "label": "Image"
+   "label": "Image",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "default": "0",
    "fieldname": "twitter",
    "fieldtype": "Check",
-   "label": "Twitter"
+   "label": "Twitter",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "default": "0",
    "fieldname": "linkedin",
    "fieldtype": "Check",
-   "label": "LinkedIn"
+   "label": "LinkedIn",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "amended_from",
@@ -56,13 +64,17 @@
    "no_copy": 1,
    "options": "Social Media Post",
    "print_hide": 1,
-   "read_only": 1
+   "read_only": 1,
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "depends_on": "eval:doc.twitter ==1",
    "fieldname": "content",
    "fieldtype": "Section Break",
-   "label": "Twitter"
+   "label": "Twitter",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "allow_on_submit": 1,
@@ -70,7 +82,9 @@
    "fieldtype": "Select",
    "label": "Post Status",
    "options": "\nScheduled\nPosted\nError",
-   "read_only": 1
+   "read_only": 1,
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "allow_on_submit": 1,
@@ -78,7 +92,9 @@
    "fieldtype": "Data",
    "hidden": 1,
    "label": "Twitter Post Id",
-   "read_only": 1
+   "read_only": 1,
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "allow_on_submit": 1,
@@ -86,68 +102,89 @@
    "fieldtype": "Data",
    "hidden": 1,
    "label": "LinkedIn Post Id",
-   "read_only": 1
+   "read_only": 1,
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "campaign_name",
    "fieldtype": "Link",
    "in_list_view": 1,
    "label": "Campaign",
-   "options": "Campaign"
+   "options": "Campaign",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "column_break_6",
    "fieldtype": "Column Break",
-   "label": "Share On"
+   "label": "Share On",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "column_break_14",
-   "fieldtype": "Column Break"
+   "fieldtype": "Column Break",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "tweet_preview",
-   "fieldtype": "HTML"
+   "fieldtype": "HTML",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "collapsible": 1,
    "depends_on": "eval:doc.linkedin==1",
    "fieldname": "linkedin_section",
    "fieldtype": "Section Break",
-   "label": "LinkedIn"
+   "label": "LinkedIn",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "collapsible": 1,
    "fieldname": "attachments_section",
    "fieldtype": "Section Break",
-   "label": "Attachments"
+   "label": "Attachments",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "linkedin_post",
    "fieldtype": "Text",
    "label": "Post",
-   "mandatory_depends_on": "eval:doc.linkedin ==1"
+   "mandatory_depends_on": "eval:doc.linkedin ==1",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "fieldname": "column_break_15",
-   "fieldtype": "Column Break"
+   "fieldtype": "Column Break",
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "allow_on_submit": 1,
    "fieldname": "scheduled_time",
    "fieldtype": "Datetime",
    "label": "Scheduled Time",
-   "read_only_depends_on": "eval:doc.post_status == \"Posted\""
+   "read_only_depends_on": "eval:doc.post_status == \"Posted\"",
+   "show_days": 1,
+   "show_seconds": 1
   }
  ],
  "is_submittable": 1,
  "links": [],
- "modified": "2020-04-21 15:10:04.953713",
+ "modified": "2020-06-14 10:31:33.961381",
  "modified_by": "Administrator",
  "module": "CRM",
  "name": "Social Media Post",
  "owner": "Administrator",
  "permissions": [
   {
+   "cancel": 1,
    "create": 1,
    "delete": 1,
    "email": 1,
@@ -157,6 +194,35 @@
    "report": 1,
    "role": "System Manager",
    "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "cancel": 1,
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Sales User",
+   "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "cancel": 1,
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Sales Manager",
+   "share": 1,
+   "submit": 1,
    "write": 1
   }
  ],
diff --git a/erpnext/education/doctype/program_course/program_course.json b/erpnext/education/doctype/program_course/program_course.json
index a24e88a..940358e 100644
--- a/erpnext/education/doctype/program_course/program_course.json
+++ b/erpnext/education/doctype/program_course/program_course.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "creation": "2015-09-07 14:37:01.886859",
  "doctype": "DocType",
  "editable_grid": 1,
@@ -16,26 +17,33 @@
    "in_list_view": 1,
    "label": "Course",
    "options": "Course",
-   "reqd": 1
+   "reqd": 1,
+   "show_days": 1,
+   "show_seconds": 1
   },
-   {
+  {
+   "fetch_from": "course.course_name",
    "fieldname": "course_name",
    "fieldtype": "Data",
    "in_list_view": 1,
    "label": "Course Name",
-   "fetch_from": "course.course_name",
-   "read_only":1
+   "read_only": 1,
+   "show_days": 1,
+   "show_seconds": 1
   },
   {
    "default": "0",
    "fieldname": "required",
    "fieldtype": "Check",
    "in_list_view": 1,
-   "label": "Mandatory"
+   "label": "Mandatory",
+   "show_days": 1,
+   "show_seconds": 1
   }
  ],
  "istable": 1,
- "modified": "2019-06-12 12:42:12.845972",
+ "links": [],
+ "modified": "2020-06-09 18:56:10.213241",
  "modified_by": "Administrator",
  "module": "Education",
  "name": "Program Course",
@@ -45,4 +53,4 @@
  "sort_field": "modified",
  "sort_order": "DESC",
  "track_changes": 1
-}
+}
\ No newline at end of file
diff --git a/erpnext/hr/desk_page/hr/hr.json b/erpnext/hr/desk_page/hr/hr.json
index 7ac000b..1c24444 100644
--- a/erpnext/hr/desk_page/hr/hr.json
+++ b/erpnext/hr/desk_page/hr/hr.json
@@ -18,7 +18,7 @@
   {
    "hidden": 0,
    "label": "Leaves",
-   "links": "[\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Application\",\n        \"name\": \"Leave Application\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Allocation\",\n        \"name\": \"Leave Allocation\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Leave Type\"\n        ],\n        \"label\": \"Leave Policy\",\n        \"name\": \"Leave Policy\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Period\",\n        \"name\": \"Leave Period\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Leave Type\",\n        \"name\": \"Leave Type\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Holiday List\",\n        \"name\": \"Holiday List\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Compensatory Leave Request\",\n        \"name\": \"Compensatory Leave Request\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Encashment\",\n        \"name\": \"Leave Encashment\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Leave Block List\",\n        \"name\": \"Leave Block List\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Leave Application\"\n        ],\n        \"doctype\": \"Leave Application\",\n        \"is_query_report\": true,\n        \"label\": \"Employee Leave Balance\",\n        \"name\": \"Employee Leave Balance\",\n        \"type\": \"report\"\n    }\n]"
+   "links": "[\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Application\",\n        \"name\": \"Leave Application\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Allocation\",\n        \"name\": \"Leave Allocation\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Leave Type\"\n        ],\n        \"label\": \"Leave Policy\",\n        \"name\": \"Leave Policy\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Leave Period\",\n        \"name\": \"Leave Period\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Leave Type\",\n        \"name\": \"Leave Type\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Holiday List\",\n        \"name\": \"Holiday List\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Compensatory Leave Request\",\n        \"name\": \"Compensatory Leave Request\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Employee\"\n        ],\n        \"label\": \"Leave Encashment\",\n        \"name\": \"Leave Encashment\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"label\": \"Leave Block List\",\n        \"name\": \"Leave Block List\",\n        \"type\": \"doctype\"\n    },\n    {\n        \"dependencies\": [\n            \"Leave Application\"\n        ],\n        \"doctype\": \"Leave Application\",\n        \"is_query_report\": true,\n        \"label\": \"Employee Leave Balance\",\n        \"name\": \"Employee Leave Balance\",\n        \"type\": \"report\"\n    }\n]"
   },
   {
    "hidden": 0,
@@ -93,7 +93,7 @@
  "idx": 0,
  "is_standard": 1,
  "label": "HR",
- "modified": "2020-05-28 13:36:07.710600",
+ "modified": "2020-06-10 12:41:41.695669",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "HR",
diff --git a/erpnext/hr/doctype/attendance/attendance.json b/erpnext/hr/doctype/attendance/attendance.json
index 906f6f7..a656a7e 100644
--- a/erpnext/hr/doctype/attendance/attendance.json
+++ b/erpnext/hr/doctype/attendance/attendance.json
@@ -19,11 +19,15 @@
   "attendance_date",
   "company",
   "department",
-  "shift",
   "attendance_request",
-  "amended_from",
+  "details_section",
+  "shift",
+  "in_time",
+  "out_time",
+  "column_break_18",
   "late_entry",
-  "early_exit"
+  "early_exit",
+  "amended_from"
  ],
  "fields": [
   {
@@ -172,13 +176,36 @@
    "fieldname": "early_exit",
    "fieldtype": "Check",
    "label": "Early Exit"
+  },
+  {
+   "fieldname": "details_section",
+   "fieldtype": "Section Break",
+   "label": "Details"
+  },
+  {
+   "depends_on": "shift",
+   "fieldname": "in_time",
+   "fieldtype": "Datetime",
+   "label": "In Time",
+   "read_only": 1
+  },
+  {
+   "depends_on": "shift",
+   "fieldname": "out_time",
+   "fieldtype": "Datetime",
+   "label": "Out Time",
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_18",
+   "fieldtype": "Column Break"
   }
  ],
  "icon": "fa fa-ok",
  "idx": 1,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-04-11 11:40:14.319496",
+ "modified": "2020-05-29 13:51:37.177231",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "Attendance",
diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.js b/erpnext/hr/doctype/employee_advance/employee_advance.js
index 6cc49cf..cba8ee9 100644
--- a/erpnext/hr/doctype/employee_advance/employee_advance.js
+++ b/erpnext/hr/doctype/employee_advance/employee_advance.js
@@ -139,13 +139,13 @@
 	employee: function (frm) {
 		if (frm.doc.employee) {
 			return frappe.call({
-				method: "erpnext.hr.doctype.employee_advance.employee_advance.get_due_advance_amount",
+				method: "erpnext.hr.doctype.employee_advance.employee_advance.get_pending_amount",
 				args: {
 					"employee": frm.doc.employee,
 					"posting_date": frm.doc.posting_date
 				},
 				callback: function(r) {
-					frm.set_value("due_advance_amount",r.message);
+					frm.set_value("pending_amount",r.message);
 				}
 			});
 		}
diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.json b/erpnext/hr/doctype/employee_advance/employee_advance.json
index 8c5ce42..0d90913 100644
--- a/erpnext/hr/doctype/employee_advance/employee_advance.json
+++ b/erpnext/hr/doctype/employee_advance/employee_advance.json
@@ -19,7 +19,7 @@
   "column_break_11",
   "advance_amount",
   "paid_amount",
-  "due_advance_amount",
+  "pending_amount",
   "claimed_amount",
   "return_amount",
   "section_break_7",
@@ -103,14 +103,6 @@
    "read_only": 1
   },
   {
-   "depends_on": "eval:cur_frm.doc.employee",
-   "fieldname": "due_advance_amount",
-   "fieldtype": "Currency",
-   "label": "Due Advance Amount",
-   "options": "Company:company:default_currency",
-   "read_only": 1
-  },
-  {
    "fieldname": "claimed_amount",
    "fieldtype": "Currency",
    "label": "Claimed Amount",
@@ -177,11 +169,19 @@
    "fieldname": "repay_unclaimed_amount_from_salary",
    "fieldtype": "Check",
    "label": "Repay unclaimed amount from salary"
+  },
+  {
+   "depends_on": "eval:cur_frm.doc.employee",
+   "fieldname": "pending_amount",
+   "fieldtype": "Currency",
+   "label": "Pending Amount",
+   "options": "Company:company:default_currency",
+   "read_only": 1
   }
  ],
  "is_submittable": 1,
  "links": [],
- "modified": "2020-03-06 15:11:33.747535",
+ "modified": "2020-06-12 12:42:39.833818",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "Employee Advance",
diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.py b/erpnext/hr/doctype/employee_advance/employee_advance.py
index db39eff..a49dfcf 100644
--- a/erpnext/hr/doctype/employee_advance/employee_advance.py
+++ b/erpnext/hr/doctype/employee_advance/employee_advance.py
@@ -95,7 +95,7 @@
 		frappe.db.set_value("Employee Advance", self.name, "status", self.status)
 
 @frappe.whitelist()
-def get_due_advance_amount(employee, posting_date):
+def get_pending_amount(employee, posting_date):
 	employee_due_amount = frappe.get_all("Employee Advance", \
 		filters = {"employee":employee, "docstatus":1, "posting_date":("<=", posting_date)}, \
 		fields = ["advance_amount", "paid_amount"])
diff --git a/erpnext/hr/doctype/employee_checkin/employee_checkin.py b/erpnext/hr/doctype/employee_checkin/employee_checkin.py
index 8670512..15fbd4e 100644
--- a/erpnext/hr/doctype/employee_checkin/employee_checkin.py
+++ b/erpnext/hr/doctype/employee_checkin/employee_checkin.py
@@ -72,7 +72,7 @@
 	return doc
 
 
-def mark_attendance_and_link_log(logs, attendance_status, attendance_date, working_hours=None, late_entry=False, early_exit=False, shift=None):
+def mark_attendance_and_link_log(logs, attendance_status, attendance_date, working_hours=None, late_entry=False, early_exit=False, in_time=None, out_time=None, shift=None):
 	"""Creates an attendance and links the attendance to the Employee Checkin.
 	Note: If attendance is already present for the given date, the logs are marked as skipped and no exception is thrown.
 
@@ -100,7 +100,9 @@
 				'company': employee_doc.company,
 				'shift': shift,
 				'late_entry': late_entry,
-				'early_exit': early_exit
+				'early_exit': early_exit,
+				'in_time': in_time,
+				'out_time': out_time
 			}
 			attendance = frappe.get_doc(doc_dict).insert()
 			attendance.submit()
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index fb23103..6bb9af9 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -243,7 +243,6 @@
 	},
 
 	update_employee_advance_claimed_amount: function(frm) {
-		console.log("update_employee_advance_claimed_amount")
 		let amount_to_be_allocated = frm.doc.grand_total;
 		$.each(frm.doc.advances || [], function(i, advance){
 			if (amount_to_be_allocated >= advance.unclaimed_amount){
@@ -295,6 +294,16 @@
 		frm.events.get_advances(frm);
 	},
 
+	cost_center: function(frm) {
+		frm.events.set_child_cost_center(frm);
+	},
+	set_child_cost_center: function(frm){
+		(frm.doc.expenses || []).forEach(function(d) {
+			if (!d.cost_center){
+				d.cost_center = frm.doc.cost_center;
+			}
+		});
+	},
 	get_taxes: function(frm) {
 		if(frm.doc.taxes) {
 			frappe.call({
@@ -338,8 +347,7 @@
 
 frappe.ui.form.on("Expense Claim Detail", {
 	expenses_add: function(frm, cdt, cdn) {
-		var row = frappe.get_doc(cdt, cdn);
-		frm.script_manager.copy_from_first_row("expenses", row, ["cost_center"]);
+		frm.events.set_child_cost_center(frm);
 	},
 	amount: function(frm, cdt, cdn) {
 		var child = locals[cdt][cdn];
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 15ce468..fb1f2c0 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -46,6 +46,7 @@
 
 	make_dashboard: function(frm) {
 		var leave_details;
+		let lwps;
 		if (frm.doc.employee) {
 			frappe.call({
 				method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_details",
@@ -61,6 +62,7 @@
 					if (!r.exc && r.message['leave_approver']) {
 						frm.set_value('leave_approver', r.message['leave_approver']);
 					}
+					lwps = r.message["lwps"];
 				}
 			});
 			$("div").remove(".form-dashboard-section.custom");
@@ -70,12 +72,17 @@
 				})
 			);
 			frm.dashboard.show();
+			let allowed_leave_types =  Object.keys(leave_details);
+
+			// lwps should be allowed, lwps don't have any allocation
+			allowed_leave_types = allowed_leave_types.concat(lwps);
+
 			frm.set_query('leave_type', function(){
 				return {
 					filters : [
-						['leave_type_name', 'in', Object.keys(leave_details)]
+						['leave_type_name', 'in', allowed_leave_types]
 					]
-				}
+				};
 			});
 		}
 	},
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index c2b4cdf..0423824 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -19,7 +19,6 @@
 
 from frappe.model.document import Document
 class LeaveApplication(Document):
-
 	def get_feed(self):
 		return _("{0}: From {0} of type {1}").format(self.employee_name, self.leave_type)
 
@@ -463,9 +462,14 @@
 			"pending_leaves": leaves_pending,
 			"remaining_leaves": remaining_leaves}
 
+	#is used in set query
+	lwps = frappe.get_list("Leave Type", filters = {"is_lwp": 1})
+	lwps = [lwp.name for lwp in lwps]
+
 	ret = {
 		'leave_allocation': leave_allocation,
-		'leave_approver': get_leave_approver(employee)
+		'leave_approver': get_leave_approver(employee),
+		'lwps': lwps
 	}
 
 	return ret
diff --git a/erpnext/hr/doctype/shift_type/shift_type.py b/erpnext/hr/doctype/shift_type/shift_type.py
index d56080e..1973564 100644
--- a/erpnext/hr/doctype/shift_type/shift_type.py
+++ b/erpnext/hr/doctype/shift_type/shift_type.py
@@ -28,13 +28,14 @@
 		logs = frappe.db.get_list('Employee Checkin', fields="*", filters=filters, order_by="employee,time")
 		for key, group in itertools.groupby(logs, key=lambda x: (x['employee'], x['shift_actual_start'])):
 			single_shift_logs = list(group)
-			attendance_status, working_hours, late_entry, early_exit = self.get_attendance(single_shift_logs)
-			mark_attendance_and_link_log(single_shift_logs, attendance_status, key[1].date(), working_hours, late_entry, early_exit, self.name)
+			attendance_status, working_hours, late_entry, early_exit, in_time, out_time = self.get_attendance(single_shift_logs)
+			mark_attendance_and_link_log(single_shift_logs, attendance_status, key[1].date(), working_hours, late_entry, early_exit, in_time, out_time, self.name)
 		for employee in self.get_assigned_employee(self.process_attendance_after, True):
 			self.mark_absent_for_dates_with_no_attendance(employee)
 
 	def get_attendance(self, logs):
-		"""Return attendance_status, working_hours for a set of logs belonging to a single shift.
+		"""Return attendance_status, working_hours, late_entry, early_exit, in_time, out_time
+		for a set of logs belonging to a single shift.
 		Assumtion:
 			1. These logs belongs to an single shift, single employee and is not in a holiday date.
 			2. Logs are in chronological order
@@ -48,10 +49,10 @@
 			early_exit = True
 
 		if self.working_hours_threshold_for_absent and total_working_hours < self.working_hours_threshold_for_absent:
-			return 'Absent', total_working_hours, late_entry, early_exit
+			return 'Absent', total_working_hours, late_entry, early_exit, in_time, out_time
 		if self.working_hours_threshold_for_half_day and total_working_hours < self.working_hours_threshold_for_half_day:
-			return 'Half Day', total_working_hours, late_entry, early_exit
-		return 'Present', total_working_hours, late_entry, early_exit
+			return 'Half Day', total_working_hours, late_entry, early_exit, in_time, out_time
+		return 'Present', total_working_hours, late_entry, early_exit, in_time, out_time
 
 	def mark_absent_for_dates_with_no_attendance(self, employee):
 		"""Marks Absents for the given employee on working days in this shift which have no attendance marked.
diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py
index cd12510..8d95924 100644
--- a/erpnext/hr/utils.py
+++ b/erpnext/hr/utils.py
@@ -73,11 +73,11 @@
 	def assign_task_to_users(self, task, users):
 		for user in users:
 			args = {
-				'assign_to' 	:	user,
-				'doctype'		:	task.doctype,
-				'name'			:	task.name,
-				'description'	:	task.description or task.subject,
-				'notify':	self.notify_users_by_email
+				'assign_to': [user],
+				'doctype': task.doctype,
+				'name': task.name,
+				'description': task.description or task.subject,
+				'notify': self.notify_users_by_email
 			}
 			assign_to.add(args)
 
diff --git a/erpnext/non_profit/doctype/member/member.py b/erpnext/non_profit/doctype/member/member.py
index 571f87a..d1294cc 100644
--- a/erpnext/non_profit/doctype/member/member.py
+++ b/erpnext/non_profit/doctype/member/member.py
@@ -77,6 +77,7 @@
 	customer = frappe.new_doc("Customer")
 	customer.customer_name = user_details.fullname
 	customer.customer_type = "Individual"
+	customer.flags.ignore_mandatory = True
 	customer.insert(ignore_permissions=True)
 
 	try:
@@ -91,7 +92,11 @@
 			"link_name": customer.name
 		})
 
-		contact.insert()
+		contact.save()
+
+	except frappe.DuplicateEntryError:
+		return customer.name
+
 	except Exception as e:
 		frappe.log_error(frappe.get_traceback(), _("Contact Creation Failed"))
 		pass
diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py
index 4b93242..7a0caed 100644
--- a/erpnext/non_profit/doctype/membership/membership.py
+++ b/erpnext/non_profit/doctype/membership/membership.py
@@ -62,7 +62,10 @@
 					'subscription_id': subscription_id,
 					'email_id': email
 				}, order_by="creation desc")
-	return frappe.get_doc("Member", members[0]['name'])
+	try:
+		return frappe.get_doc("Member", members[0]['name'])
+	except:
+		return None
 
 def verify_signature(data):
 	signature = frappe.request.headers.get('X-Razorpay-Signature')
@@ -77,7 +80,7 @@
 
 @frappe.whitelist(allow_guest=True)
 def trigger_razorpay_subscription(*args, **kwargs):
-	data = frappe.request.get_data()
+	data = frappe.request.get_data(as_text=True)
 	verify_signature(data)
 
 	if isinstance(data, six.string_types):
@@ -96,7 +99,10 @@
 	except Exception as e:
 		error_log = frappe.log_error(frappe.get_traceback() + '\n' + data_json , _("Membership Webhook Failed"))
 		notify_failure(error_log)
-		raise e
+		return False
+
+	if not member:
+		return False
 
 	if data.event == "subscription.activated":
 		member.customer_id = payment.customer_id
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index b0421f4..a0707b7 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -680,6 +680,8 @@
 erpnext.patches.v12_0.retain_permission_rules_for_video_doctype
 erpnext.patches.v12_0.remove_duplicate_leave_ledger_entries #2020-05-22
 erpnext.patches.v13_0.patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive
+execute:frappe.reload_doc("HR", "doctype", "Employee Advance")
+erpnext.patches.v12_0.move_due_advance_amount_to_pending_amount
 execute:frappe.delete_doc_if_exists("Page", "appointment-analytic")
 execute:frappe.rename_doc("Desk Page", "Getting Started", "Home", force=True)
 erpnext.patches.v12_0.unset_customer_supplier_based_on_type_of_item_price
@@ -694,4 +696,4 @@
 execute:frappe.rename_doc("Desk Page", "Loan Management", "Loan", force=True)
 erpnext.patches.v12_0.update_uom_conversion_factor
 erpnext.patches.v13_0.delete_old_purchase_reports
-erpnext.patches.v12_0.set_italian_import_supplier_invoice_permissions
\ No newline at end of file
+erpnext.patches.v12_0.set_italian_import_supplier_invoice_permissions
diff --git a/erpnext/patches/v12_0/move_due_advance_amount_to_pending_amount.py b/erpnext/patches/v12_0/move_due_advance_amount_to_pending_amount.py
new file mode 100644
index 0000000..f1ffaf9
--- /dev/null
+++ b/erpnext/patches/v12_0/move_due_advance_amount_to_pending_amount.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2019, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+    ''' Move from due_advance_amount to pending_amount '''
+    frappe.db.sql(''' UPDATE `tabEmployee Advance` SET pending_amount=due_advance_amount ''')
diff --git a/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py b/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py
index a7d4c66..be5e30f 100644
--- a/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py
+++ b/erpnext/patches/v13_0/set_company_field_in_healthcare_doctypes.py
@@ -7,4 +7,4 @@
 	for entry in doctypes:
 		if frappe.db.exists('DocType', entry):
 			frappe.reload_doc('Healthcare', 'doctype', entry)
-			frappe.db.sql("update `tab{dt}` set company = '{company}' where ifnull(company, '') = ''".format(dt=entry, company=company))
+			frappe.db.sql("update `tab{dt}` set company = {company} where ifnull(company, '') = ''".format(dt=entry, company=frappe.db.escape(company)))
diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js
index 5862963..3570a0f 100644
--- a/erpnext/projects/doctype/project/project.js
+++ b/erpnext/projects/doctype/project/project.js
@@ -18,7 +18,7 @@
 		};
 	},
 	onload: function (frm) {
-		var so = frm.get_docfield("Project", "sales_order");
+		var so = frappe.meta.get_docfield("Project", "sales_order");
 		so.get_route_options_for_new_doc = function (field) {
 			if (frm.is_new()) return;
 			return {
@@ -135,4 +135,4 @@
 		frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
 	});
 
-}
+}
\ No newline at end of file
diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js
index 3eea390..defc18b 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.js
+++ b/erpnext/projects/doctype/timesheet/timesheet.js
@@ -258,7 +258,12 @@
 
 var update_billing_hours = function(frm, cdt, cdn){
 	var child = locals[cdt][cdn];
-	if(!child.billable) frappe.model.set_value(cdt, cdn, 'billing_hours', 0.0);
+	if(!child.billable) {
+		frappe.model.set_value(cdt, cdn, 'billing_hours', 0.0);
+	} else {
+		// bill all hours by default
+		frappe.model.set_value(cdt, cdn, "billing_hours", child.hours);
+	}
 };
 
 var update_time_rates = function(frm, cdt, cdn){
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 9421668..ca897dd 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -552,7 +552,8 @@
 									if (show_batch_dialog)
 										return frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
 											.then((r) => {
-												if(r.message.has_batch_no || r.message.has_serial_no) {
+												if (r.message &&
+													(r.message.has_batch_no || r.message.has_serial_no)) {
 													frappe.flags.hide_serial_batch_dialog = false;
 												}
 											});
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index a6889e0..ac3bc20 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -3,16 +3,19 @@
 
 from __future__ import unicode_literals
 import frappe
+import json
 from frappe.model.naming import set_name_by_naming_series
-from frappe import _, msgprint, throw
+from frappe import _, msgprint
 import frappe.defaults
-from frappe.utils import flt, cint, cstr, today
+from frappe.utils import flt, cint, cstr, today, get_formatted_email
 from frappe.desk.reportview import build_match_conditions, get_filters_cond
 from erpnext.utilities.transaction_base import TransactionBase
 from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
 from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address
 from frappe.model.rename_doc import update_linked_doctypes
 from frappe.model.mapper import get_mapped_doc
+from frappe.utils.user import get_users_with_role
+
 
 class Customer(TransactionBase):
 	def get_feed(self):
@@ -378,10 +381,45 @@
 			.format(customer, customer_outstanding, credit_limit))
 
 		# If not authorized person raise exception
-		credit_controller = frappe.db.get_value('Accounts Settings', None, 'credit_controller')
-		if not credit_controller or credit_controller not in frappe.get_roles():
-			throw(_("Please contact to the user who have Sales Master Manager {0} role")
-				.format(" / " + credit_controller if credit_controller else ""))
+		credit_controller_role = frappe.db.get_single_value('Accounts Settings', 'credit_controller')
+		if not credit_controller_role or credit_controller_role not in frappe.get_roles():
+			# form a list of emails for the credit controller users
+			credit_controller_users = get_users_with_role(credit_controller_role or "Sales Master Manager")
+
+			# form a list of emails and names to show to the user
+			credit_controller_users_list = [user for user in credit_controller_users if frappe.db.exists("Employee", {"prefered_email": user})]
+			credit_controller_users = [get_formatted_email(user).replace("<", "(").replace(">", ")") for user in credit_controller_users_list]
+
+			if not credit_controller_users:
+				frappe.throw(_("Please contact your administrator to extend the credit limits for {0}.".format(customer)))
+
+			message = """Please contact any of the following users to extend the credit limits for {0}:
+				<br><br><ul><li>{1}</li></ul>""".format(customer, '<li>'.join(credit_controller_users))
+
+			# if the current user does not have permissions to override credit limit,
+			# prompt them to send out an email to the controller users
+			frappe.msgprint(message,
+				title="Notify",
+				raise_exception=1,
+				primary_action={
+					'label': 'Send Email',
+					'server_action': 'erpnext.selling.doctype.customer.customer.send_emails',
+					'args': {
+						'customer': customer,
+						'customer_outstanding': customer_outstanding,
+						'credit_limit': credit_limit,
+						'credit_controller_users_list': credit_controller_users_list
+					}
+				}
+			)
+
+@frappe.whitelist()
+def send_emails(args):
+	args = json.loads(args)
+	subject = (_("Credit limit reached for customer {0}").format(args.get('customer')))
+	message = (_("Credit limit has been crossed for customer {0} ({1}/{2})")
+			.format(args.get('customer'), args.get('customer_outstanding'), args.get('credit_limit')))
+	frappe.sendmail(recipients=[args.get('credit_controller_users_list')], subject=subject, message=message)
 
 def get_customer_outstanding(customer, company, ignore_outstanding_sales_order=False, cost_center=None):
 	# Outstanding based on GL Entries
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index d04c8c2..7096c17 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -337,21 +337,17 @@
 def _set_price_list(cart_settings, quotation=None):
 	"""Set price list based on customer or shopping cart default"""
 	from erpnext.accounts.party import get_default_price_list
-
-	# check if customer price list exists
+	party_name = quotation.get("party_name") if quotation else get_party().get("name")
 	selling_price_list = None
-	if quotation and quotation.get("party_name"):
-		selling_price_list = frappe.db.get_value('Customer', quotation.get("party_name"), 'default_price_list')
 
-	# else check for territory based price list
+	# check if default customer price list exists
+	if party_name:
+		selling_price_list = get_default_price_list(frappe.get_doc("Customer", party_name))
+
+	# check default price list in shopping cart
 	if not selling_price_list:
 		selling_price_list = cart_settings.price_list
 
-	party_name = quotation.get("party_name") if quotation else get_party().get("name")
-
-	if not selling_price_list and party_name:
-		selling_price_list = get_default_price_list(frappe.get_doc("Customer", party_name))
-
 	if quotation:
 		quotation.selling_price_list = selling_price_list
 
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index 93b29c8..4b8b594 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -119,11 +119,13 @@
 		if item_location.serial_no:
 			serial_nos = '\n'.join(item_location.serial_no[0: cint(stock_qty)])
 
+		auto_set_serial_no = frappe.db.get_single_value("Stock Settings", "automatically_set_serial_nos_based_on_fifo")
+
 		locations.append(frappe._dict({
 			'qty': qty,
 			'stock_qty': stock_qty,
 			'warehouse': item_location.warehouse,
-			'serial_no': serial_nos,
+			'serial_no': serial_nos if auto_set_serial_no else item_doc.serial_no,
 			'batch_no': item_location.batch_no
 		}))
 
@@ -206,6 +208,7 @@
 			sle.batch_no = batch.name
 			and sle.`item_code`=%(item_code)s
 			and sle.`company` = %(company)s
+			and batch.disabled = 0
 			and IFNULL(batch.`expiry_date`, '2200-01-01') > %(today)s
 			{warehouse_condition}
 		GROUP BY
@@ -471,4 +474,4 @@
 	item.material_request = location.material_request
 	item.serial_no = location.serial_no
 	item.batch_no = location.batch_no
-	item.material_request_item = location.material_request_item
\ No newline at end of file
+	item.material_request_item = location.material_request_item
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 18d6853..5fbd512 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -500,7 +500,7 @@
 					if raw_material_cost and self.purpose == "Manufacture":
 						d.basic_rate = flt((raw_material_cost - scrap_material_cost) / flt(d.transfer_qty), d.precision("basic_rate"))
 						d.basic_amount = flt((raw_material_cost - scrap_material_cost), d.precision("basic_amount"))
-					elif self.purpose == "Repack" and total_fg_qty:
+					elif self.purpose == "Repack" and total_fg_qty and not d.set_basic_rate_manually:
 						d.basic_rate = flt(raw_material_cost) / flt(total_fg_qty)
 						d.basic_amount = d.basic_rate * d.qty
 
diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
index c16a41c..7b9c129 100644
--- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
+++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
@@ -23,6 +23,7 @@
   "image",
   "image_view",
   "quantity_and_rate",
+  "set_basic_rate_manually",
   "qty",
   "basic_rate",
   "basic_amount",
@@ -491,12 +492,21 @@
    "no_copy": 1,
    "print_hide": 1,
    "read_only": 1
+  },
+  {
+   "default": "0",
+   "depends_on": "eval:parent.purpose===\"Repack\" && doc.t_warehouse",
+   "fieldname": "set_basic_rate_manually",
+   "fieldtype": "Check",
+   "label": "Set Basic Rate Manually",
+   "show_days": 1,
+   "show_seconds": 1
   }
  ],
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2020-04-23 19:19:28.539769",
+ "modified": "2020-06-08 12:57:03.172887",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Stock Entry Detail",
diff --git a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py
index 9a97210..5df3fa8 100644
--- a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py
+++ b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py
@@ -8,7 +8,7 @@
 
 def execute(filters=None):
 	if not filters: filters = {}
-	float_preceision = frappe.db.get_default("float_preceision")
+	float_precision = frappe.db.get_default("float_precision")
 
 	condition = get_condition(filters)
 
@@ -25,7 +25,7 @@
 	data = []
 	for item in items:
 		total_outgoing = flt(consumed_item_map.get(item.name, 0)) + flt(delivered_item_map.get(item.name,0))
-		avg_daily_outgoing = flt(total_outgoing / diff, float_preceision)
+		avg_daily_outgoing = flt(total_outgoing / diff, float_precision)
 		reorder_level = (avg_daily_outgoing * flt(item.lead_time_days)) + flt(item.safety_stock)
 
 		data.append([item.name, item.item_name, item.item_group, item.brand, item.description,
diff --git a/erpnext/stock/report/stock_ageing/stock_ageing.py b/erpnext/stock/report/stock_ageing/stock_ageing.py
index af99780..723ed5c 100644
--- a/erpnext/stock/report/stock_ageing/stock_ageing.py
+++ b/erpnext/stock/report/stock_ageing/stock_ageing.py
@@ -180,10 +180,10 @@
 				qty_to_pop = abs(d.actual_qty)
 				while qty_to_pop:
 					batch = fifo_queue[0] if fifo_queue else [0, None]
-					if 0 < batch[0] <= qty_to_pop:
+					if 0 < flt(batch[0]) <= qty_to_pop:
 						# if batch qty > 0
 						# not enough or exactly same qty in current batch, clear batch
-						qty_to_pop -= batch[0]
+						qty_to_pop -= flt(batch[0])
 						transferred_item_details[(d.voucher_no, d.name)].append(fifo_queue.pop(0))
 					else:
 						# all from current batch
@@ -262,4 +262,4 @@
 			]
 		},
 		"type" : "bar"
-	}
\ No newline at end of file
+	}
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index f21dc3f..11e758f 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -230,12 +230,12 @@
 
 def get_fifo_rate(previous_stock_queue, qty):
 	"""get FIFO (average) Rate from Queue"""
-	if qty >= 0:
+	if flt(qty) >= 0:
 		total = sum(f[0] for f in previous_stock_queue)
 		return sum(flt(f[0]) * flt(f[1]) for f in previous_stock_queue) / flt(total) if total else 0.0
 	else:
 		available_qty_for_outgoing, outgoing_cost = 0, 0
-		qty_to_pop = abs(qty)
+		qty_to_pop = abs(flt(qty))
 		while qty_to_pop and previous_stock_queue:
 			batch = previous_stock_queue[0]
 			if 0 < batch[0] <= qty_to_pop: