Merge pull request #33254 from ruthra-kumar/index_error_on_customer_master

fix: index error on customer master
diff --git a/.github/helper/install.sh b/.github/helper/install.sh
index 2bb950f..2b3d8cb 100644
--- a/.github/helper/install.sh
+++ b/.github/helper/install.sh
@@ -24,15 +24,14 @@
 
 
 if [ "$DB" == "mariadb" ];then
-    mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"
-    mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"
+    mysql --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL character_set_server = 'utf8mb4'"
+    mysql --host 127.0.0.1 --port 3306 -u root -proot -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"
 
-    mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
-    mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE DATABASE test_frappe"
-    mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"
+    mysql --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
+    mysql --host 127.0.0.1 --port 3306 -u root -proot -e "CREATE DATABASE test_frappe"
+    mysql --host 127.0.0.1 --port 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"
 
-    mysql --host 127.0.0.1 --port 3306 -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"
-    mysql --host 127.0.0.1 --port 3306 -u root -e "FLUSH PRIVILEGES"
+    mysql --host 127.0.0.1 --port 3306 -u root -proot -e "FLUSH PRIVILEGES"
 fi
 
 if [ "$DB" == "postgres" ];then
diff --git a/.github/helper/site_config_mariadb.json b/.github/helper/site_config_mariadb.json
index 948ad08..49e7fcf 100644
--- a/.github/helper/site_config_mariadb.json
+++ b/.github/helper/site_config_mariadb.json
@@ -9,7 +9,7 @@
  "mail_password": "test",
  "admin_password": "admin",
  "root_login": "root",
- "root_password": "travis",
+ "root_password": "root",
  "host_name": "http://test_site:8000",
  "install_apps": ["erpnext"],
  "throttle_user_limit": 100
diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml
index 9e06254..d5f0052 100644
--- a/.github/workflows/patch.yml
+++ b/.github/workflows/patch.yml
@@ -25,7 +25,7 @@
       mysql:
         image: mariadb:10.3
         env:
-          MYSQL_ALLOW_EMPTY_PASSWORD: YES
+          MARIADB_ROOT_PASSWORD: 'root'
         ports:
           - 3306:3306
         options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
diff --git a/.github/workflows/server-tests-mariadb.yml b/.github/workflows/server-tests-mariadb.yml
index b40faa7..bbb8a7e 100644
--- a/.github/workflows/server-tests-mariadb.yml
+++ b/.github/workflows/server-tests-mariadb.yml
@@ -45,9 +45,9 @@
 
     services:
       mysql:
-        image: mariadb:10.3
+        image: mariadb:10.6
         env:
-          MYSQL_ALLOW_EMPTY_PASSWORD: YES
+          MARIADB_ROOT_PASSWORD: 'root'
         ports:
           - 3306:3306
         options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
index 4592421..3207e41 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
@@ -9,10 +9,6 @@
 from frappe.utils import add_days, add_years, cstr, getdate
 
 
-class FiscalYearIncorrectDate(frappe.ValidationError):
-	pass
-
-
 class FiscalYear(Document):
 	@frappe.whitelist()
 	def set_as_default(self):
@@ -53,23 +49,18 @@
 					)
 
 	def validate_dates(self):
+		self.validate_from_to_dates("year_start_date", "year_end_date")
 		if self.is_short_year:
 			# Fiscal Year can be shorter than one year, in some jurisdictions
 			# under certain circumstances. For example, in the USA and Germany.
 			return
 
-		if getdate(self.year_start_date) > getdate(self.year_end_date):
-			frappe.throw(
-				_("Fiscal Year Start Date should be one year earlier than Fiscal Year End Date"),
-				FiscalYearIncorrectDate,
-			)
-
 		date = getdate(self.year_start_date) + relativedelta(years=1) - relativedelta(days=1)
 
 		if getdate(self.year_end_date) != date:
 			frappe.throw(
 				_("Fiscal Year End Date should be one year after Fiscal Year Start Date"),
-				FiscalYearIncorrectDate,
+				frappe.exceptions.InvalidDates,
 			)
 
 	def on_update(self):
@@ -169,5 +160,6 @@
 
 
 def get_from_and_to_date(fiscal_year):
-	fields = ["year_start_date as from_date", "year_end_date as to_date"]
-	return frappe.get_cached_value("Fiscal Year", fiscal_year, fields, as_dict=1)
+	fields = ["year_start_date", "year_end_date"]
+	cached_results = frappe.get_cached_value("Fiscal Year", fiscal_year, fields, as_dict=1)
+	return dict(from_date=cached_results.year_start_date, to_date=cached_results.year_end_date)
diff --git a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
index 6e946f7..181406b 100644
--- a/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/test_fiscal_year.py
@@ -7,8 +7,6 @@
 import frappe
 from frappe.utils import now_datetime
 
-from erpnext.accounts.doctype.fiscal_year.fiscal_year import FiscalYearIncorrectDate
-
 test_ignore = ["Company"]
 
 
@@ -26,7 +24,7 @@
 			}
 		)
 
-		self.assertRaises(FiscalYearIncorrectDate, fy.insert)
+		self.assertRaises(frappe.exceptions.InvalidDates, fy.insert)
 
 
 def test_record_generator():
@@ -35,8 +33,8 @@
 			"doctype": "Fiscal Year",
 			"year": "_Test Short Fiscal Year 2011",
 			"is_short_year": 1,
-			"year_end_date": "2011-04-01",
-			"year_start_date": "2011-12-31",
+			"year_start_date": "2011-04-01",
+			"year_end_date": "2011-12-31",
 		}
 	]
 
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index ed46d85..b666e0d 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -10,7 +10,7 @@
 import frappe
 from frappe import _, throw
 from frappe.model.document import Document
-from frappe.utils import cint, flt, getdate
+from frappe.utils import cint, flt
 
 apply_on_dict = {"Item Code": "items", "Item Group": "item_groups", "Brand": "brands"}
 
@@ -184,8 +184,7 @@
 		if self.is_cumulative and not (self.valid_from and self.valid_upto):
 			frappe.throw(_("Valid from and valid upto fields are mandatory for the cumulative"))
 
