From cfdbeb6a1a6810852b1b517edb261c68cf55d3a4 Mon Sep 17 00:00:00 2001 From: Jatin3128 Date: Mon, 1 Dec 2025 17:33:49 +0530 Subject: [PATCH] feat(accounting-period): add role-based bypass for accounting period restrictions --- .../doctype/accounting_period/accounting_period.json | 11 ++++++++++- .../doctype/accounting_period/accounting_period.py | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_period/accounting_period.json b/erpnext/accounts/doctype/accounting_period/accounting_period.json index 4e7313984b8..2fb69f6b97c 100644 --- a/erpnext/accounts/doctype/accounting_period/accounting_period.json +++ b/erpnext/accounts/doctype/accounting_period/accounting_period.json @@ -12,6 +12,7 @@ "column_break_4", "company", "disabled", + "exempted_role", "section_break_7", "closed_documents" ], @@ -67,10 +68,18 @@ "label": "Closed Documents", "options": "Closed Document", "reqd": 1 + }, + { + "description": "Role allowed to bypass period restrictions.", + "fieldname": "exempted_role", + "fieldtype": "Link", + "label": "Exempted Role", + "link_filters": "[[\"Role\",\"disabled\",\"=\",0]]", + "options": "Role" } ], "links": [], - "modified": "2025-10-06 15:00:15.568067", + "modified": "2025-12-01 16:53:44.631299", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting Period", diff --git a/erpnext/accounts/doctype/accounting_period/accounting_period.py b/erpnext/accounts/doctype/accounting_period/accounting_period.py index b0fccf7c524..c4e51d813b2 100644 --- a/erpnext/accounts/doctype/accounting_period/accounting_period.py +++ b/erpnext/accounts/doctype/accounting_period/accounting_period.py @@ -30,6 +30,7 @@ class AccountingPeriod(Document): company: DF.Link disabled: DF.Check end_date: DF.Date + exempted_role: DF.Link | None period_name: DF.Data start_date: DF.Date # end: auto-generated types @@ -113,7 +114,7 @@ def validate_accounting_period_on_doc_save(doc, method=None): accounting_period = ( frappe.qb.from_(ap) .from_(cd) - .select(ap.name) + .select(ap.name, ap.exempted_role) .where( (ap.name == cd.parent) & (ap.company == doc.company) @@ -126,6 +127,11 @@ def validate_accounting_period_on_doc_save(doc, method=None): ).run(as_dict=1) if accounting_period: + if ( + accounting_period[0].get("exempted_role") + and accounting_period[0].get("exempted_role") in frappe.get_roles() + ): + return frappe.throw( _("You cannot create a {0} within the closed Accounting Period {1}").format( doc.doctype, frappe.bold(accounting_period[0]["name"])