fix: opening entry causing discepancy between stock and trial balance
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index e77e828..82f38da 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -237,9 +237,9 @@
 		or filters.get("party")
 		or filters.get("group_by") in ["Group by Account", "Group by Party"]
 	):
-		conditions.append("posting_date >=%(from_date)s")
+		conditions.append("(posting_date >=%(from_date)s or is_opening = 'Yes')")
 
-	conditions.append("(posting_date <=%(to_date)s or is_opening = 'Yes')")
+	conditions.append("(posting_date <=%(to_date)s)")
 
 	if filters.get("project"):
 		conditions.append("project in %(project)s")
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py
index 6bd08ad..6d2cd8e 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.py
+++ b/erpnext/accounts/report/trial_balance/trial_balance.py
@@ -172,6 +172,7 @@
 	query_filters = {
 		"company": filters.company,
 		"from_date": filters.from_date,
+		"to_date": filters.to_date,
 		"report_type": report_type,
 		"year_start_date": filters.year_start_date,
 		"project": filters.project,
@@ -200,7 +201,7 @@
 		where
 			company=%(company)s
 			{additional_conditions}
-			and (posting_date < %(from_date)s or ifnull(is_opening, 'No') = 'Yes')
+			and (posting_date < %(from_date)s or (ifnull(is_opening, 'No') = 'Yes' and posting_date <= %(to_date)s))
 			and account in (select name from `tabAccount` where report_type=%(report_type)s)
 			and is_cancelled = 0
 		group by account""".format(
diff --git a/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py b/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py
index 5fcfdff..ee22348 100644
--- a/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py
+++ b/erpnext/accounts/report/trial_balance_for_party/trial_balance_for_party.py
@@ -104,12 +104,17 @@
 		where company=%(company)s
 			and is_cancelled=0
 			and ifnull(party_type, '') = %(party_type)s and ifnull(party, '') != ''
-			and (posting_date < %(from_date)s or ifnull(is_opening, 'No') = 'Yes')
+			and (posting_date < %(from_date)s or (ifnull(is_opening, 'No') = 'Yes' and posting_date <= %(to_date)s))
 			{account_filter}
 		group by party""".format(
 			account_filter=account_filter
 		),
-		{"company": filters.company, "from_date": filters.from_date, "party_type": filters.party_type},
+		{
+			"company": filters.company,
+			"from_date": filters.from_date,
+			"to_date": filters.to_date,
+			"party_type": filters.party_type,
+		},
 		as_dict=True,
 	)