-		if self.valid_from and self.valid_upto and getdate(self.valid_from) > getdate(self.valid_upto):
-			frappe.throw(_("Valid from date must be less than valid upto date"))
+		self.validate_from_to_dates("valid_from", "valid_upto")
 
 	def validate_condition(self):
 		if (
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 0a92820..0e9f976 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -231,7 +231,9 @@
 		)
 
 		if (
-			cint(frappe.db.get_single_value("Buying Settings", "maintain_same_rate")) and not self.is_return
+			cint(frappe.db.get_single_value("Buying Settings", "maintain_same_rate"))
+			and not self.is_return
+			and not self.is_internal_supplier
 		):
 			self.validate_rate_with_reference_doc(
 				[
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 18d2b5c..b38bce7 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -921,6 +921,7 @@
    "fieldtype": "Table",
    "hide_days": 1,
    "hide_seconds": 1,
+   "label": "Sales Taxes and Charges",
    "oldfieldname": "other_charges",
    "oldfieldtype": "Table",
    "options": "Sales Taxes and Charges"
@@ -2133,7 +2134,7 @@
    "link_fieldname": "consolidated_invoice"
   }
  ],
- "modified": "2022-11-17 17:17:10.883487",
+ "modified": "2022-12-05 16:18:14.532114",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Sales Invoice",
diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.py b/erpnext/accounts/doctype/tax_rule/tax_rule.py
index 4d20129..87c5e6d 100644
--- a/erpnext/accounts/doctype/tax_rule/tax_rule.py
+++ b/erpnext/accounts/doctype/tax_rule/tax_rule.py
@@ -32,7 +32,7 @@
 
 	def validate(self):
 		self.validate_tax_template()
-		self.validate_date()
+		self.validate_from_to_dates("from_date", "to_date")
 		self.validate_filters()
 		self.validate_use_for_shopping_cart()
 
@@ -51,10 +51,6 @@
 		if not (self.sales_tax_template or self.purchase_tax_template):
 			frappe.throw(_("Tax Template is mandatory."))
 
-	def validate_date(self):
-		if self.from_date and self.to_date and self.from_date > self.to_date:
-			frappe.throw(_("From Date cannot be greater than To Date"))
-
 	def validate_filters(self):
 		filters = {
 			"tax_type": self.tax_type,
diff --git a/erpnext/accounts/report/utils.py b/erpnext/accounts/report/utils.py
index eed5836..d3cd290 100644
--- a/erpnext/accounts/report/utils.py
+++ b/erpnext/accounts/report/utils.py
@@ -28,7 +28,7 @@
 		filters["presentation_currency"] if filters.get("presentation_currency") else company_currency
 	)
 
-	report_date = filters.get("to_date")
+	report_date = filters.get("to_date") or filters.get("period_end_date")
 
 	if not report_date:
 		fiscal_year_to_date = get_from_and_to_date(filters.get("to_fiscal_year"))["to_date"]
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index 136a033..2bec273 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -12,6 +12,7 @@
 	get_first_day,
 	get_last_day,
 	getdate,
+	is_last_day_of_the_month,
 	nowdate,
 )
 
@@ -264,7 +265,7 @@
 			asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation,
 			asset.precision("gross_purchase_amount"),
 		)
-		this_month_depr_amount = 9000.0 if get_last_day(date) == date else 0
+		this_month_depr_amount = 9000.0 if is_last_day_of_the_month(date) else 0
 
 		self.assertEquals(accumulated_depr_amount, 18000.0 + this_month_depr_amount)
 
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 31a4837..98c7dc9 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -22,6 +22,13 @@
 				}
 			};
 		}
+
+		frm.set_query('warehouse', 'items', () => ({
+			filters: {
+				company: frm.doc.company,
+				is_group: 0
+			}
+		}));
 	},
 
 	onload: function(frm) {
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index b7a80c1..5a051e3 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -2311,7 +2311,7 @@
 	elif term.due_date_based_on == "Day(s) after the end of the invoice month":
 		due_date = add_days(get_last_day(date), term.credit_days)
 	elif term.due_date_based_on == "Month(s) after the end of the invoice month":
-		due_date = add_months(get_last_day(date), term.credit_months)
+		due_date = get_last_day(add_months(date, term.credit_months))
 	return due_date
 
 
@@ -2323,7 +2323,7 @@
 	elif term.discount_validity_based_on == "Day(s) after the end of the invoice month":
 		discount_validity = add_days(get_last_day(date), term.discount_validity)
 	elif term.discount_validity_based_on == "Month(s) after the end of the invoice month":
-		discount_validity = add_months(get_last_day(date), term.discount_validity)
+		discount_validity = get_last_day(add_months(date, term.discount_validity))
 	return discount_validity
 
 
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 0514604..2efa545 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -322,17 +322,18 @@
 					)
 
 				if self.is_internal_transfer():
-					if rate != d.rate:
-						d.rate = rate
-						frappe.msgprint(
-							_(
-								"Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer"
-							).format(d.idx),
-							alert=1,
-						)
-					d.discount_percentage = 0.0
-					d.discount_amount = 0.0
-					d.margin_rate_or_amount = 0.0
+					if self.doctype == "Purchase Receipt" or self.get("update_stock"):
+						if rate != d.rate:
+							d.rate = rate
+							frappe.msgprint(
+								_(
+									"Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer"
+								).format(d.idx),
+								alert=1,
+							)
+						d.discount_percentage = 0.0
+						d.discount_amount = 0.0
+						d.margin_rate_or_amount = 0.0
 
 	def validate_for_subcontracting(self):
 		if self.is_subcontracted and self.get("is_old_subcontracting_flow"):
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 965335b..0ebc8d4 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -442,30 +442,31 @@
 
 				# For internal transfers use incoming rate as the valuation rate
 				if self.is_internal_transfer():
