mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 21:19:19 +00:00
Merge pull request #51107 from frappe/mergify/bp/version-16-beta/pr-50837
feat(accounting-period): add role-based bypass for accounting period restrictions (backport #50837)
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
"column_break_4",
|
"column_break_4",
|
||||||
"company",
|
"company",
|
||||||
"disabled",
|
"disabled",
|
||||||
|
"exempted_role",
|
||||||
"section_break_7",
|
"section_break_7",
|
||||||
"closed_documents"
|
"closed_documents"
|
||||||
],
|
],
|
||||||
@@ -67,10 +68,18 @@
|
|||||||
"label": "Closed Documents",
|
"label": "Closed Documents",
|
||||||
"options": "Closed Document",
|
"options": "Closed Document",
|
||||||
"reqd": 1
|
"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": [],
|
"links": [],
|
||||||
"modified": "2025-10-06 15:00:15.568067",
|
"modified": "2025-12-01 16:53:44.631299",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Accounting Period",
|
"name": "Accounting Period",
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class AccountingPeriod(Document):
|
|||||||
company: DF.Link
|
company: DF.Link
|
||||||
disabled: DF.Check
|
disabled: DF.Check
|
||||||
end_date: DF.Date
|
end_date: DF.Date
|
||||||
|
exempted_role: DF.Link | None
|
||||||
period_name: DF.Data
|
period_name: DF.Data
|
||||||
start_date: DF.Date
|
start_date: DF.Date
|
||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
@@ -113,7 +114,7 @@ def validate_accounting_period_on_doc_save(doc, method=None):
|
|||||||
accounting_period = (
|
accounting_period = (
|
||||||
frappe.qb.from_(ap)
|
frappe.qb.from_(ap)
|
||||||
.from_(cd)
|
.from_(cd)
|
||||||
.select(ap.name)
|
.select(ap.name, ap.exempted_role)
|
||||||
.where(
|
.where(
|
||||||
(ap.name == cd.parent)
|
(ap.name == cd.parent)
|
||||||
& (ap.company == doc.company)
|
& (ap.company == doc.company)
|
||||||
@@ -126,6 +127,11 @@ def validate_accounting_period_on_doc_save(doc, method=None):
|
|||||||
).run(as_dict=1)
|
).run(as_dict=1)
|
||||||
|
|
||||||
if accounting_period:
|
if accounting_period:
|
||||||
|
if (
|
||||||
|
accounting_period[0].get("exempted_role")
|
||||||
|
and accounting_period[0].get("exempted_role") in frappe.get_roles()
|
||||||
|
):
|
||||||
|
return
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("You cannot create a {0} within the closed Accounting Period {1}").format(
|
_("You cannot create a {0} within the closed Accounting Period {1}").format(
|
||||||
doc.doctype, frappe.bold(accounting_period[0]["name"])
|
doc.doctype, frappe.bold(accounting_period[0]["name"])
|
||||||
|
|||||||
Reference in New Issue
Block a user