Merge pull request #21404 from abhishekbalam/develop

feat(Accounts): Journal Entry Templates v1
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry_list.js b/erpnext/accounts/doctype/payment_entry/payment_entry_list.js
new file mode 100644
index 0000000..7ea60bb
--- /dev/null
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry_list.js
@@ -0,0 +1,12 @@
+frappe.listview_settings['Payment Entry'] = {
+
+	onload: function(listview) {
+		listview.page.fields_dict.party_type.get_query = function() {
+			return {
+				"filters": {
+					"name": ["in", Object.keys(frappe.boot.party_account_types)],
+				}
+			};
+		};
+	}
+};
\ No newline at end of file
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 47dfa09..6e5b33f 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -600,10 +600,12 @@
 	else:
 		return ''
 
-def get_partywise_advanced_payment_amount(party_type, posting_date = None):
+def get_partywise_advanced_payment_amount(party_type, posting_date = None, company=None):
 	cond = "1=1"
 	if posting_date:
 		cond = "posting_date <= '{0}'".format(posting_date)
+	if company:
+		cond += "and company = '{0}'".format(company)
 
 	data = frappe.db.sql(""" SELECT party, sum({0}) as amount
 		FROM `tabGL Entry`
diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
index b607c0f..aa6b42e 100644
--- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
+++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
@@ -33,7 +33,7 @@
 		self.get_party_total(args)
 
 		party_advance_amount = get_partywise_advanced_payment_amount(self.party_type,
-			self.filters.report_date) or {}
+			self.filters.report_date, self.filters.company) or {}
 
 		for party, party_dict in iteritems(self.party_total):
 			if party_dict.outstanding == 0:
diff --git a/erpnext/hr/doctype/leave_application/leave_application.json b/erpnext/hr/doctype/leave_application/leave_application.json
index cdb1add..5e45155 100644
--- a/erpnext/hr/doctype/leave_application/leave_application.json
+++ b/erpnext/hr/doctype/leave_application/leave_application.json
@@ -1,332 +1,337 @@
 {
-   "allow_import": 1,
-   "autoname": "naming_series:",
-   "creation": "2013-02-20 11:18:11",
-   "description": "Apply / Approve Leaves",
-   "doctype": "DocType",
-   "document_type": "Document",
-   "engine": "InnoDB",
-   "field_order": [
-    "naming_series",
-    "employee",
-    "employee_name",
-    "column_break_4",
-    "leave_type",
-    "department",
-    "leave_balance",
-    "section_break_5",
-    "from_date",
-    "to_date",
-    "half_day",
-    "half_day_date",
-    "total_leave_days",
-    "column_break1",
-    "description",
-    "section_break_7",
-    "leave_approver",
-    "leave_approver_name",
-    "column_break_18",
-    "status",
-    "salary_slip",
-    "sb10",
-    "posting_date",
-    "follow_via_email",
-    "color",
-    "column_break_17",
-    "company",
-    "letter_head",
-    "amended_from"
-   ],
-   "fields": [
-    {
-     "fieldname": "naming_series",
-     "fieldtype": "Select",
-     "label": "Series",
-     "no_copy": 1,
-     "options": "HR-LAP-.YYYY.-",
-     "print_hide": 1,
-     "reqd": 1,
-     "set_only_once": 1
-    },
-    {
-     "fieldname": "employee",
-     "fieldtype": "Link",
-     "in_global_search": 1,
-     "in_standard_filter": 1,
-     "label": "Employee",
-     "options": "Employee",
-     "reqd": 1,
-     "search_index": 1
-    },
-    {
-     "fieldname": "employee_name",
-     "fieldtype": "Data",
-     "in_global_search": 1,
-     "label": "Employee Name",
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_4",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "leave_type",
-     "fieldtype": "Link",
-     "ignore_user_permissions": 1,
-     "in_standard_filter": 1,
-     "label": "Leave Type",
-     "options": "Leave Type",
-     "reqd": 1,
-     "search_index": 1
-    },
-    {
-     "fetch_from": "employee.department",
-     "fieldname": "department",
-     "fieldtype": "Link",
-     "label": "Department",
-     "options": "Department",
-     "read_only": 1
-    },
-    {
-     "fieldname": "leave_balance",
-     "fieldtype": "Float",
-     "label": "Leave Balance Before Application",
-     "no_copy": 1,
-     "read_only": 1
-    },
-    {
-     "fieldname": "section_break_5",
-     "fieldtype": "Section Break"
-    },
-    {
-     "fieldname": "from_date",
-     "fieldtype": "Date",
-     "in_list_view": 1,
-     "label": "From Date",
-     "reqd": 1,
-     "search_index": 1
-    },
-    {
-     "fieldname": "to_date",
-     "fieldtype": "Date",
-     "label": "To Date",
-     "reqd": 1,
-     "search_index": 1
-    },
-    {
-     "default": "0",
-     "fieldname": "half_day",
-     "fieldtype": "Check",
-     "label": "Half Day"
-    },
-    {
-     "depends_on": "eval:doc.half_day && (doc.from_date != doc.to_date)",
-     "fieldname": "half_day_date",
-     "fieldtype": "Date",
-     "label": "Half Day Date"
-    },
-    {
-     "fieldname": "total_leave_days",
-     "fieldtype": "Float",
-     "in_list_view": 1,
-     "label": "Total Leave Days",
-     "no_copy": 1,
-     "precision": "1",
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break1",
-     "fieldtype": "Column Break",
-     "print_width": "50%",
-     "width": "50%"
-    },
-    {
-     "fieldname": "description",
-     "fieldtype": "Small Text",
-     "label": "Reason"
-    },
-    {
-     "fieldname": "section_break_7",
-     "fieldtype": "Section Break"
-    },
-    {
-     "fieldname": "leave_approver",
-     "fieldtype": "Link",
-     "label": "Leave Approver",
-     "options": "User"
-    },
-    {
-     "fieldname": "leave_approver_name",
-     "fieldtype": "Data",
-     "label": "Leave Approver Name",
-     "read_only": 1
-    },
-    {
-     "fieldname": "column_break_18",
-     "fieldtype": "Column Break"
-    },
-    {
-     "default": "Open",
-     "fieldname": "status",
-     "fieldtype": "Select",
-     "in_standard_filter": 1,
-     "label": "Status",
-     "no_copy": 1,
-     "options": "Open\nApproved\nRejected\nCancelled"
-    },
-    {
-     "fieldname": "sb10",
-     "fieldtype": "Section Break"
-    },
-    {
-     "default": "Today",
-     "fieldname": "posting_date",
-     "fieldtype": "Date",
-     "label": "Posting Date",
-     "no_copy": 1,
-     "reqd": 1
-    },
-    {
-     "fieldname": "company",
-     "fieldtype": "Link",
-     "label": "Company",
-     "options": "Company",
-     "remember_last_selected_value": 1,
-     "reqd": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "default": "1",
-     "fieldname": "follow_via_email",
-     "fieldtype": "Check",
-     "label": "Follow via Email",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "column_break_17",
-     "fieldtype": "Column Break"
-    },
-    {
-     "fieldname": "salary_slip",
-     "fieldtype": "Link",
-     "label": "Salary Slip",
-     "options": "Salary Slip",
-     "print_hide": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "letter_head",
-     "fieldtype": "Link",
-     "ignore_user_permissions": 1,
-     "label": "Letter Head",
-     "options": "Letter Head",
-     "print_hide": 1
-    },
-    {
-     "allow_on_submit": 1,
-     "fieldname": "color",
-     "fieldtype": "Color",
-     "label": "Color",
-     "print_hide": 1
-    },
-    {
-     "fieldname": "amended_from",
-     "fieldtype": "Link",
-     "ignore_user_permissions": 1,
-     "label": "Amended From",
-     "no_copy": 1,
-     "options": "Leave Application",
-     "print_hide": 1,
-     "read_only": 1
-    }
-   ],
-   "icon": "fa fa-calendar",
-   "idx": 1,
-   "is_submittable": 1,
-   "max_attachments": 3,
-   "modified": "2019-08-13 13:32:04.860848",
-   "modified_by": "Administrator",
-   "module": "HR",
-   "name": "Leave Application",
-   "owner": "Administrator",
-   "permissions": [
-    {
-     "create": 1,
-     "email": 1,
-     "print": 1,
-     "read": 1,
-     "report": 1,
-     "role": "Employee",
-     "share": 1,
-     "write": 1
-    },
-    {
-     "amend": 1,
-     "cancel": 1,
-     "create": 1,
-     "delete": 1,
-     "email": 1,
-     "export": 1,
-     "print": 1,
-     "read": 1,
-     "report": 1,
-     "role": "HR Manager",
-     "set_user_permissions": 1,
-     "share": 1,
-     "submit": 1,
-     "write": 1
-    },
-    {
-     "permlevel": 1,
-     "read": 1,
-     "role": "All"
-    },
-    {
-     "amend": 1,
-     "cancel": 1,
-     "create": 1,
-     "delete": 1,
-     "email": 1,
-     "print": 1,
-     "read": 1,
-     "report": 1,
-     "role": "HR User",
-     "set_user_permissions": 1,
-     "share": 1,
-     "submit": 1,
-     "write": 1
-    },
-    {
-     "amend": 1,
-     "cancel": 1,
-     "delete": 1,
-     "email": 1,
-     "print": 1,
-     "read": 1,
-     "report": 1,
-     "role": "Leave Approver",
-     "share": 1,
-     "submit": 1,
-     "write": 1
-    },
-    {
-     "permlevel": 1,
-     "read": 1,
-     "report": 1,
-     "role": "HR User",
-     "write": 1
-    },
-    {
-     "permlevel": 1,
-     "read": 1,
-     "report": 1,
-     "role": "Leave Approver",
-     "write": 1
-    }
-   ],
-   "search_fields": "employee,employee_name,leave_type,from_date,to_date,total_leave_days",
-   "sort_field": "modified",
-   "sort_order": "DESC",
-   "timeline_field": "employee",
-   "title_field": "employee_name"
-  }
\ No newline at end of file
+ "actions": [],
+ "allow_import": 1,
+ "autoname": "naming_series:",
+ "creation": "2013-02-20 11:18:11",
+ "description": "Apply / Approve Leaves",
+ "doctype": "DocType",
+ "document_type": "Document",
+ "engine": "InnoDB",
+ "field_order": [
+  "naming_series",
+  "employee",
+  "employee_name",
+  "column_break_4",
+  "leave_type",
+  "department",
+  "leave_balance",
+  "section_break_5",
+  "from_date",
+  "to_date",
+  "half_day",
+  "half_day_date",
+  "total_leave_days",
+  "column_break1",
+  "description",
+  "section_break_7",
+  "leave_approver",
+  "leave_approver_name",
+  "column_break_18",
+  "status",
+  "salary_slip",
+  "sb10",
+  "posting_date",
+  "follow_via_email",
+  "color",
+  "column_break_17",
+  "company",
+  "letter_head",
+  "amended_from"
+ ],
+ "fields": [
+  {
+   "fieldname": "naming_series",
+   "fieldtype": "Select",
+   "label": "Series",
+   "no_copy": 1,
+   "options": "HR-LAP-.YYYY.-",
+   "print_hide": 1,
+   "reqd": 1,
+   "set_only_once": 1
+  },
+  {
+   "fieldname": "employee",
+   "fieldtype": "Link",
+   "in_global_search": 1,
+   "in_standard_filter": 1,
+   "label": "Employee",
+   "options": "Employee",
+   "reqd": 1,
+   "search_index": 1
+  },
+  {
+   "fieldname": "employee_name",
+   "fieldtype": "Data",
+   "in_global_search": 1,
+   "label": "Employee Name",
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_4",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "leave_type",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "in_standard_filter": 1,
+   "label": "Leave Type",
+   "options": "Leave Type",
+   "reqd": 1,
+   "search_index": 1
+  },
+  {
+   "fetch_from": "employee.department",
+   "fieldname": "department",
+   "fieldtype": "Link",
+   "label": "Department",
+   "options": "Department",
+   "read_only": 1
+  },
+  {
+   "fieldname": "leave_balance",
+   "fieldtype": "Float",
+   "label": "Leave Balance Before Application",
+   "no_copy": 1,
+   "read_only": 1
+  },
+  {
+   "fieldname": "section_break_5",
+   "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "from_date",
+   "fieldtype": "Date",
+   "in_list_view": 1,
+   "label": "From Date",
+   "reqd": 1,
+   "search_index": 1
+  },
+  {
+   "fieldname": "to_date",
+   "fieldtype": "Date",
+   "label": "To Date",
+   "reqd": 1,
+   "search_index": 1
+  },
+  {
+   "default": "0",
+   "fieldname": "half_day",
+   "fieldtype": "Check",
+   "label": "Half Day"
+  },
+  {
+   "depends_on": "eval:doc.half_day && (doc.from_date != doc.to_date)",
+   "fieldname": "half_day_date",
+   "fieldtype": "Date",
+   "label": "Half Day Date"
+  },
+  {
+   "fieldname": "total_leave_days",
+   "fieldtype": "Float",
+   "in_list_view": 1,
+   "label": "Total Leave Days",
+   "no_copy": 1,
+   "precision": "1",
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break1",
+   "fieldtype": "Column Break",
+   "print_width": "50%",
+   "width": "50%"
+  },
+  {
+   "fieldname": "description",
+   "fieldtype": "Small Text",
+   "label": "Reason"
+  },
+  {
+   "fieldname": "section_break_7",
+   "fieldtype": "Section Break"
+  },
+  {
+   "fieldname": "leave_approver",
+   "fieldtype": "Link",
+   "label": "Leave Approver",
+   "options": "User"
+  },
+  {
+   "fieldname": "leave_approver_name",
+   "fieldtype": "Data",
+   "label": "Leave Approver Name",
+   "read_only": 1
+  },
+  {
+   "fieldname": "column_break_18",
+   "fieldtype": "Column Break"
+  },
+  {
+   "default": "Open",
+   "fieldname": "status",
+   "fieldtype": "Select",
+   "in_standard_filter": 1,
+   "label": "Status",
+   "no_copy": 1,
+   "options": "Open\nApproved\nRejected\nCancelled",
+   "permlevel": 1
+  },
+  {
+   "fieldname": "sb10",
+   "fieldtype": "Section Break"
+  },
+  {
+   "default": "Today",
+   "fieldname": "posting_date",
+   "fieldtype": "Date",
+   "label": "Posting Date",
+   "no_copy": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "company",
+   "fieldtype": "Link",
+   "label": "Company",
+   "options": "Company",
+   "read_only": 1,
+   "remember_last_selected_value": 1,
+   "reqd": 1,
+   "fetch_from": "employee.company",
+  },
+  {
+   "allow_on_submit": 1,
+   "default": "1",
+   "fieldname": "follow_via_email",
+   "fieldtype": "Check",
+   "label": "Follow via Email",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "column_break_17",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "salary_slip",
+   "fieldtype": "Link",
+   "label": "Salary Slip",
+   "options": "Salary Slip",
+   "print_hide": 1
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "letter_head",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Letter Head",
+   "options": "Letter Head",
+   "print_hide": 1
+  },
+  {
+   "allow_on_submit": 1,
+   "fieldname": "color",
+   "fieldtype": "Color",
+   "label": "Color",
+   "print_hide": 1
+  },
+  {
+   "fieldname": "amended_from",
+   "fieldtype": "Link",
+   "ignore_user_permissions": 1,
+   "label": "Amended From",
+   "no_copy": 1,
+   "options": "Leave Application",
+   "print_hide": 1,
+   "read_only": 1
+  }
+ ],
+ "icon": "fa fa-calendar",
+ "idx": 1,
+ "is_submittable": 1,
+ "links": [],
+ "max_attachments": 3,
+ "modified": "2020-03-10 22:40:43.487721",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Leave Application",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "create": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Employee",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "amend": 1,
+   "cancel": 1,
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR Manager",
+   "set_user_permissions": 1,
+   "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "permlevel": 1,
+   "read": 1,
+   "role": "All"
+  },
+  {
+   "amend": 1,
+   "cancel": 1,
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR User",
+   "set_user_permissions": 1,
+   "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "amend": 1,
+   "cancel": 1,
+   "delete": 1,
+   "email": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Leave Approver",
+   "share": 1,
+   "submit": 1,
+   "write": 1
+  },
+  {
+   "permlevel": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR User",
+   "write": 1
+  },
+  {
+   "permlevel": 1,
+   "read": 1,
+   "report": 1,
+   "role": "Leave Approver",
+   "write": 1
+  }
+ ],
+ "search_fields": "employee,employee_name,leave_type,from_date,to_date,total_leave_days",
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "timeline_field": "employee",
+ "title_field": "employee_name"
+}
diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
index b55b45f..9a9e42e 100644
--- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
+++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
@@ -13,7 +13,7 @@
 	conditions, filters = get_conditions(filters)
 	columns = get_columns(filters)
 	att_map = get_attendance_list(conditions, filters)
-	emp_map = get_employee_details()
+	emp_map = get_employee_details(filters)
 
 	holiday_list = [emp_map[d]["holiday_list"] for d in emp_map if emp_map[d]["holiday_list"]]
 	default_holiday_list = frappe.get_cached_value('Company',  filters.get("company"),  "default_holiday_list")
@@ -140,10 +140,10 @@
 
 	return conditions, filters
 
-def get_employee_details():
+def get_employee_details(filters):
 	emp_map = frappe._dict()
 	for d in frappe.db.sql("""select name, employee_name, designation, department, branch, company,
-		holiday_list from tabEmployee""", as_dict=1):
+		holiday_list from tabEmployee where company = %s""", (filters.get("company")), as_dict=1):
 		emp_map.setdefault(d.name, d)
 
 	return emp_map