-					if d.doctype == "Packed Item":
-						incoming_rate = flt(
-							flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
-							d.precision("incoming_rate"),
-						)
-						if d.incoming_rate != incoming_rate:
-							d.incoming_rate = incoming_rate
-					else:
-						rate = flt(
-							flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
-							d.precision("rate"),
-						)
-						if d.rate != rate:
-							d.rate = rate
-							frappe.msgprint(
-								_(
-									"Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer"
-								).format(d.idx),
-								alert=1,
+					if self.doctype == "Delivery Note" or self.get("update_stock"):
+						if d.doctype == "Packed Item":
+							incoming_rate = flt(
+								flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
+								d.precision("incoming_rate"),
 							)
+							if d.incoming_rate != incoming_rate:
+								d.incoming_rate = incoming_rate
+						else:
+							rate = flt(
+								flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
+								d.precision("rate"),
+							)
+							if d.rate != rate:
+								d.rate = rate
+								frappe.msgprint(
+									_(
+										"Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer"
+									).format(d.idx),
+									alert=1,
+								)
 
-						d.discount_percentage = 0.0
-						d.discount_amount = 0.0
-						d.margin_rate_or_amount = 0.0
+							d.discount_percentage = 0.0
+							d.discount_amount = 0.0
+							d.margin_rate_or_amount = 0.0
 
 			elif self.get("return_against"):
 				# Get incoming rate of return entry from reference document
diff --git a/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py b/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py
index d23a22a..dea3f2d 100644
--- a/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py
+++ b/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py
@@ -217,7 +217,7 @@
 
 	def check_for_assigned_to(self, period, value, count_or_amount, assigned_to, info):
 		if self.filters.get("assigned_to"):
-			for data in json.loads(info.get("opportunity_owner")):
+			for data in json.loads(info.get("opportunity_owner") or "[]"):
 				if data == self.filters.get("assigned_to"):
 					self.set_formatted_data(period, data, count_or_amount, assigned_to)
 		else:
diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py
index 694dc79..36466ff 100644
--- a/erpnext/manufacturing/doctype/work_order/test_work_order.py
+++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py
@@ -635,6 +635,10 @@
 			bom.submit()
 			bom_name = bom.name
 
+		ste1 = test_stock_entry.make_stock_entry(
+			item_code=rm1, target="_Test Warehouse - _TC", qty=32, basic_rate=5000.0
+		)
+
 		work_order = make_wo_order_test_record(
 			item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1
 		)
@@ -659,11 +663,29 @@
 		work_order.insert()
 		work_order.submit()
 		self.assertEqual(work_order.has_batch_no, 1)
-		ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 30))
+		batches = frappe.get_all("Batch", filters={"reference_name": work_order.name})
+		self.assertEqual(len(batches), 3)
+		batches = [batch.name for batch in batches]
+
+		ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 10))
 		for row in ste1.get("items"):
 			if row.is_finished_item:
 				self.assertEqual(row.item_code, fg_item)
 				self.assertEqual(row.qty, 10)
+				self.assertTrue(row.batch_no in batches)
+				batches.remove(row.batch_no)
+
+		ste1.submit()
+
+		remaining_batches = []
+		ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 20))
+		for row in ste1.get("items"):
+			if row.is_finished_item:
+				self.assertEqual(row.item_code, fg_item)
+				self.assertEqual(row.qty, 10)
+				remaining_batches.append(row.batch_no)
+
+		self.assertEqual(sorted(remaining_batches), sorted(batches))
 
 		frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0)
 
diff --git a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py
index 16c25ce..109d9ab 100644
--- a/erpnext/manufacturing/report/production_planning_report/production_planning_report.py
+++ b/erpnext/manufacturing/report/production_planning_report/production_planning_report.py
@@ -49,7 +49,7 @@
 					parent.bom_no,
 					parent.fg_warehouse.as_("warehouse"),
 				)
-				.where(parent.status.notin(["Completed", "Stopped"]))
+				.where(parent.status.notin(["Completed", "Stopped", "Closed"]))
 			)
 
 			if order_by == "Planned Start Date":
@@ -79,10 +79,11 @@
 				query = query.where(child.parent.isin(self.filters.docnames))
 
 			if doctype == "Sales Order":
-				query = query.select(
-					child.delivery_date,
-					parent.base_grand_total,
-				).where((child.stock_qty > child.produced_qty) & (parent.per_delivered < 100.0))
+				query = query.select(child.delivery_date, parent.base_grand_total,).where(
+					(child.stock_qty > child.produced_qty)
+					& (parent.per_delivered < 100.0)
+					& (parent.status.notin(["Completed", "Closed"]))
+				)
 
 				if order_by == "Delivery Date":
 					query = query.orderby(child.delivery_date, order=Order.asc)
@@ -91,7 +92,9 @@
 
 			elif doctype == "Material Request":
 				query = query.select(child.schedule_date,).where(
-					(parent.per_ordered < 100) & (parent.material_request_type == "Manufacture")
+					(parent.per_ordered < 100)
+					& (parent.material_request_type == "Manufacture")
+					& (parent.status != "Stopped")
 				)
 
 				if order_by == "Required Date":
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 166faf9..0aad1d3 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -318,3 +318,4 @@
 erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization
 erpnext.patches.v14_0.update_partial_tds_fields
 erpnext.patches.v14_0.create_incoterms_and_migrate_shipment
+erpnext.patches.v14_0.setup_clear_repost_logs
\ No newline at end of file
diff --git a/erpnext/patches/v13_0/update_exchange_rate_settings.py b/erpnext/patches/v13_0/update_exchange_rate_settings.py
index 746195f..130a7bf 100644
--- a/erpnext/patches/v13_0/update_exchange_rate_settings.py
+++ b/erpnext/patches/v13_0/update_exchange_rate_settings.py
@@ -1,5 +1,8 @@
+import frappe
+
 from erpnext.setup.install import setup_currency_exchange
 
 
 def execute():
+	frappe.reload_doc("accounts", "doctype", "currency_exchange_settings")
 	setup_currency_exchange()
diff --git a/erpnext/patches/v14_0/setup_clear_repost_logs.py b/erpnext/patches/v14_0/setup_clear_repost_logs.py
new file mode 100644
index 0000000..be9ddca
--- /dev/null
+++ b/erpnext/patches/v14_0/setup_clear_repost_logs.py
@@ -0,0 +1,8 @@
+# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
+# License: MIT. See LICENSE
+
+from erpnext.setup.install import setup_log_settings
+
+
+def execute():
+	setup_log_settings()
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index d80133c..cbf2493 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -42,6 +42,8 @@
 		self.send_welcome_email()
 		self.update_costing()
 		self.update_percent_complete()
