feat(Accounting Dimension): other apps may have accounting dimension doctypes
Prior to this change, there was simply a single hardcoded list of doctypes
with accounting dimensions in ERPNext. However, when extending the
capabilities of ERPNext using an add-on app rather than by modifying
ERPNext itself, it may well be necessary to create new doctypes in other
apps that will have accounting dimensions as well.
So, this PR moves the list of doctypes with accounting dimensions into
hooks.py so it can be accumulated from multiple apps. It also allows the
list of doctypes in make_dimension_in_accounting_doctypes be specifiable,
for more convenient use in the after_install hooks of other apps.
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
index f888d9e..ed1a0b6 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
@@ -48,8 +48,9 @@
if not self.fieldname:
self.fieldname = scrub(self.label)
-def make_dimension_in_accounting_doctypes(doc):
- doclist = get_doctypes_with_dimensions()
+def make_dimension_in_accounting_doctypes(doc, doclist=None):
+ if not doclist:
+ doclist = get_doctypes_with_dimensions()
doc_count = len(get_accounting_dimensions())
count = 0
@@ -69,13 +70,12 @@
"owner": "Administrator"
}
- if doctype == "Budget":
- add_dimension_to_budget_doctype(df, doc)
- else:
- meta = frappe.get_meta(doctype, cached=False)
- fieldnames = [d.fieldname for d in meta.get("fields")]
-
- if df['fieldname'] not in fieldnames:
+ meta = frappe.get_meta(doctype, cached=False)
+ fieldnames = [d.fieldname for d in meta.get("fields")]
+ if df['fieldname'] not in fieldnames:
+ if doctype == "Budget":
+ add_dimension_to_budget_doctype(df.copy(), doc)
+ else:
create_custom_field(doctype, df)
count += 1
@@ -165,15 +165,7 @@
frappe.clear_cache(doctype=doctype)
def get_doctypes_with_dimensions():
- doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
- "Expense Claim", "Expense Claim Detail", "Expense Taxes and Charges", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note",
- "Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item",
- "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule",
- "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
- "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription",
- "Subscription Plan"]
-
- return doclist
+ return frappe.get_hooks("accounting_dimension_doctypes")
def get_accounting_dimensions(as_list=True):
accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["label", "fieldname", "disabled", "document_type"])
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 9873456..3ef93fc 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -386,6 +386,15 @@
communication_doctypes = ["Customer", "Supplier"]
+accounting_dimension_doctypes = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
+ "Expense Claim", "Expense Claim Detail", "Expense Taxes and Charges", "Stock Entry", "Budget", "Payroll Entry", "Delivery Note",
+ "Sales Invoice Item", "Purchase Invoice Item", "Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item",
+ "Purchase Receipt Item", "Stock Entry Detail", "Payment Entry Deduction", "Sales Taxes and Charges", "Purchase Taxes and Charges", "Shipping Rule",
+ "Landed Cost Item", "Asset Value Adjustment", "Loyalty Program", "Fee Schedule", "Fee Structure", "Stock Reconciliation",
+ "Travel Request", "Fees", "POS Profile", "Opening Invoice Creation Tool", "Opening Invoice Creation Tool Item", "Subscription",
+ "Subscription Plan"
+]
+
regional_overrides = {
'France': {
'erpnext.tests.test_regional.test_method': 'erpnext.regional.france.utils.test_method'