Merge pull request #20447 from Alchez/dev-driver-address-fetch

fix: only fetch driver address if not set (develop)
diff --git a/.github/ISSUE_TEMPLATE/question-about-using-erpnext.md b/.github/ISSUE_TEMPLATE/question-about-using-erpnext.md
index 455c20e..2016bcc 100644
--- a/.github/ISSUE_TEMPLATE/question-about-using-erpnext.md
+++ b/.github/ISSUE_TEMPLATE/question-about-using-erpnext.md
@@ -8,7 +8,7 @@
 
 for questions about using `ERPNext`: https://discuss.erpnext.com
 
-for questions about using the `Frappe Framework`: https://discuss.frappe.io
+for questions about using the `Frappe Framework`: ~~https://discuss.frappe.io~~ => [stackoverflow](https://stackoverflow.com/questions/tagged/frappe) tagged under `frappe`
 
 for questions about using `bench`, probably the best place to start is the [bench repo](https://github.com/frappe/bench)
 
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 703df79..6e3e43e 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1238,24 +1238,27 @@
 				self.status = 'Draft'
 			return
 
+		precision = self.precision("outstanding_amount")
+		outstanding_amount = flt(self.outstanding_amount, precision)
+
 		if not status:
 			if self.docstatus == 2:
 				status = "Cancelled"
 			elif self.docstatus == 1:
-				if flt(self.outstanding_amount) > 0 and getdate(self.due_date) < getdate(nowdate()) and self.is_discounted and self.get_discounting_status()=='Disbursed':
+				if outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()) and self.is_discounted and self.get_discounting_status()=='Disbursed':
 					self.status = "Overdue and Discounted"
-				elif flt(self.outstanding_amount) > 0 and getdate(self.due_date) < getdate(nowdate()):
+				elif outstanding_amount > 0 and getdate(self.due_date) < getdate(nowdate()):
 					self.status = "Overdue"
-				elif flt(self.outstanding_amount) > 0 and getdate(self.due_date) >= getdate(nowdate()) and self.is_discounted and self.get_discounting_status()=='Disbursed':
+				elif outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()) and self.is_discounted and self.get_discounting_status()=='Disbursed':
 					self.status = "Unpaid and Discounted"
-				elif flt(self.outstanding_amount) > 0 and getdate(self.due_date) >= getdate(nowdate()):
+				elif outstanding_amount > 0 and getdate(self.due_date) >= getdate(nowdate()):
 					self.status = "Unpaid"
 				#Check if outstanding amount is 0 due to credit note issued against invoice
-				elif flt(self.outstanding_amount) <= 0 and self.is_return == 0 and frappe.db.get_value('Sales Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1}):
+				elif outstanding_amount <= 0 and self.is_return == 0 and frappe.db.get_value('Sales Invoice', {'is_return': 1, 'return_against': self.name, 'docstatus': 1}):
 					self.status = "Credit Note Issued"
 				elif self.is_return == 1:
 					self.status = "Return"
-				elif flt(self.outstanding_amount)<=0:
+				elif outstanding_amount <=0:
 					self.status = "Paid"
 				else:
 					self.status = "Submitted"
diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.js b/erpnext/accounts/report/balance_sheet/balance_sheet.js
index 8c11514..c4c24c0 100644
--- a/erpnext/accounts/report/balance_sheet/balance_sheet.js
+++ b/erpnext/accounts/report/balance_sheet/balance_sheet.js
@@ -14,6 +14,7 @@
 	frappe.query_reports["Balance Sheet"]["filters"].push({
 		"fieldname": "include_default_book_entries",
 		"label": __("Include Default Book Entries"),
-		"fieldtype": "Check"
+		"fieldtype": "Check",
+		"default": 1
 	});
 });
diff --git a/erpnext/accounts/report/cash_flow/cash_flow.js b/erpnext/accounts/report/cash_flow/cash_flow.js
index 03940f4..89244c3 100644
--- a/erpnext/accounts/report/cash_flow/cash_flow.js
+++ b/erpnext/accounts/report/cash_flow/cash_flow.js
@@ -20,7 +20,8 @@
 		{
 			"fieldname": "include_default_book_entries",
 			"label": __("Include Default Book Entries"),
-			"fieldtype": "Check"
+			"fieldtype": "Check",
+			"default": 1
 		}
 	);
 });