+		self.validate_from_to_dates("expected_start_date", "expected_end_date")
+		self.validate_from_to_dates("actual_start_date", "actual_end_date")
 
 	def copy_from_template(self):
 		"""
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index fa50785..79f1b3a 100755
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -9,6 +9,7 @@
 from frappe.desk.form.assign_to import clear, close_all_assignments
 from frappe.model.mapper import get_mapped_doc
 from frappe.utils import add_days, cstr, date_diff, flt, get_link_to_form, getdate, today
+from frappe.utils.data import format_date
 from frappe.utils.nestedset import NestedSet
 
 
@@ -16,10 +17,6 @@
 	pass
 
 
-class EndDateCannotBeGreaterThanProjectEndDateError(frappe.ValidationError):
-	pass
-
-
 class Task(NestedSet):
 	nsm_parent_field = "parent_task"
 
@@ -34,8 +31,6 @@
 
 	def validate(self):
 		self.validate_dates()
-		self.validate_parent_expected_end_date()
-		self.validate_parent_project_dates()
 		self.validate_progress()
 		self.validate_status()
 		self.update_depends_on()
@@ -43,51 +38,42 @@
 		self.validate_completed_on()
 
 	def validate_dates(self):
-		if (
-			self.exp_start_date
-			and self.exp_end_date
-			and getdate(self.exp_start_date) > getdate(self.exp_end_date)
-		):
-			frappe.throw(
-				_("{0} can not be greater than {1}").format(
-					frappe.bold("Expected Start Date"), frappe.bold("Expected End Date")
-				)
-			)
-
-		if (
-			self.act_start_date
-			and self.act_end_date
-			and getdate(self.act_start_date) > getdate(self.act_end_date)
-		):
-			frappe.throw(
-				_("{0} can not be greater than {1}").format(
-					frappe.bold("Actual Start Date"), frappe.bold("Actual End Date")
-				)
-			)
+		self.validate_from_to_dates("exp_start_date", "exp_end_date")
+		self.validate_from_to_dates("act_start_date", "act_end_date")
+		self.validate_parent_expected_end_date()
+		self.validate_parent_project_dates()
 
 	def validate_parent_expected_end_date(self):
-		if self.parent_task:
-			parent_exp_end_date = frappe.db.get_value("Task", self.parent_task, "exp_end_date")
-			if parent_exp_end_date and getdate(self.get("exp_end_date")) > getdate(parent_exp_end_date):
-				frappe.throw(
-					_(
-						"Expected End Date should be less than or equal to parent task's Expected End Date {0}."
-					).format(getdate(parent_exp_end_date))
-				)
+		if not self.parent_task or not self.exp_end_date:
+			return
+
+		parent_exp_end_date = frappe.db.get_value("Task", self.parent_task, "exp_end_date")
+		if not parent_exp_end_date:
+			return
+
+		if getdate(self.exp_end_date) > getdate(parent_exp_end_date):
+			frappe.throw(
+				_(
+					"Expected End Date should be less than or equal to parent task's Expected End Date {0}."
+				).format(format_date(parent_exp_end_date)),
+				frappe.exceptions.InvalidDates,
+			)
 
 	def validate_parent_project_dates(self):
 		if not self.project or frappe.flags.in_test:
 			return
 
-		expected_end_date = frappe.db.get_value("Project", self.project, "expected_end_date")
-
-		if expected_end_date:
-			validate_project_dates(
-				getdate(expected_end_date), self, "exp_start_date", "exp_end_date", "Expected"
-			)
-			validate_project_dates(
-				getdate(expected_end_date), self, "act_start_date", "act_end_date", "Actual"
-			)
+		if project_end_date := frappe.db.get_value("Project", self.project, "expected_end_date"):
+			project_end_date = getdate(project_end_date)
+			for fieldname in ("exp_start_date", "exp_end_date", "act_start_date", "act_end_date"):
+				task_date = self.get(fieldname)
+				if task_date and date_diff(project_end_date, getdate(task_date)) < 0:
+					frappe.throw(
+						_("Task's {0} cannot be after Project's Expected End Date.").format(
+							_(self.meta.get_label(fieldname))
+						),
+						frappe.exceptions.InvalidDates,
+					)
 
 	def validate_status(self):
 		if self.is_template and self.status != "Template":
@@ -398,15 +384,3 @@
 
 def on_doctype_update():
 	frappe.db.add_index("Task", ["lft", "rgt"])
-
-
-def validate_project_dates(project_end_date, task, task_start, task_end, actual_or_expected_date):
-	if task.get(task_start) and date_diff(project_end_date, getdate(task.get(task_start))) < 0:
-		frappe.throw(
-			_("Task's {0} Start Date cannot be after Project's End Date.").format(actual_or_expected_date)
-		)
-
-	if task.get(task_end) and date_diff(project_end_date, getdate(task.get(task_end))) < 0:
-		frappe.throw(
-			_("Task's {0} End Date cannot be after Project's End Date.").format(actual_or_expected_date)
-		)
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 4c3e9dc..7481000 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -47,29 +47,36 @@
 
 		await this.calculate_shipping_charges();
 
-		// Advance calculation applicable to Sales /Purchase Invoice
-		if(in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype)
-			&& this.frm.doc.docstatus < 2 && !this.frm.doc.is_return) {
+		// Advance calculation applicable to Sales/Purchase Invoice
+		if (
+			in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype)
+			&& this.frm.doc.docstatus < 2
+			&& !this.frm.doc.is_return
+		) {
 			this.calculate_total_advance(update_paid_amount);
 		}
 
-		if (in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) && this.frm.doc.is_pos &&
-			this.frm.doc.is_return) {
-			if (this.frm.doc.doctype == "Sales Invoice") {
-				this.set_total_amount_to_default_mop();
-			}
+		if (
+			in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype)
+			&& this.frm.doc.s_pos
+			&& this.frm.doc.is_return
+		) {
+			this.set_total_amount_to_default_mop();
 			this.calculate_paid_amount();
 		}
 
 		// Sales person's commission
-		if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
+		if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
 			this.calculate_commission();
 			this.calculate_contribution();
 		}
 
 		// Update paid amount on return/debit note creation
-		if(this.frm.doc.doctype === "Purchase Invoice" && this.frm.doc.is_return
-			&& (this.frm.doc.grand_total > this.frm.doc.paid_amount)) {
+		if (
+			this.frm.doc.doctype === "Purchase Invoice"
+			&& this.frm.doc.is_return
+			&& (this.frm.doc.grand_total > this.frm.doc.paid_amount)
+		) {
 			this.frm.doc.paid_amount = flt(this.frm.doc.grand_total, precision("grand_total"));
 		}
 
@@ -775,21 +782,30 @@
 		let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
 		let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
 
-		if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
-			var total_amount_to_pay = flt((grand_total - this.frm.doc.total_advance
-				- this.frm.doc.write_off_amount), precision("grand_total"));
+		if (this.frm.doc.party_account_currency == this.frm.doc.currency) {
+			var total_amount_to_pay = flt(
+				grand_total - this.frm.doc.total_advance - this.frm.doc.write_off_amount,
+				precision("grand_total")
+			);
 		} else {
 			var total_amount_to_pay = flt(
-				(flt(base_grand_total, precision("base_grand_total"))
-					- this.frm.doc.total_advance - this.frm.doc.base_write_off_amount),
+				(
+					flt(
+						base_grand_total,
+						precision("base_grand_total")
+					)
+					- this.frm.doc.total_advance - this.frm.doc.base_write_off_amount
+				),
 				precision("base_grand_total")
 			);
 		}
+
 		this.frm.doc.payments.find(pay => {
 			if (pay.default) {
 				pay.amount = total_amount_to_pay;
 			}
 		});
+
 		this.frm.refresh_fields();
 	}
 
diff --git a/erpnext/setup/doctype/employee/employee.py b/erpnext/setup/doctype/employee/employee.py
index 13a6f20..facefa3 100755
--- a/erpnext/setup/doctype/employee/employee.py
+++ b/erpnext/setup/doctype/employee/employee.py
@@ -145,33 +145,10 @@
 		if self.date_of_birth and getdate(self.date_of_birth) > getdate(today()):
 			throw(_("Date of Birth cannot be greater than today."))
 
-		if (
-			self.date_of_birth
-			and self.date_of_joining
-			and getdate(self.date_of_birth) >= getdate(self.date_of_joining)
-		):
-			throw(_("Date of Joining must be greater than Date of Birth"))
-
-		elif (
-			self.date_of_retirement
-			and self.date_of_joining
-			and (getdate(self.date_of_retirement) <= getdate(self.date_of_joining))
-		):
-			throw(_("Date Of Retirement must be greater than Date of Joining"))
-
-		elif (
-			self.relieving_date
-			and self.date_of_joining
-			and (getdate(self.relieving_date) < getdate(self.date_of_joining))
-		):
-			throw(_("Relieving Date must be greater than or equal to Date of Joining"))
-
-		elif (
-			self.contract_end_date
-			and self.date_of_joining
-			and (getdate(self.contract_end_date) <= getdate(self.date_of_joining))
-		):
-			throw(_("Contract End Date must be greater than Date of Joining"))
+		self.validate_from_to_dates("date_of_birth", "date_of_joining")
+		self.validate_from_to_dates("date_of_joining", "date_of_retirement")
+		self.validate_from_to_dates("date_of_joining", "relieving_date")
+		self.validate_from_to_dates("date_of_joining", "contract_end_date")
 
 	def validate_email(self):
 		if self.company_email:
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index d3b47f9..1f7dddf 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -30,6 +30,7 @@
 	add_company_to_session_defaults()
 	add_standard_navbar_items()
 	add_app_name()
+	setup_log_settings()
 	frappe.db.commit()
 
 
@@ -197,3 +198,10 @@
 
 def add_app_name():
 	frappe.db.set_value("System Settings", None, "app_name", "ERPNext")
+
+
+def setup_log_settings():
+	log_settings = frappe.get_single("Log Settings")
+	log_settings.append("logs_to_clear", {"ref_doctype": "Repost Item Valuation", "days": 60})
+
+	log_settings.save(ignore_permissions=True)
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 04aee42..afad751 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -596,7 +596,9 @@
 		if source.material_request_type == "Customer Provided":
 			target.purpose = "Material Receipt"
 
-		target.set_missing_values()
+		target.set_transfer_qty()
+		target.set_actual_qty()
+		target.calculate_rate_and_amount(raise_error_if_no_rate=False)
 		target.set_stock_entry_type()
 		target.set_job_card_data()
 
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index 4d05d7a..d606751 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -48,7 +48,7 @@
 				update_packed_item_from_cancelled_doc(item_row, bundle_item, pi_row, doc)
 
 				if set_price_from_children:  # create/update bundle item wise price dict
-					update_product_bundle_rate(parent_items_price, pi_row)
+					update_product_bundle_rate(parent_items_price, pi_row, item_row)
 
 	if parent_items_price:
 		set_product_bundle_rate_amount(doc, parent_items_price)  # set price in bundle item
@@ -247,7 +247,7 @@
 	return prev_doc_packed_items_map
 
 
-def update_product_bundle_rate(parent_items_price, pi_row):
+def update_product_bundle_rate(parent_items_price, pi_row, item_row):
 	"""
 	Update the price dict of Product Bundles based on the rates of the Items in the bundle.
 