diff --git a/erpnext/loan_management/desk_page/loan_management/loan_management.json b/erpnext/loan_management/desk_page/loan_management/loan_management.json
index 691d2c1..f9ea978 100644
--- a/erpnext/loan_management/desk_page/loan_management/loan_management.json
+++ b/erpnext/loan_management/desk_page/loan_management/loan_management.json
@@ -37,7 +37,7 @@
  "idx": 0,
  "is_standard": 1,
  "label": "Loan Management",
- "modified": "2020-04-01 11:28:51.380509",
+ "modified": "2020-04-02 11:28:51.380509",
  "modified_by": "Administrator",
  "module": "Loan Management",
  "name": "Loan Management",
diff --git a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json
index 2d9c45d..c437a98 100644
--- a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json
+++ b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json
@@ -7,17 +7,17 @@
  "engine": "InnoDB",
  "field_order": [
   "against_loan",
-  "disbursement_date",
   "posting_date",
+  "applicant_type",
   "column_break_4",
   "company",
-  "applicant_type",
   "applicant",
   "section_break_7",
+  "disbursement_date",
+  "column_break_8",
   "disbursed_amount",
   "accounting_dimensions_section",
   "cost_center",
-  "section_break_13",
   "customer_details_section",
   "bank_account",
   "amended_from"
@@ -66,6 +66,7 @@
    "read_only": 1
   },
   {
+   "collapsible": 1,
    "fieldname": "accounting_dimensions_section",
    "fieldtype": "Section Break",
    "label": "Accounting Dimensions"
@@ -89,12 +90,8 @@
   },
   {
    "fieldname": "section_break_7",
-   "fieldtype": "Section Break"
-  },
-  {
-   "collapsible": 1,
-   "fieldname": "section_break_13",
-   "fieldtype": "Section Break"
+   "fieldtype": "Section Break",
+   "label": "Disbursement Details"
   },
   {
    "fieldname": "customer_details_section",
@@ -114,11 +111,15 @@
    "fieldtype": "Link",
    "label": "Bank Account",
    "options": "Bank Account"
+  },
+  {
+   "fieldname": "column_break_8",
+   "fieldtype": "Column Break"
   }
  ],
  "is_submittable": 1,
  "links": [],
