fix: Closing balance entries for period closing voucher
diff --git a/erpnext/accounts/doctype/closing_balance/closing_balance.json b/erpnext/accounts/doctype/closing_balance/closing_balance.json
index 377121f..37d26b8 100644
--- a/erpnext/accounts/doctype/closing_balance/closing_balance.json
+++ b/erpnext/accounts/doctype/closing_balance/closing_balance.json
@@ -15,11 +15,10 @@
"debit_in_account_currency",
"credit_in_account_currency",
"project",
- "is_opening",
- "fiscal_year",
"company",
"finance_book",
- "period_closing_voucher"
+ "period_closing_voucher",
+ "is_period_closing_voucher_entry"
],
"fields": [
{
@@ -95,24 +94,6 @@
"options": "Project"
},
{
- "fieldname": "is_opening",
- "fieldtype": "Select",
- "in_filter": 1,
- "label": "Is Opening",
- "oldfieldname": "is_opening",
- "oldfieldtype": "Select",
- "options": "No\nYes"
- },
- {
- "fieldname": "fiscal_year",
- "fieldtype": "Link",
- "in_filter": 1,
- "label": "Fiscal Year",
- "oldfieldname": "fiscal_year",
- "oldfieldtype": "Select",
- "options": "Fiscal Year"
- },
- {
"fieldname": "company",
"fieldtype": "Link",
"in_filter": 1,
@@ -136,12 +117,18 @@
"in_standard_filter": 1,
"label": "Period Closing Voucher",
"options": "Period Closing Voucher"
+ },
+ {
+ "default": "0",
+ "fieldname": "is_period_closing_voucher_entry",
+ "fieldtype": "Check",
+ "label": "Is Period Closing Voucher Entry"
}
],
"icon": "fa fa-list",
"in_create": 1,
"links": [],
- "modified": "2023-02-24 18:11:11.612395",
+ "modified": "2023-02-27 19:47:36.658224",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Closing Balance",
diff --git a/erpnext/accounts/doctype/closing_balance/closing_balance.py b/erpnext/accounts/doctype/closing_balance/closing_balance.py
index d49459d..7dccaca 100644
--- a/erpnext/accounts/doctype/closing_balance/closing_balance.py
+++ b/erpnext/accounts/doctype/closing_balance/closing_balance.py
@@ -35,10 +35,22 @@
self.credit += last_closing_balance[0].credit
-def make_closing_entries(closing_entries):
+def make_closing_entries(
+ closing_entries, is_period_closing_voucher_entry=False, voucher_name=None
+):
accounting_dimensions = get_accounting_dimensions()
for entry in closing_entries:
cle = frappe.new_doc("Closing Balance")
cle.update(entry)
+
+ if is_period_closing_voucher_entry:
+ cle.update(
+ {
+ "closing_date": entry.get("posting_date"),
+ "is_period_closing_voucher_entry": 1,
+ "period_closing_voucher": voucher_name,
+ }
+ )
+
cle.aggregate_with_last_closing_balance(accounting_dimensions)
cle.submit()
diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
index 5d118bc..57e22a1 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
@@ -92,13 +92,13 @@
gl_entries = self.get_gl_entries()
if gl_entries:
if len(gl_entries) > 5000:
- frappe.enqueue(process_gl_entries, gl_entries=gl_entries, queue="long")
+ frappe.enqueue(process_gl_entries, gl_entries=gl_entries, voucher_name=self.name, queue="long")
frappe.msgprint(
_("The GL Entries will be processed in the background, it can take a few minutes."),
alert=True,
)
else:
- process_gl_entries(gl_entries)
+ process_gl_entries(gl_entries, voucher_name=self.name)
def make_closing_entries(self):
closing_entries = self.get_grouped_gl_entries()
@@ -285,11 +285,13 @@
frappe.log_error(e)
-def process_gl_entries(gl_entries):
+def process_gl_entries(gl_entries, voucher_name=None):
+ from erpnext.accounts.doctype.closing_balance.closing_balance import make_closing_entries
from erpnext.accounts.general_ledger import make_gl_entries
try:
make_gl_entries(gl_entries, merge_entries=False)
+ make_closing_entries(gl_entries, is_period_closing_voucher_entry=True, voucher_name=voucher_name)
frappe.db.set_value(
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "gle_processing_status", "Completed"
)
diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
index e9ed2e4..cc12a55 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
@@ -16,6 +16,7 @@
class TestPeriodClosingVoucher(unittest.TestCase):
def test_closing_entry(self):
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
+ frappe.db.sql("delete from `tabPeriod Closing Voucher` where company='Test PCV Company'")
company = create_company()
cost_center = create_cost_center("Test Cost Center 1")
@@ -65,6 +66,7 @@
def test_cost_center_wise_posting(self):
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
+ frappe.db.sql("delete from `tabPeriod Closing Voucher` where company='Test PCV Company'")
company = create_company()
surplus_account = create_account()
@@ -128,6 +130,7 @@
def test_period_closing_with_finance_book_entries(self):
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
+ frappe.db.sql("delete from `tabPeriod Closing Voucher` where company='Test PCV Company'")
company = create_company()
surplus_account = create_account()