@@ -259,7 +259,7 @@
 	if not rate:
 		parent_items_price[key] = 0.0
 
-	parent_items_price[key] += flt(pi_row.rate)
+	parent_items_price[key] += flt((pi_row.rate * pi_row.qty) / item_row.stock_qty)
 
 
 def set_product_bundle_rate_amount(doc, parent_items_price):
diff --git a/erpnext/stock/doctype/packed_item/test_packed_item.py b/erpnext/stock/doctype/packed_item/test_packed_item.py
index ad7fd9a..ad06732 100644
--- a/erpnext/stock/doctype/packed_item/test_packed_item.py
+++ b/erpnext/stock/doctype/packed_item/test_packed_item.py
@@ -126,8 +126,8 @@
 		so.packed_items[1].rate = 200
 		so.save()
 
-		self.assertEqual(so.items[0].rate, 350)
-		self.assertEqual(so.items[0].amount, 700)
+		self.assertEqual(so.items[0].rate, 700)
+		self.assertEqual(so.items[0].amount, 1400)
 
 	def test_newly_mapped_doc_packed_items(self):
 		"Test impact on packed items in newly mapped DN from SO."
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 673fcb5..3739cb8 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -173,7 +173,9 @@
 		)
 
 		if (
-			cint(frappe.db.get_single_value("Buying Settings", "maintain_same_rate")) and not self.is_return
+			cint(frappe.db.get_single_value("Buying Settings", "maintain_same_rate"))
+			and not self.is_return
+			and not self.is_internal_supplier
 		):
 			self.validate_rate_with_reference_doc(
 				[["Purchase Order", "purchase_order", "purchase_order_item"]]
diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
index 8e914e6..bbed099 100644
--- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
+++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
@@ -5,6 +5,8 @@
 from frappe import _
 from frappe.exceptions import QueryDeadlockError, QueryTimeoutError
 from frappe.model.document import Document
+from frappe.query_builder import DocType, Interval
+from frappe.query_builder.functions import Now
 from frappe.utils import cint, get_link_to_form, get_weekday, getdate, now, nowtime
 from frappe.utils.user import get_users_with_role
 from rq.timeouts import JobTimeoutException
@@ -21,6 +23,18 @@
 
 
 class RepostItemValuation(Document):
+	@staticmethod
+	def clear_old_logs(days=None):
+		days = days or 90
+		table = DocType("Repost Item Valuation")
+		frappe.db.delete(
+			table,
+			filters=(
+				(table.modified < (Now() - Interval(days=days)))
+				& (table.status.isin(["Completed", "Skipped"]))
+			),
+		)
+
 	def validate(self):
 		self.set_status(write=False)
 		self.reset_field_values()
diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
index f166775..96ac435 100644
--- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
+++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
@@ -6,8 +6,7 @@
 
 import frappe
 from frappe.tests.utils import FrappeTestCase
-from frappe.utils import nowdate
-from frappe.utils.data import add_to_date, today
+from frappe.utils import add_days, add_to_date, now, nowdate, today
 
 from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
 from erpnext.accounts.utils import repost_gle_for_stock_vouchers
@@ -86,6 +85,33 @@
 				msg=f"Exepcted false from : {case}",
 			)
 