\ No newline at end of file
diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py
index 98c25b7..0b12477 100644
--- a/erpnext/accounts/report/cash_flow/cash_flow.py
+++ b/erpnext/accounts/report/cash_flow/cash_flow.py
@@ -130,11 +130,11 @@
 	filters = frappe._dict(filters)
 
 	if filters.finance_book:
-		cond = " and finance_book = %s" %(frappe.db.escape(filters.finance_book))
+		cond = " AND (finance_book in (%s, '') OR finance_book IS NULL)" %(frappe.db.escape(filters.finance_book))
 		if filters.include_default_book_entries:
 			company_fb = frappe.db.get_value("Company", company, 'default_finance_book')
 
-			cond = """ and finance_book in (%s, %s)
+			cond = """ AND (finance_book in (%s, %s, '') OR finance_book IS NULL)
 				""" %(frappe.db.escape(filters.finance_book), frappe.db.escape(company_fb))
 
 	gl_sum = frappe.db.sql_list("""
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js
index e69a993..48a030a 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js
@@ -58,7 +58,8 @@
 		{
 			"fieldname": "include_default_book_entries",
 			"label": __("Include Default Book Entries"),
-			"fieldtype": "Check"
+			"fieldtype": "Check",
+			"default": 1
 		}
 	]
 }
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
index 418a23c..e9eb819 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
@@ -389,9 +389,9 @@
 
 	if filters.get("finance_book"):
 		if filters.get("include_default_book_entries"):
-			additional_conditions.append("finance_book in (%(finance_book)s, %(company_fb)s)")
+			additional_conditions.append("(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)")
 		else:
-			additional_conditions.append("finance_book in (%(finance_book)s)")
+			additional_conditions.append("(finance_book in (%(finance_book)s, '') OR finance_book IS NULL)")
 
 	return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
 
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 40d5682..32d9075 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -408,9 +408,9 @@
 
 		if filters.get("finance_book"):
 			if filters.get("include_default_book_entries"):
-				additional_conditions.append("finance_book in (%(finance_book)s, %(company_fb)s)")
+				additional_conditions.append("(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)")
 			else:
-				additional_conditions.append("finance_book in (%(finance_book)s)")
+				additional_conditions.append("(finance_book in (%(finance_book)s, '') OR finance_book IS NULL)")
 
 	if accounting_dimensions:
 		for dimension in accounting_dimensions:
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js
index 4a28706..ac49d37 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -154,7 +154,8 @@
 		{
 			"fieldname": "include_default_book_entries",
 			"label": __("Include Default Book Entries"),
-			"fieldtype": "Check"
+			"fieldtype": "Check",
+			"default": 1
 		}
 	]
 }
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index b32a54f..0939354 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -184,7 +184,7 @@
 
 	if filters.get("finance_book"):
 		if filters.get("include_default_book_entries"):
-			conditions.append("finance_book in (%(finance_book)s, %(company_fb)s)")
+			conditions.append("(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)")
 		else:
 			conditions.append("finance_book in (%(finance_book)s)")
 
diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js
index a8362bf..baa0bda 100644
--- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js
+++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.js
@@ -23,7 +23,8 @@
 		{
 			"fieldname": "include_default_book_entries",
 			"label": __("Include Default Book Entries"),
-			"fieldtype": "Check"
+			"fieldtype": "Check",
+			"default": 1
 		}
 	);
 });
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js
index f15b5b1..622bab6 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.js
+++ b/erpnext/accounts/report/trial_balance/trial_balance.js
@@ -85,7 +85,8 @@
 			{
 				"fieldname": "include_default_book_entries",
 				"label": __("Include Default Book Entries"),
-				"fieldtype": "Check"
+				"fieldtype": "Check",
+				"default": 1
 			}
 		],
 		"formatter": erpnext.financial_statements.formatter,
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py
index faeee0f..69285cc 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.py
+++ b/erpnext/accounts/report/trial_balance/trial_balance.py
@@ -103,9 +103,9 @@
 			where lft >= %s and rgt <= %s)""" % (lft, rgt)
 
 	if filters.finance_book:
-		fb_conditions = " and finance_book = %(finance_book)s"
+		fb_conditions = " AND finance_book = %(finance_book)s"
 		if filters.include_default_book_entries:
-			fb_conditions = " and (finance_book in (%(finance_book)s, %(company_fb)s))"
+			fb_conditions = " AND (finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)"
 
 		additional_conditions += fb_conditions
 
diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js
index 8c737d0..91ce9ce 100644
--- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js
+++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.js
@@ -21,16 +21,31 @@
 			reqd: 1
 		},
 		{
+			fieldname:"purchase_date",
+			label: __("Purchase Date"),
+			fieldtype: "Date"
+		},
+		{
+			fieldname:"available_for_use_date",
+			label: __("Available For Use Date"),
+			fieldtype: "Date"
+		},
+		{
 			fieldname:"finance_book",
 			label: __("Finance Book"),
 			fieldtype: "Link",
 			options: "Finance Book"
 		},
 		{
-			fieldname:"date",
-			label: __("Date"),
-			fieldtype: "Date",
-			default: frappe.datetime.get_today()
+			fieldname:"asset_category",
+			label: __("Asset Category"),
+			fieldtype: "Link",
+			options: "Asset Category"
+		},
+		{
+			fieldname:"is_existing_asset",
+			label: __("Is Existing Asset"),
+			fieldtype: "Check"
 		},
 	]
 };
diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
index 1498444..fa2fe7b 100644
--- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
+++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
@@ -41,6 +41,42 @@
 			"width": 90
 		},
 		{
+			"label": _("Purchase Date"),
+			"fieldtype": "Date",
+			"fieldname": "purchase_date",
+			"width": 90
+		},
+		{
+			"label": _("Available For Use Date"),
+			"fieldtype": "Date",
+			"fieldname": "available_for_use_date",
+			"width": 90
+		},
+		{
+			"label": _("Gross Purchase Amount"),
+			"fieldname": "gross_purchase_amount",
+			"options": "Currency",
+			"width": 90
+		},
+		{
+			"label": _("Asset Value"),
+			"fieldname": "asset_value",
+			"options": "Currency",
+			"width": 90
+		},
+		{
+			"label": _("Opening Accumulated Depreciation"),
+			"fieldname": "opening_accumulated_depreciation",
+			"options": "Currency",
+			"width": 90
+		},
+		{
+			"label": _("Depreciated Amount"),
+			"fieldname": "depreciated_amount",
+			"options": "Currency",
+			"width": 90
+		},
+		{
 			"label": _("Cost Center"),
 			"fieldtype": "Link",
 			"fieldname": "cost_center",
@@ -55,50 +91,35 @@
 			"width": 100
 		},
 		{
-			"label": _("Location"),
-			"fieldtype": "Link",
-			"fieldname": "location",
-			"options": "Location",
-			"width": 100
-		},
-		{
-			"label": _("Purchase Date"),
-			"fieldtype": "Date",
-			"fieldname": "purchase_date",
-			"width": 90
-		},
-		{
-			"label": _("Gross Purchase Amount"),
-			"fieldname": "gross_purchase_amount",
-			"options": "Currency",
-			"width": 90
-		},
-		{
 			"label": _("Vendor Name"),
 			"fieldtype": "Data",
 			"fieldname": "vendor_name",
 			"width": 100
 		},
 		{
-			"label": _("Available For Use Date"),
-			"fieldtype": "Date",
-			"fieldname": "available_for_use_date",
-			"width": 90
-		},
-		{
-			"label": _("Asset Value"),
-			"fieldname": "asset_value",
-			"options": "Currency",
-			"width": 90
+			"label": _("Location"),
+			"fieldtype": "Link",
+			"fieldname": "location",
+			"options": "Location",
+			"width": 100
 		},
 	]
 
 def get_conditions(filters):
-	conditions = {'docstatus': 1}
+	conditions = { 'docstatus': 1 }
 	status = filters.status
+	date = filters.date
 
-	if filters.company:
+	if filters.get('company'):
 		conditions["company"] = filters.company
+	if filters.get('purchase_date'):
+		conditions["purchase_date"] = ('<=', filters.get('purchase_date'))
+	if filters.get('available_for_use_date'):
+		conditions["available_for_use_date"] = ('<=', filters.get('available_for_use_date'))
+	if filters.get('is_existing_asset'):
+		conditions["is_existing_asset"] = filters.get('is_existing_asset')
+	if filters.get('asset_category'):
+		conditions["asset_category"] = filters.get('asset_category')
 
 	# In Store assets are those that are not sold or scrapped
 	operand = 'not in'
@@ -114,7 +135,7 @@
 	data = []
 
 	conditions = get_conditions(filters)
-	depreciation_amount_map = get_finance_book_value_map(filters.date, filters.finance_book)
+	depreciation_amount_map = get_finance_book_value_map(filters)
 	pr_supplier_map = get_purchase_receipt_supplier_map()
 	pi_supplier_map = get_purchase_invoice_supplier_map()
 
@@ -136,6 +157,8 @@
 				"cost_center": asset.cost_center,
 				"vendor_name": pr_supplier_map.get(asset.purchase_receipt) or pi_supplier_map.get(asset.purchase_invoice),
 				"gross_purchase_amount": asset.gross_purchase_amount,
+				"opening_accumulated_depreciation": asset.opening_accumulated_depreciation,
+				"depreciated_amount": depreciation_amount_map.get(asset.name) or 0.0,
 				"available_for_use_date": asset.available_for_use_date,
 				"location": asset.location,
 				"asset_category": asset.asset_category,
@@ -146,9 +169,9 @@
 
 	return data
 
-def get_finance_book_value_map(date, finance_book=''):
-	if not date:
-		date = today()
+def get_finance_book_value_map(filters):
+	date = filters.get('purchase_date') or filters.get('available_for_use_date') or today()
+
 	return frappe._dict(frappe.db.sql(''' Select
 		parent, SUM(depreciation_amount)
 		FROM `tabDepreciation Schedule`
@@ -157,7 +180,7 @@
 			AND schedule_date<=%s
 			AND journal_entry IS NOT NULL
 			AND ifnull(finance_book, '')=%s
-		GROUP BY parent''', (date, cstr(finance_book))))
+		GROUP BY parent''', (date, cstr(filters.finance_book or ''))))
 
 def get_purchase_receipt_supplier_map():
 	return frappe._dict(frappe.db.sql(''' Select
diff --git a/erpnext/hr/doctype/employee_checkin/employee_checkin.js b/erpnext/hr/doctype/employee_checkin/employee_checkin.js
index f11cc9b..c2403ca 100644
--- a/erpnext/hr/doctype/employee_checkin/employee_checkin.js
+++ b/erpnext/hr/doctype/employee_checkin/employee_checkin.js
@@ -2,7 +2,9 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Employee Checkin', {
-	// refresh: function(frm) {
-
-	// }
+	setup: (frm) => {
+		if(!frm.doc.time) {
+			frm.set_value("time", frappe.datetime.now_datetime());
+		}
+	}
 });
diff --git a/erpnext/hr/doctype/employee_checkin/employee_checkin.json b/erpnext/hr/doctype/employee_checkin/employee_checkin.json
index 08fa4af..75f6997 100644
--- a/erpnext/hr/doctype/employee_checkin/employee_checkin.json
+++ b/erpnext/hr/doctype/employee_checkin/employee_checkin.json
@@ -1,4 +1,5 @@
 {
+ "actions": [],
  "allow_import": 1,
  "autoname": "EMP-CKIN-.MM.-.YYYY.-.######",
  "creation": "2019-06-10 11:56:34.536413",
@@ -23,7 +24,6 @@
   {
    "fieldname": "employee",
    "fieldtype": "Link",
-   "in_list_view": 1,
    "label": "Employee",
    "options": "Employee",
    "reqd": 1
@@ -32,14 +32,17 @@
    "fetch_from": "employee.employee_name",
    "fieldname": "employee_name",
    "fieldtype": "Data",
+   "in_list_view": 1,
    "label": "Employee Name",
    "read_only": 1
   },
   {
    "fieldname": "log_type",
    "fieldtype": "Select",
+   "in_list_view": 1,
    "label": "Log Type",
-   "options": "\nIN\nOUT"
+   "options": "\nIN\nOUT",
+   "reqd": 1
   },
   {
    "fieldname": "shift",
@@ -58,6 +61,7 @@
    "fieldtype": "Datetime",
    "in_list_view": 1,
    "label": "Time",
+   "permlevel": 1,
    "reqd": 1
   },
   {
@@ -103,7 +107,8 @@
    "label": "Shift Actual End"
   }
  ],
- "modified": "2019-07-23 23:47:33.975263",
+ "links": [],
+ "modified": "2020-01-23 04:57:42.551355",
  "modified_by": "Administrator",
  "module": "HR",
  "name": "Employee Checkin",
@@ -147,9 +152,58 @@
    "role": "HR User",
    "share": 1,
    "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "read": 1,
+   "role": "Employee",
+   "write": 1
+  },
+  {
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "permlevel": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "permlevel": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "permlevel": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR User",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "permlevel": 1,
+   "read": 1,
+   "role": "Employee"
   }
  ],
  "sort_field": "modified",
  "sort_order": "ASC",
+ "title_field": "employee_name",
  "track_changes": 1
 }
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 04f6fc6..7f8bd67 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -47,7 +47,18 @@
 		else:
 			idx = 1
 
-		self.name = 'BOM-' + self.item + ('-%.3i' % idx)
+		name = 'BOM-' + self.item + ('-%.3i' % idx)
+		if frappe.db.exists("BOM", name):
+			conflicting_bom = frappe.get_doc("BOM", name)
+
+			if conflicting_bom.item != self.item:
+
+				frappe.throw(_("""A BOM with name {0} already exists for item {1}.
+					<br> Did you rename the item? Please contact Administrator / Tech support
+				""").format(frappe.bold(name), frappe.bold(conflicting_bom.item)))
+
+		self.name = name
+
 
 	def validate(self):
 		self.route = frappe.scrub(self.name).replace('_', '-')
diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json
index c2c8c19..dc8febd 100644
--- a/erpnext/selling/doctype/customer/customer.json
+++ b/erpnext/selling/doctype/customer/customer.json
@@ -322,8 +322,9 @@
   },
   {
    "fieldname": "primary_address",
-   "fieldtype": "Read Only",
-   "label": "Primary Address"
+   "fieldtype": "Text",
+   "label": "Primary Address",
+   "read_only": 1
   },
   {
    "collapsible": 1,
@@ -469,7 +470,7 @@
  "icon": "fa fa-user",
  "idx": 363,
  "image_field": "image",
- "modified": "2019-09-06 12:40:31.801424",
+ "modified": "2020-01-24 15:07:48.815546",
  "modified_by": "Administrator",
  "module": "Selling",
  "name": "Customer",
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 22375ae..9f25882 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -119,7 +119,7 @@
 				or I.name like %(search)s)"""
 		search = "%" + cstr(search) + "%"
 
-	query += """order by I.weightage desc, in_stock desc, I.modified desc limit %s, %s""" % (start, limit)
+	query += """order by I.weightage desc, in_stock desc, I.modified desc limit %s, %s""" % (cint(start), cint(limit))
 
 	data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)
 	data = adjust_qty_for_expired_items(data)
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 2ee6872..67e8bd2 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -92,6 +92,17 @@
 			}, __('Create'));
 			frm.page.set_inner_btn_group_as_primary(__('Create'));
 		}
+	},
+
+	to_warehouse: function(frm) {
+		if(frm.doc.to_warehouse) {
+			["items", "packed_items"].forEach(doctype => {
+				frm.doc[doctype].forEach(d => {
+					frappe.model.set_value(d.doctype, d.name,
+						"target_warehouse", frm.doc.to_warehouse);
+				});
+			});
+		}
 	}
 });