- "modified": "2020-04-09 14:44:28.527271",
+ "modified": "2020-04-29 05:20:41.629911",
  "modified_by": "Administrator",
  "module": "Loan Management",
  "name": "Loan Disbursement",
diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py
index 87e8a15..a5ed5de 100644
--- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py
+++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py
@@ -106,6 +106,7 @@
 	def allocate_amounts(self, paid_entries):
 		self.set('repayment_details', [])
 		self.principal_amount_paid = 0
+		interest_paid = 0
 
 		if self.amount_paid - self.penalty_amount > 0 and paid_entries:
 			interest_paid = self.amount_paid - self.penalty_amount
@@ -286,7 +287,11 @@
 	pending_principal_amount = against_loan_doc.total_payment - against_loan_doc.total_principal_paid - against_loan_doc.total_interest_payable
 
 	if payment_type == "Loan Closure" and not payable_principal_amount:
-		pending_days = date_diff(posting_date, entry.posting_date) + 1
+		if final_due_date:
+			pending_days = date_diff(posting_date, final_due_date)
+		else:
+			pending_days = date_diff(posting_date, against_loan_doc.disbursement_date) + 1
+
 		payable_principal_amount = pending_principal_amount
 		per_day_interest = (payable_principal_amount * (loan_type_details.rate_of_interest / 100))/365
 		total_pending_interest += (pending_days * per_day_interest)