+	def test_clear_old_logs(self):
+		# create 10 logs
+		for i in range(1, 20):
+			repost_doc = frappe.get_doc(
+				doctype="Repost Item Valuation",
+				item_code="_Test Item",
+				warehouse="_Test Warehouse - _TC",
+				based_on="Item and Warehouse",
+				posting_date=nowdate(),
+				status="Skipped",
+				posting_time="00:01:00",
+			).insert(ignore_permissions=True)
+
+			repost_doc.load_from_db()
+			repost_doc.modified = add_days(now(), days=-i * 10)
+			repost_doc.db_update_all()
+
+		logs = frappe.get_all("Repost Item Valuation", filters={"status": "Skipped"})
+		self.assertTrue(len(logs) > 10)
+
+		from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import RepostItemValuation
+
+		RepostItemValuation.clear_old_logs(days=1)
+
+		logs = frappe.get_all("Repost Item Valuation", filters={"status": "Skipped"})
+		self.assertTrue(len(logs) == 0)
+
 	def test_create_item_wise_repost_item_valuation_entries(self):
 		pr = make_purchase_receipt(
 			company="_Test Company with perpetual inventory",
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index b116735..f6c53f7 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -659,6 +659,13 @@
 
 			if d.allow_zero_valuation_rate:
 				d.basic_rate = 0.0
+				frappe.msgprint(
+					_(
+						"Row {0}: Item rate has been updated to zero as Allow Zero Valuation Rate is checked for item {1}"
+					).format(d.idx, d.item_code),
+					alert=1,
+				)
+
 			elif d.is_finished_item:
 				if self.purpose == "Manufacture":
 					d.basic_rate = self.get_basic_rate_for_manufactured_item(
@@ -1538,6 +1545,7 @@
 			"reference_name": self.pro_doc.name,
 			"reference_doctype": self.pro_doc.doctype,
 			"qty_to_produce": (">", 0),
+			"batch_qty": ("=", 0),
 		}
 
 		fields = ["qty_to_produce as qty", "produced_qty", "name"]
@@ -2231,14 +2239,14 @@
 			d.qty -= process_loss_dict[d.item_code][1]
 
 	def set_serial_no_batch_for_finished_good(self):
-		args = {}
+		serial_nos = ""
 		if self.pro_doc.serial_no:
-			self.get_serial_nos_for_fg(args)
+			serial_nos = self.get_serial_nos_for_fg()
 
 		for row in self.items:
 			if row.is_finished_item and row.item_code == self.pro_doc.production_item:
-				if args.get("serial_no"):
-					row.serial_no = "\n".join(args["serial_no"][0 : cint(row.qty)])
+				if serial_nos:
+					row.serial_no = "\n".join(serial_nos[0 : cint(row.qty)])
 
 	def get_serial_nos_for_fg(self, args):
 		fields = [
@@ -2251,14 +2259,14 @@
 		filters = [
 			["Stock Entry", "work_order", "=", self.work_order],
 			["Stock Entry", "purpose", "=", "Manufacture"],
-			["Stock Entry", "docstatus", "=", 1],
+			["Stock Entry", "docstatus", "<", 2],
 			["Stock Entry Detail", "item_code", "=", self.pro_doc.production_item],
 		]
 
 		stock_entries = frappe.get_all("Stock Entry", fields=fields, filters=filters)
 
 		if self.pro_doc.serial_no:
-			args["serial_no"] = self.get_available_serial_nos(stock_entries)
+			return self.get_available_serial_nos(stock_entries)
 
 	def get_available_serial_nos(self, stock_entries):
 		used_serial_nos = []
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 6e06d23..430a8d1 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -2,12 +2,10 @@
 # License: GNU General Public License v3. See license.txt
 
 
-from collections import defaultdict
-
 import frappe
 from frappe import _, throw
 from frappe.contacts.address_and_contact import load_address_and_contact
-from frappe.utils import cint, flt
+from frappe.utils import cint
 from frappe.utils.nestedset import NestedSet
 from pypika.terms import ExistsCriterion
 
@@ -166,60 +164,7 @@
 		["company", "in", (company, None, "")],
 	]
 
-	warehouses = frappe.get_list(doctype, fields=fields, filters=filters, order_by="name")
-
-	company_currency = ""
-	if company:
-		company_currency = frappe.get_cached_value("Company", company, "default_currency")
-
-	warehouse_wise_value = get_warehouse_wise_stock_value(company)
-
-	# return warehouses
-	for wh in warehouses:
-		wh["balance"] = warehouse_wise_value.get(wh.value)
-		if company_currency:
-			wh["company_currency"] = company_currency
-	return warehouses
-
-
-def get_warehouse_wise_stock_value(company):
-	warehouses = frappe.get_all(
-		"Warehouse", fields=["name", "parent_warehouse"], filters={"company": company}
-	)
-	parent_warehouse = {d.name: d.parent_warehouse for d in warehouses}
-
-	filters = {"warehouse": ("in", [data.name for data in warehouses])}
-	bin_data = frappe.get_all(
-		"Bin",
-		fields=["sum(stock_value) as stock_value", "warehouse"],
-		filters=filters,
-		group_by="warehouse",
-	)
-
-	warehouse_wise_stock_value = defaultdict(float)
-	for row in bin_data:
-		if not row.stock_value:
-			continue
-
-		warehouse_wise_stock_value[row.warehouse] = row.stock_value
-		update_value_in_parent_warehouse(
-			warehouse_wise_stock_value, parent_warehouse, row.warehouse, row.stock_value
-		)
-
-	return warehouse_wise_stock_value
-
-
-def update_value_in_parent_warehouse(
-	warehouse_wise_stock_value, parent_warehouse_dict, warehouse, stock_value
-):
-	parent_warehouse = parent_warehouse_dict.get(warehouse)
-	if not parent_warehouse:
-		return
-
-	warehouse_wise_stock_value[parent_warehouse] += flt(stock_value)
-	update_value_in_parent_warehouse(
-		warehouse_wise_stock_value, parent_warehouse_dict, parent_warehouse, stock_value
-	)
+	return frappe.get_list(doctype, fields=fields, filters=filters, order_by="name")
 
 
 @frappe.whitelist()
diff --git a/erpnext/stock/doctype/warehouse/warehouse_tree.js b/erpnext/stock/doctype/warehouse/warehouse_tree.js
index e9e14c7..eb635e6 100644
--- a/erpnext/stock/doctype/warehouse/warehouse_tree.js
+++ b/erpnext/stock/doctype/warehouse/warehouse_tree.js
@@ -17,11 +17,4 @@
 			description: __("Child nodes can be only created under 'Group' type nodes")}
 	],
 	ignore_fields:["parent_warehouse"],
