fix: running balance after sorting
diff --git a/erpnext/accounts/report/purchase_register/purchase_register.py b/erpnext/accounts/report/purchase_register/purchase_register.py
index 720b5ea..819da78 100644
--- a/erpnext/accounts/report/purchase_register/purchase_register.py
+++ b/erpnext/accounts/report/purchase_register/purchase_register.py
@@ -69,7 +69,7 @@
"balance": flt(opening_row.balance),
}
)
- running_balance = flt(opening_row.balance)
+
data = []
for inv in invoice_list:
# invoice details
@@ -136,12 +136,16 @@
row.update({"debit": inv.base_grand_total, "credit": 0.0})
else:
row.update({"debit": 0.0, "credit": inv.base_grand_total})
- if include_payments:
- running_balance += row["debit"] - row["credit"]
- row.update({"balance": running_balance})
data.append(row)
res += sorted(data, key=lambda x: x["posting_date"])
+
+ if include_payments:
+ running_balance = flt(opening_row.balance)
+ for row in range(1, len(res)):
+ running_balance += res[row]["debit"] - res[row]["credit"]
+ res[row].update({"balance": running_balance})
+
return columns, res, None, None, None, include_payments
diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py
index dca84a5..b84f259 100644
--- a/erpnext/accounts/report/sales_register/sales_register.py
+++ b/erpnext/accounts/report/sales_register/sales_register.py
@@ -66,13 +66,13 @@
)[0]
res.append(
{
- "receivable_account": opening_row,
+ "receivable_account": opening_row.account,
"debit": flt(opening_row.debit),
"credit": flt(opening_row.credit),
"balance": flt(opening_row.balance),
}
)
- running_balance = flt(opening_row.balance)
+
data = []
for inv in invoice_list:
# invoice details
@@ -152,12 +152,16 @@
row.update({"debit": inv.base_grand_total, "credit": 0.0})
else:
row.update({"debit": 0.0, "credit": inv.base_grand_total})
- if include_payments:
- running_balance += row["debit"] - row["credit"]
- row.update({"balance": running_balance})
data.append(row)
res += sorted(data, key=lambda x: x["posting_date"])
+
+ if include_payments:
+ running_balance = flt(opening_row.balance)
+ for row in range(1, len(res)):
+ running_balance += res[row]["debit"] - res[row]["credit"]
+ res[row].update({"balance": running_balance})
+
return columns, res, None, None, None, include_payments