diff --git a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json
index f27197d..f93b244 100644
--- a/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json
+++ b/erpnext/manufacturing/doctype/material_request_plan_item/material_request_plan_item.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "creation": "2017-12-01 12:12:55.048691",
  "doctype": "DocType",
  "editable_grid": 1,
@@ -6,8 +7,9 @@
  "field_order": [
   "item_code",
   "item_name",
-  "warehouse",
   "material_request_type",
+  "from_warehouse",
+  "warehouse",
   "column_break_4",
   "quantity",
   "uom",
@@ -46,6 +48,7 @@
   {
    "fieldname": "material_request_type",
    "fieldtype": "Select",
+   "in_list_view": 1,
    "label": "Material Request Type",
    "options": "\nPurchase\nMaterial Transfer\nMaterial Issue\nManufacture\nCustomer Provided"
   },
@@ -64,11 +67,11 @@
   {
    "fieldname": "projected_qty",
    "fieldtype": "Float",
-   "in_list_view": 1,
    "label": "Projected Qty",
    "read_only": 1
   },
   {
+   "default": "0",
    "fieldname": "actual_qty",
    "fieldtype": "Float",
    "in_list_view": 1,
@@ -119,10 +122,18 @@
    "label": "UOM",
    "options": "UOM",
    "read_only": 1
+  },
+  {
+   "depends_on": "eval:doc.material_request_type == 'Material Transfer'",
+   "fieldname": "from_warehouse",
+   "fieldtype": "Link",
+   "label": "From Warehouse",
+   "options": "Warehouse"
   }
  ],
  "istable": 1,