-	onrender: function(node) {
-		if (node.data && node.data.balance!==undefined) {
-			$('<span class="balance-area pull-right">'
-			+ format_currency((node.data.balance), node.data.company_currency)
-			+ '</span>').insertBefore(node.$ul);
-		}
-	}
 }
diff --git a/erpnext/stock/report/warehouse_wise_stock_balance/__init__.py b/erpnext/stock/report/warehouse_wise_stock_balance/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/stock/report/warehouse_wise_stock_balance/__init__.py
diff --git a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js
new file mode 100644
index 0000000..58a043e
--- /dev/null
+++ b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.js
@@ -0,0 +1,20 @@
+// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+/* eslint-disable */
+
+frappe.query_reports["Warehouse Wise Stock Balance"] = {
+	"filters": [
+		{
+			"fieldname":"company",
+			"label": __("Company"),
+			"fieldtype": "Link",
+			"options": "Company",
+			"reqd": 1,
+			"default": frappe.defaults.get_user_default("Company")
+		}
+	],
+	"initial_depth": 3,
+	"tree": true,
+	"parent_field": "parent_warehouse",
+	"name_field": "warehouse"
+};
diff --git a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.json b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.json
new file mode 100644
index 0000000..4f7ec65
--- /dev/null
+++ b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.json
@@ -0,0 +1,30 @@
+{
+ "add_total_row": 0,
+ "columns": [],
+ "creation": "2022-12-06 14:15:31.924345",
+ "disable_prepared_report": 0,
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "filters": [],
+ "idx": 0,
+ "is_standard": "Yes",
+ "json": "{}",
+ "modified": "2022-12-06 14:16:55.969214",
+ "modified_by": "Administrator",
+ "module": "Stock",
+ "name": "Warehouse Wise Stock Balance",
+ "owner": "Administrator",
+ "prepared_report": 0,
+ "ref_doctype": "Stock Ledger Entry",
+ "report_name": "Warehouse Wise Stock Balance",
+ "report_type": "Script Report",
+ "roles": [
+  {
+   "role": "Stock User"
+  },
+  {
+   "role": "Accounts Manager"
+  }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py
new file mode 100644
index 0000000..d364b57
--- /dev/null
+++ b/erpnext/stock/report/warehouse_wise_stock_balance/warehouse_wise_stock_balance.py
@@ -0,0 +1,103 @@
+# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from typing import Any, Dict, List, Optional, TypedDict
+
+import frappe
+from frappe import _
+from frappe.query_builder.functions import Sum
+
+
+class StockBalanceFilter(TypedDict):
+	company: Optional[str]
+	warehouse: Optional[str]
+
+
+SLEntry = Dict[str, Any]
+
+
+def execute(filters=None):
+	columns, data = [], []
+	columns = get_columns()
+	data = get_data(filters)
+
+	return columns, data
+
+
+def get_warehouse_wise_balance(filters: StockBalanceFilter) -> List[SLEntry]:
+	sle = frappe.qb.DocType("Stock Ledger Entry")
+
+	query = (
+		frappe.qb.from_(sle)
+		.select(sle.warehouse, Sum(sle.stock_value_difference).as_("stock_balance"))
+		.where((sle.docstatus < 2) & (sle.is_cancelled == 0))
+		.groupby(sle.warehouse)
+	)
+
+	if filters.get("company"):
+		query = query.where(sle.company == filters.get("company"))
+
+	data = query.run(as_list=True)
+	return frappe._dict(data) if data else frappe._dict()
+
+
+def get_warehouses(report_filters: StockBalanceFilter):
+	return frappe.get_all(
+		"Warehouse",
+		fields=["name", "parent_warehouse", "is_group"],
+		filters={"company": report_filters.company},
+		order_by="lft",
+	)
+
+
+def get_data(filters: StockBalanceFilter):
+	warehouse_balance = get_warehouse_wise_balance(filters)
+	warehouses = get_warehouses(filters)
+
+	for warehouse in warehouses:
+		warehouse.stock_balance = warehouse_balance.get(warehouse.name, 0) or 0.0
+
+	update_indent(warehouses)
+	set_balance_in_parent(warehouses)
+
+	return warehouses
+
+
+def update_indent(warehouses):
+	for warehouse in warehouses:
+
+		def add_indent(warehouse, indent):
+			warehouse.indent = indent
+			for child in warehouses:
+				if child.parent_warehouse == warehouse.name:
+					add_indent(child, indent + 1)
+
+		if warehouse.is_group:
+			add_indent(warehouse, warehouse.indent or 0)
+
+
+def set_balance_in_parent(warehouses):
+	# sort warehouses by indent in descending order
+	warehouses = sorted(warehouses, key=lambda x: x.get("indent", 0), reverse=1)
+
+	for warehouse in warehouses:
+
+		def update_balance(warehouse, balance):
+			for parent in warehouses:
+				if warehouse.parent_warehouse == parent.name:
+					parent.stock_balance += balance
+
+		update_balance(warehouse, warehouse.stock_balance)
+
+
+def get_columns():
+	return [
+		{
+			"label": _("Warehouse"),
+			"fieldname": "name",
+			"fieldtype": "Link",
+			"options": "Warehouse",
+			"width": 200,
+		},
+		{"label": _("Stock Balance"), "fieldname": "stock_balance", "fieldtype": "Float", "width": 150},
+	]
diff --git a/erpnext/stock/workspace/stock/stock.json b/erpnext/stock/workspace/stock/stock.json
index ed33067..de5e6de 100644
--- a/erpnext/stock/workspace/stock/stock.json
+++ b/erpnext/stock/workspace/stock/stock.json
@@ -5,7 +5,7 @@
    "label": "Warehouse wise Stock Value"
   }
  ],
