refactor: enforce company restrictions on any doctype with a Company link

Replace the manually maintained transaction allowlist with a wildcard
validate hook: any doctype carrying a Company link field is checked, so
new doctypes are covered automatically. System-managed doctypes (ledger
entries, reposts, bundles, bins, POS consolidation, bank feeds) are
exempted so cancel, repost and reconciliation of documents created
before a restriction changed keep working; that guarantee is pinned by
a cancel-after-restriction test.
This commit is contained in:
Mihir Kandoi
2026-07-22 14:36:48 +05:30
parent ce01fa0e34
commit 1982816a70
3 changed files with 53 additions and 42 deletions

View File

@@ -364,44 +364,12 @@ pre_submit_validation_doctypes = [
"Sales Order",
]
company_restricted_transaction_doctypes = [
"Quotation",
"Sales Order",
"Delivery Note",
"Sales Invoice",
"POS Invoice",
"Material Request",
"Request for Quotation",
"Supplier Quotation",
"Purchase Order",
"Purchase Receipt",
"Purchase Invoice",
"Stock Entry",
"Stock Reconciliation",
"Payment Entry",
"Journal Entry",
"Subcontracting Order",
"Subcontracting Receipt",
"BOM",
"Work Order",
"Job Card",
"Production Plan",
"Pick List",
"Blanket Order",
"Asset Capitalization",
"Asset Repair",
"Dunning",
"Installation Note",
"Maintenance Schedule",
"Maintenance Visit",
"Warranty Claim",
]
doc_events = {
"*": {
"validate": [
"erpnext.support.doctype.service_level_agreement.service_level_agreement.apply",
"erpnext.setup.doctype.transaction_deletion_record.transaction_deletion_record.check_for_running_deletion_job",
"erpnext.stock.doctype.company_restriction.company_restriction.validate_transaction_company",
],
},
tuple(period_closing_doctypes): {
@@ -410,9 +378,6 @@ doc_events = {
tuple(pre_submit_validation_doctypes): {
"validate": "erpnext.accounts.utils.pre_submit_validation",
},
tuple(company_restricted_transaction_doctypes): {
"validate": "erpnext.stock.doctype.company_restriction.company_restriction.validate_transaction_company",
},
("Item", "Customer", "Supplier"): {
"validate": "erpnext.stock.doctype.company_restriction.company_restriction.validate_allowed_companies",
},