Merge pull request #35618 from s-aga-r/FIX-SBB-SERIAL-NO-QTY

fix: reset entries qty to `1` for serial item
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index c64f296..0dfcee4 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -812,14 +812,14 @@
 			number_of_depreciations_booked=1,
 			opening_accumulated_depreciation=50000,
 			expected_value_after_useful_life=10000,
-			depreciation_start_date="2030-12-31",
+			depreciation_start_date="2031-12-31",
 			total_number_of_depreciations=3,
 			frequency_of_depreciation=12,
 		)
 
 		self.assertEqual(asset.status, "Draft")
 
-		expected_schedules = [["2030-12-31", 33333.50, 83333.50], ["2031-12-31", 6666.50, 90000.0]]
+		expected_schedules = [["2031-12-31", 33333.50, 83333.50], ["2032-12-31", 6666.50, 90000.0]]
 
 		schedules = [
 			[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
index 982d376..deae8c7 100644
--- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
+++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py
@@ -10,6 +10,7 @@
 	cint,
 	date_diff,
 	flt,
+	get_first_day,
 	get_last_day,
 	getdate,
 	is_last_day_of_the_month,
@@ -271,8 +272,14 @@
 				break
 
 			# For first row
-			if n == 0 and has_pro_rata and not self.opening_accumulated_depreciation:
-				from_date = add_days(asset_doc.available_for_use_date, -1)
+			if (
+				n == 0
+				and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
+				and not self.opening_accumulated_depreciation
+			):
+				from_date = add_days(
+					asset_doc.available_for_use_date, -1
+				)  # needed to calc depr amount for available_for_use_date too
 				depreciation_amount, days, months = _get_pro_rata_amt(
 					row,
 					depreciation_amount,
@@ -281,10 +288,18 @@
 					has_wdv_or_dd_non_yearly_pro_rata,
 				)
 			elif n == 0 and has_wdv_or_dd_non_yearly_pro_rata and self.opening_accumulated_depreciation:
-				from_date = add_months(
-					getdate(asset_doc.available_for_use_date),
-					(self.number_of_depreciations_booked * row.frequency_of_depreciation),
-				)
+				if not is_first_day_of_the_month(getdate(asset_doc.available_for_use_date)):
+					from_date = get_last_day(
+						add_months(
+							getdate(asset_doc.available_for_use_date),
+							((self.number_of_depreciations_booked - 1) * row.frequency_of_depreciation),
+						)
+					)
+				else:
+					from_date = add_months(
+						getdate(add_days(asset_doc.available_for_use_date, -1)),
+						(self.number_of_depreciations_booked * row.frequency_of_depreciation),
+					)
 				depreciation_amount, days, months = _get_pro_rata_amt(
 					row,
 					depreciation_amount,
@@ -702,3 +717,9 @@
 			["status", "=", status],
 		],
 	)
+
+
+def is_first_day_of_the_month(date):
+	first_day_of_the_month = get_first_day(date)
+
+	return getdate(first_day_of_the_month) == getdate(date)
diff --git a/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.py b/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.py
index a796372..295d979 100644
--- a/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.py
+++ b/erpnext/stock/doctype/closing_stock_balance/closing_stock_balance.py
@@ -51,7 +51,7 @@
 
 		for fieldname in ["warehouse", "item_code", "item_group", "warehouse_type"]:
 			if self.get(fieldname):
-				query = query.where(table.get(fieldname) == self.get(fieldname))
+				query = query.where(table[fieldname] == self.get(fieldname))
 
 		query = query.run(as_dict=True)