- "content": "[{\"type\":\"onboarding\",\"data\":{\"onboarding_name\":\"Stock\",\"col\":12}},{\"type\":\"chart\",\"data\":{\"chart_name\":\"Warehouse wise Stock Value\",\"col\":12}},{\"type\":\"spacer\",\"data\":{\"col\":12}},{\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Quick Access</b></span>\",\"col\":12}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Item\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Material Request\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Stock Entry\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Purchase Receipt\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Delivery Note\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Stock Ledger\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Stock Balance\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Dashboard\",\"col\":3}},{\"type\":\"spacer\",\"data\":{\"col\":12}},{\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Masters & Reports</b></span>\",\"col\":12}},{\"type\":\"card\",\"data\":{\"card_name\":\"Items and Pricing\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Stock Transactions\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Stock Reports\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Settings\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Serial No and Batch\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Tools\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Key Reports\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Other Reports\",\"col\":4}}]",
+ "content": "[{\"type\":\"onboarding\",\"data\":{\"onboarding_name\":\"Stock\",\"col\":12}},{\"type\":\"chart\",\"data\":{\"chart_name\":\"Warehouse wise Stock Value\",\"col\":12}},{\"type\":\"spacer\",\"data\":{\"col\":12}},{\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Quick Access</b></span>\",\"col\":12}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Item\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Material Request\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Stock Entry\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Purchase Receipt\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Delivery Note\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Stock Ledger\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Stock Balance\",\"col\":3}},{\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Dashboard\",\"col\":3}},{\"type\":\"spacer\",\"data\":{\"col\":12}},{\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\"><b>Masters &amp; Reports</b></span>\",\"col\":12}},{\"type\":\"card\",\"data\":{\"card_name\":\"Items and Pricing\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Stock Transactions\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Stock Reports\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Settings\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Serial No and Batch\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Tools\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Key Reports\",\"col\":4}},{\"type\":\"card\",\"data\":{\"card_name\":\"Other Reports\",\"col\":4}}]",
  "creation": "2020-03-02 15:43:10.096528",
  "docstatus": 0,
  "doctype": "Workspace",
@@ -210,80 +210,6 @@
   {
    "hidden": 0,
    "is_query_report": 0,
-   "label": "Stock Reports",
-   "link_count": 0,
-   "onboard": 0,
-   "type": "Card Break"
-  },
-  {
-   "dependencies": "Item",
-   "hidden": 0,
-   "is_query_report": 1,
-   "label": "Stock Ledger",
-   "link_count": 0,
-   "link_to": "Stock Ledger",
-   "link_type": "Report",
-   "onboard": 1,
-   "type": "Link"
-  },
-  {
-   "dependencies": "Item",
-   "hidden": 0,
-   "is_query_report": 1,
-   "label": "Stock Balance",
-   "link_count": 0,
-   "link_to": "Stock Balance",
-   "link_type": "Report",
-   "onboard": 1,
-   "type": "Link"
-  },
-  {
-   "dependencies": "Item",
-   "hidden": 0,
-   "is_query_report": 1,
-   "label": "Stock Projected Qty",
-   "link_count": 0,
-   "link_to": "Stock Projected Qty",
-   "link_type": "Report",
-   "onboard": 1,
-   "type": "Link"
-  },
-  {
-   "dependencies": "Item",
-   "hidden": 0,
-   "is_query_report": 0,
-   "label": "Stock Summary",
-   "link_count": 0,
-   "link_to": "stock-balance",
-   "link_type": "Page",
-   "onboard": 0,
-   "type": "Link"
-  },
-  {
-   "dependencies": "Item",
-   "hidden": 0,
-   "is_query_report": 1,
-   "label": "Stock Ageing",
-   "link_count": 0,
-   "link_to": "Stock Ageing",
-   "link_type": "Report",
-   "onboard": 0,
-   "type": "Link"
-  },
-  {
-   "dependencies": "Item",
-   "hidden": 0,
-   "is_query_report": 1,
-   "label": "Item Price Stock",
-   "link_count": 0,
-   "link_to": "Item Price Stock",
-   "link_type": "Report",
-   "onboard": 0,
-   "type": "Link"
-  },
-  {
-   "hidden": 0,
-   "is_query_report": 0,
    "label": "Settings",
    "link_count": 0,
    "onboard": 0,
@@ -705,15 +631,100 @@
    "link_type": "Report",
    "onboard": 0,
    "type": "Link"
+  },
+  {
+   "hidden": 0,
+   "is_query_report": 0,
+   "label": "Stock Reports",
+   "link_count": 7,
+   "onboard": 0,
+   "type": "Card Break"
+  },
+  {
+   "dependencies": "Item",
+   "hidden": 0,
+   "is_query_report": 1,
+   "label": "Stock Ledger",
+   "link_count": 0,
+   "link_to": "Stock Ledger",
+   "link_type": "Report",
+   "onboard": 1,
+   "type": "Link"
+  },
+  {
+   "dependencies": "Item",
+   "hidden": 0,
+   "is_query_report": 1,
+   "label": "Stock Balance",
+   "link_count": 0,
+   "link_to": "Stock Balance",
+   "link_type": "Report",
+   "onboard": 1,
+   "type": "Link"
+  },
+  {
+   "dependencies": "Item",
+   "hidden": 0,
+   "is_query_report": 1,
+   "label": "Stock Projected Qty",
+   "link_count": 0,
+   "link_to": "Stock Projected Qty",
+   "link_type": "Report",
+   "onboard": 1,
+   "type": "Link"
+  },
+  {
+   "dependencies": "Item",
+   "hidden": 0,
+   "is_query_report": 0,
+   "label": "Stock Summary",
+   "link_count": 0,
+   "link_to": "stock-balance",
+   "link_type": "Page",
+   "onboard": 0,
+   "type": "Link"
+  },
+  {
+   "dependencies": "Item",
+   "hidden": 0,
+   "is_query_report": 1,
+   "label": "Stock Ageing",
+   "link_count": 0,
+   "link_to": "Stock Ageing",
+   "link_type": "Report",
+   "onboard": 0,
+   "type": "Link"
+  },
+  {
+   "dependencies": "Item",
+   "hidden": 0,
+   "is_query_report": 1,
+   "label": "Item Price Stock",
+   "link_count": 0,
+   "link_to": "Item Price Stock",
+   "link_type": "Report",
+   "onboard": 0,
+   "type": "Link"
+  },
+  {
+   "hidden": 0,
+   "is_query_report": 0,
+   "label": "Warehouse Wise Stock Balance",
+   "link_count": 0,
+   "link_to": "Warehouse Wise Stock Balance",
+   "link_type": "Report",
+   "onboard": 0,
+   "type": "Link"
   }
  ],
- "modified": "2022-01-13 17:47:38.339931",
+ "modified": "2022-12-06 17:03:56.397272",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Stock",
  "owner": "Administrator",
  "parent_page": "",
  "public": 1,
+ "quick_lists": [],
  "restrict_to_domain": "",
  "roles": [],
  "sequence_id": 24.0,