- "modified": "2019-11-08 15:15:43.979360",
+ "links": [],
+ "modified": "2020-02-03 12:22:29.913302",
  "modified_by": "Administrator",
  "module": "Manufacturing",
  "name": "Material Request Plan Item",
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js
index b49b0ba..64c952b 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.js
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js
@@ -19,7 +19,8 @@
 		frm.set_query('for_warehouse', function(doc) {
 			return {
 				filters: {
-					company: doc.company
+					company: doc.company,
+					is_group: 0
 				}
 			}
 		});
@@ -188,12 +189,53 @@
 	},
 
 	get_items_for_mr: function(frm) {
-		const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom',
+		if (!frm.doc.for_warehouse) {
+			frappe.throw(__("Select warehouse for material requests"));
+		}
+
+		if (frm.doc.ignore_existing_ordered_qty) {
+			frm.events.get_items_for_material_requests(frm);
+		} else {
+			const title = __("Transfer Materials For Warehouse {0}", [frm.doc.for_warehouse]);
+			var dialog = new frappe.ui.Dialog({
+				title: title,
+				fields: [
+					{
+						"fieldtype": "Table MultiSelect", "label": __("Source Warehouses"),
+						"fieldname": "warehouses", "options": "Production Plan Material Request Warehouse",
+						"description": "System will pickup the materials from the selected warehouses",
+						get_query: function () {
+							return {
+								filters: {
+									company: frm.doc.company
+								}
+							};
+						},
+					},
+				]
+			});
+
+			dialog.show();
+
+			dialog.set_primary_action(__("Get Items"), () => {
+				let warehouses = dialog.get_values().warehouses;
+				frm.events.get_items_for_material_requests(frm, warehouses);
+				dialog.hide();
+			});
+		}
+	},
+
+	get_items_for_material_requests: function(frm, warehouses) {
+		const set_fields = ['actual_qty', 'item_code','item_name', 'description', 'uom', 'from_warehouse',
 			'min_order_qty', 'quantity', 'sales_order', 'warehouse', 'projected_qty', 'material_request_type'];
+
 		frappe.call({
 			method: "erpnext.manufacturing.doctype.production_plan.production_plan.get_items_for_material_requests",
 			freeze: true,
-			args: {doc: frm.doc},
+			args: {
+				doc: frm.doc,
+				warehouses: warehouses || []
+			},
 			callback: function(r) {
 				if(r.message) {
 					frm.set_value('mr_items', []);
@@ -212,14 +254,14 @@
 	},
 
 	for_warehouse: function(frm) {
-		if (frm.doc.mr_items) {
+		if (frm.doc.mr_items && frm.doc.for_warehouse) {
 			frm.trigger("get_items_for_mr");
 		}
 	},
 
 	download_materials_required: function(frm) {
 		let get_template_url = 'erpnext.manufacturing.doctype.production_plan.production_plan.download_raw_materials';
-		open_url_post(frappe.request.url, { cmd: get_template_url, production_plan: frm.doc.name });
+		open_url_post(frappe.request.url, { cmd: get_template_url, doc: frm.doc });
 	},
 
 	show_progress: function(frm) {
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.json b/erpnext/manufacturing/doctype/production_plan/production_plan.json
index 77ca6b6..90e8b22 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.json
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.json
@@ -43,6 +43,7 @@
   "total_produced_qty",
   "column_break_32",
   "status",
+  "warehouses",
   "amended_from"
  ],
  "fields": [
@@ -219,12 +220,6 @@
    "fieldtype": "Column Break"
   },
   {
-   "fieldname": "for_warehouse",
-   "fieldtype": "Link",
-   "label": "For Warehouse",
-   "options": "Warehouse"
-  },
-  {
    "depends_on": "eval:!doc.__islocal",
    "fieldname": "download_materials_required",
    "fieldtype": "Button",
@@ -292,12 +287,26 @@
    "options": "Production Plan",
    "print_hide": 1,
    "read_only": 1
+  },
+  {
+   "fieldname": "for_warehouse",
+   "fieldtype": "Link",
+   "label": "Material Request Warehouse",
+   "options": "Warehouse"
+  },
+  {
+   "fieldname": "warehouses",
+   "fieldtype": "Table MultiSelect",
+   "hidden": 1,
+   "label": "Warehouses",
+   "options": "Production Plan Material Request Warehouse",
+   "read_only": 1
   }
  ],
  "icon": "fa fa-calendar",
  "is_submittable": 1,
  "links": [],
- "modified": "2020-01-21 19:13:10.113854",
+ "modified": "2020-02-03 00:25:25.934202",
  "modified_by": "Administrator",
  "module": "Manufacturing",
  "name": "Production Plan",
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index c3f27cd..560286e 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -3,7 +3,7 @@
 # For license information, please see license.txt
 
 from __future__ import unicode_literals
-import frappe, json
+import frappe, json, copy
 from frappe import msgprint, _
 from six import string_types, iteritems
 
@@ -385,6 +385,7 @@
 			# add item
 			material_request.append("items", {
 				"item_code": item.item_code,
+				"from_warehouse": item.from_warehouse,
 				"qty": item.quantity,
 				"schedule_date": schedule_date,
 				"warehouse": item.warehouse,
@@ -415,19 +416,18 @@
 			msgprint(_("No material request created"))
 
 @frappe.whitelist()
-def download_raw_materials(production_plan):
-	doc = frappe.get_doc('Production Plan', production_plan)
-	doc.check_permission()
+def download_raw_materials(doc):
+	if isinstance(doc, string_types):
+		doc = frappe._dict(json.loads(doc))
 
 	item_list = [['Item Code', 'Description', 'Stock UOM', 'Required Qty', 'Warehouse',
 		'projected Qty', 'Actual Qty']]
 
-	doc = doc.as_dict()
-	for d in get_items_for_material_requests(doc, ignore_existing_ordered_qty=True):
+	for d in get_items_for_material_requests(doc):
 		item_list.append([d.get('item_code'), d.get('description'), d.get('stock_uom'), d.get('quantity'),
 			d.get('warehouse'), d.get('projected_qty'), d.get('actual_qty')])
 
-		if not doc.for_warehouse:
+		if not doc.get('for_warehouse'):
 			row = {'item_code': d.get('item_code')}
 			for bin_dict in get_bin_details(row, doc.company, all_warehouse=True):
 				if d.get("warehouse") == bin_dict.get('warehouse'):
@@ -610,26 +610,43 @@
 	""".format(conditions=conditions), { "item_code": row['item_code'] }, as_dict=1)
 
 @frappe.whitelist()
-def get_items_for_material_requests(doc, ignore_existing_ordered_qty=None):
+def get_items_for_material_requests(doc, warehouses=None):
 	if isinstance(doc, string_types):
 		doc = frappe._dict(json.loads(doc))
 
+	warehouse_list = []
+	if warehouses:
+		if isinstance(warehouses, string_types):
+			warehouses = json.loads(warehouses)
+
+		for row in warehouses:
+			child_warehouses = frappe.db.get_descendants('Warehouse', row.get("warehouse"))
+			if child_warehouses:
+				warehouse_list.extend(child_warehouses)
+			else:
+				warehouse_list.append(row.get("warehouse"))
+
+	if warehouse_list:
+		warehouses = list(set(warehouse_list))
+	
+		if doc.get("for_warehouse") and doc.get("for_warehouse") in warehouses:
+			warehouses.remove(doc.get("for_warehouse"))
+
+		warehouse_list = None
+
 	doc['mr_items'] = []
 	po_items = doc.get('po_items') if doc.get('po_items') else doc.get('items')
 	if not po_items:
 		frappe.throw(_("Items are required to pull the raw materials which is associated with it."))
 
 	company = doc.get('company')
-	warehouse = doc.get('for_warehouse')
-
-	if not ignore_existing_ordered_qty:
-		ignore_existing_ordered_qty = doc.get('ignore_existing_ordered_qty')
+	ignore_existing_ordered_qty = doc.get('ignore_existing_ordered_qty')
 
 	so_item_details = frappe._dict()
 	for data in po_items:
 		planned_qty = data.get('required_qty') or data.get('planned_qty')
 		ignore_existing_ordered_qty = data.get('ignore_existing_ordered_qty') or ignore_existing_ordered_qty
-		warehouse = data.get("warehouse") or warehouse
+		warehouse = doc.get('for_warehouse')
 
 		item_details = {}
 		if data.get("bom") or data.get("bom_no"):
@@ -700,12 +717,51 @@
 				if items:
 					mr_items.append(items)
 
+	if not ignore_existing_ordered_qty and warehouses:
+		new_mr_items = []
+		for item in mr_items:
+			get_materials_from_other_locations(item, warehouses, new_mr_items, company)
+
+		mr_items = new_mr_items
+
 	if not mr_items:
-		frappe.msgprint(_("""As raw materials projected quantity is more than required quantity, there is no need to create material request.
-			Still if you want to make material request, kindly enable <b>Ignore Existing Projected Quantity</b> checkbox"""))
+		frappe.msgprint(_("""As raw materials projected quantity is more than required quantity,
+			there is no need to create material request for the warehouse {0}.
+			Still if you want to make material request,
+			kindly enable <b>Ignore Existing Projected Quantity</b> checkbox""").format(doc.get('for_warehouse')))
 
 	return mr_items
 
+def get_materials_from_other_locations(item, warehouses, new_mr_items, company):
+	from erpnext.stock.doctype.pick_list.pick_list import get_available_item_locations
+	locations = get_available_item_locations(item.get("item_code"),
+		warehouses, item.get("quantity"), company, ignore_validation=True)
+
+	if not locations:
+		new_mr_items.append(item)
+		return
+
+	required_qty = item.get("quantity")
+	for d in locations:
+		if required_qty <=0: return
+
+		new_dict = copy.deepcopy(item)
+		quantity = required_qty if d.get("qty") > required_qty else d.get("qty")
+
+		if required_qty > 0:
+			new_dict.update({
+				"quantity": quantity,
+				"material_request_type": "Material Transfer",
+				"from_warehouse": d.get("warehouse")
+			})
+
+			required_qty -= quantity
+			new_mr_items.append(new_dict)
+
+	if required_qty:
+		item["quantity"] = required_qty
+		new_mr_items.append(item)
+
 @frappe.whitelist()
 def get_item_data(item_code):
 	item_details = get_item_details(item_code)
diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/__init__.py b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/__init__.py
diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js
new file mode 100644
index 0000000..53f8758
--- /dev/null
+++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Production Plan Material Request Warehouse', {
+	// refresh: function(frm) {
+
+	// }
+});
diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json
new file mode 100644
index 0000000..53e33c0
--- /dev/null
+++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json
@@ -0,0 +1,42 @@
+{
+ "actions": [],
+ "creation": "2020-02-02 10:37:16.650836",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "warehouse"
+ ],
+ "fields": [
+  {
+   "fieldname": "warehouse",
+   "fieldtype": "Link",
+   "label": "Warehouse",
+   "options": "Warehouse"
+  }
+ ],
+ "links": [],
+ "modified": "2020-02-02 10:37:16.650836",
+ "modified_by": "Administrator",
+ "module": "Manufacturing",
+ "name": "Production Plan Material Request Warehouse",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
+   "write": 1
+  }
+ ],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.py b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.py
new file mode 100644
index 0000000..f605985
--- /dev/null
+++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+# import frappe
+from frappe.model.document import Document
+
+class ProductionPlanMaterialRequestWarehouse(Document):
+	pass
diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py
new file mode 100644
index 0000000..ecab5fb
--- /dev/null
+++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/test_production_plan_material_request_warehouse.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+# import frappe
+import unittest
+
+class TestProductionPlanMaterialRequestWarehouse(unittest.TestCase):
+	pass
diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js
index eb298a6..db8bffd 100644
--- a/erpnext/stock/doctype/material_request/material_request.js
+++ b/erpnext/stock/doctype/material_request/material_request.js
@@ -20,6 +20,17 @@
 		frm.set_indicator_formatter('item_code',
 			function(doc) { return (doc.qty<=doc.ordered_qty) ? "green" : "orange"; });
 
+		frm.set_query("item_code", "items", function() {
+			return {
+				query: "erpnext.controllers.queries.item_query"
+			};
+		});
+
+		frm.set_query("from_warehouse", "items", function(doc) {
+			return {
+				filters: {'company': doc.company}
+			};
+		})
 	},
 
 	onload: function(frm) {
@@ -53,6 +64,16 @@
 		frm.toggle_reqd('customer', frm.doc.material_request_type=="Customer Provided");
 	},
 
+	set_from_warehouse: function(frm) {
+		if (frm.doc.material_request_type == "Material Transfer"
+			&& frm.doc.set_from_warehouse) {
+			frm.doc.items.forEach(d => {
+				frappe.model.set_value(d.doctype, d.name,
+					"from_warehouse", frm.doc.set_from_warehouse);
+			})
+		}
+	},
+
 	make_custom_buttons: function(frm) {
 		if (frm.doc.docstatus==0) {
 			frm.add_custom_button(__("Bill of Materials"),
@@ -159,6 +180,7 @@
 			args: {
 				args: {
 					item_code: item.item_code,
+					from_warehouse: item.from_warehouse,
 					warehouse: item.warehouse,
 					doctype: frm.doc.doctype,
 					buying_price_list: frappe.defaults.get_default('buying_price_list'),
@@ -176,9 +198,11 @@
 			},
 			callback: function(r) {
 				const d = item;
+				const qty_fields = ['actual_qty', 'projected_qty', 'min_order_qty'];
+
 				if(!r.exc) {
 					$.each(r.message, function(k, v) {
-						if(!d[k]) d[k] = v;
+						if(!d[k] || in_list(qty_fields, k)) d[k] = v;
 					});
 				}
 			}
@@ -324,6 +348,16 @@
 		frm.events.get_item_data(frm, item);
 	},
 
+	from_warehouse: function(frm, doctype, name) {
+		const item = locals[doctype][name];
+		frm.events.get_item_data(frm, item);
+	},
+
+	warehouse: function(frm, doctype, name) {
+		const item = locals[doctype][name];
+		frm.events.get_item_data(frm, item);
+	},
+
 	rate: function(frm, doctype, name) {
 		const item = locals[doctype][name];
 		frm.events.get_item_data(frm, item);
diff --git a/erpnext/stock/doctype/material_request/material_request.json b/erpnext/stock/doctype/material_request/material_request.json
index 536f5fa..d1f29e3 100644
--- a/erpnext/stock/doctype/material_request/material_request.json
+++ b/erpnext/stock/doctype/material_request/material_request.json
@@ -18,6 +18,8 @@
   "amended_from",
   "warehouse_section",
   "set_warehouse",
+  "column_break5",
+  "set_from_warehouse",
   "items_section",
   "scan_barcode",
   "items",
@@ -287,13 +289,27 @@
    "fieldtype": "Link",
    "label": "Set Warehouse",
    "options": "Warehouse"
+  },
+  {
+   "fieldname": "column_break5",
+   "fieldtype": "Column Break",
+   "oldfieldtype": "Column Break",
+   "print_width": "50%",
+   "width": "50%"
+  },
+  {
+   "depends_on": "eval:doc.material_request_type == 'Material Transfer'",
+   "fieldname": "set_from_warehouse",
+   "fieldtype": "Link",
+   "label": "Set From Warehouse",
+   "options": "Warehouse"
   }
  ],
  "icon": "fa fa-ticket",
  "idx": 70,
  "is_submittable": 1,
  "links": [],
- "modified": "2020-03-02 20:21:09.990867",
+ "modified": "2020-05-01 20:21:09.990867",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Material Request",
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 739d749..97606f4 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -456,6 +456,9 @@
 		if source_parent.material_request_type == "Customer Provided":
 			target.allow_zero_valuation_rate = 1
 
+		if source_parent.material_request_type == "Material Transfer":
+			target.s_warehouse = obj.from_warehouse
+
 	def set_missing_values(source, target):
 		target.purpose = source.material_request_type
 		if source.job_card:
diff --git a/erpnext/stock/doctype/material_request_item/material_request_item.json b/erpnext/stock/doctype/material_request_item/material_request_item.json
index 2bdc268..df140ff 100644
--- a/erpnext/stock/doctype/material_request_item/material_request_item.json
+++ b/erpnext/stock/doctype/material_request_item/material_request_item.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "autoname": "hash",
  "creation": "2013-02-22 01:28:02",
  "doctype": "DocType",
@@ -21,6 +22,7 @@
   "quantity_and_warehouse",
   "qty",
   "stock_uom",
+  "from_warehouse",
   "warehouse",
   "col_break2",
   "uom",
@@ -419,12 +421,19 @@
   {
    "fieldname": "col_break4",
    "fieldtype": "Column Break"
+  },
+  {
+   "depends_on": "eval:parent.material_request_type == \"Material Transfer\"",
+   "fieldname": "from_warehouse",
+   "fieldtype": "Link",
+   "label": "Source Warehouse (Material Transfer)",
+   "options": "Warehouse"
   }
  ],
  "idx": 1,
  "istable": 1,
  "links": [],
- "modified": "2020-04-16 09:00:00.992835",
+ "modified": "2020-05-01 09:00:00.992835",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Material Request Item",
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index 616de5e..231af1a 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -139,7 +139,7 @@
 	item_location_map[item_doc.item_code] = available_locations
 	return locations
 
-def get_available_item_locations(item_code, from_warehouses, required_qty, company):
+def get_available_item_locations(item_code, from_warehouses, required_qty, company, ignore_validation=False):
 	locations = []
 	if frappe.get_cached_value('Item', item_code, 'has_serial_no'):
 		locations = get_available_item_locations_for_serialized_item(item_code, from_warehouses, required_qty, company)
@@ -152,7 +152,7 @@
 
 	remaining_qty = required_qty - total_qty_available
 
-	if remaining_qty > 0:
+	if remaining_qty > 0 and not ignore_validation:
 		frappe.msgprint(_('{0} units of {1} is not available.')
 			.format(remaining_qty, frappe.get_desk_link('Item', item_code)))
 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index f9aae7b..ddf4ec0 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -1053,9 +1053,9 @@
 				fields=["required_qty", "consumed_qty"]
 				)
 
-			req_qty = flt(req_items[0].required_qty)
+			req_qty = flt(req_items[0].required_qty) if req_items else flt(4)
 			req_qty_each = flt(req_qty / manufacturing_qty)
-			consumed_qty = flt(req_items[0].consumed_qty)
+			consumed_qty = flt(req_items[0].consumed_qty) if req_items else 0
 
 			if trans_qty and manufacturing_qty > (produced_qty + flt(self.fg_completed_qty)):
 				if qty >= req_qty:
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index c5ba686..d50712a 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -77,7 +77,11 @@
 	if args.customer and cint(args.is_pos):
 		out.update(get_pos_profile_item_details(args.company, args))
 
-	if out.get("warehouse"):
+	if (args.get("doctype") == "Material Request" and
+		args.get("material_request_type") == "Material Transfer"):
+		out.update(get_bin_details(args.item_code, args.get("from_warehouse")))
+
+	elif out.get("warehouse"):
 		out.update(get_bin_details(args.item_code, out.warehouse))
 
 	# update args with out, if key or value not exists