fix: accounting period (#18477)
* fix: accounting period
* test: accounting period
* fix: account period creation
* fix: remove status field from accounting period
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index be1448d..5c9e93d 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -10,11 +10,13 @@
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_accounting_dimensions
+class ClosedAccountingPeriod(frappe.ValidationError): pass
class StockAccountInvalidTransaction(frappe.ValidationError): pass
def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes', from_repost=False):
if gl_map:
if not cancel:
+ validate_accounting_period(gl_map)
gl_map = process_gl_map(gl_map, merge_entries)
if gl_map and len(gl_map) > 1:
save_entries(gl_map, adv_adj, update_outstanding, from_repost)
@@ -23,6 +25,27 @@
else:
delete_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
+def validate_accounting_period(gl_map):
+ accounting_periods = frappe.db.sql(""" SELECT
+ ap.name as name
+ FROM
+ `tabAccounting Period` ap, `tabClosed Document` cd
+ WHERE
+ ap.name = cd.parent
+ AND ap.company = %(company)s
+ AND cd.closed = 1
+ AND cd.document_type = %(voucher_type)s
+ AND %(date)s between ap.start_date and ap.end_date
+ """, {
+ 'date': gl_map[0].posting_date,
+ 'company': gl_map[0].company,
+ 'voucher_type': gl_map[0].voucher_type
+ }, as_dict=1)
+
+ if accounting_periods:
+ frappe.throw(_("You can't create accounting entries in the closed accounting period {0}")
+ .format(accounting_periods[0].name), ClosedAccountingPeriod)
+
def process_gl_map(gl_map, merge_entries=True):
if merge_entries:
gl_map = merge_similar_entries(gl_map)