fix: Multiple fixes in accounting dimensions
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
index 1f83d9a..fcbd10f 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js
@@ -27,9 +27,6 @@
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.disable_dimension",
args: {
doc: frm.doc
- },
- callback: function() {
- frappe.msgprint(__("{0} dimension disabled", [frm.doc.label]));
}
});
}
diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
index a14f714..1d97005 100644
--- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
+++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
+from frappe import _
import json
from frappe.model.document import Document
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
@@ -33,8 +34,9 @@
self.fieldname = scrub(self.label)
def make_dimension_in_accounting_doctypes(doc):
- doclist = get_doclist()
+ doclist = get_doctypes_with_dimensions()
doc_count = len(get_accounting_dimensions())
+ count = 0
for doctype in doclist:
@@ -52,38 +54,45 @@
}
if doctype == "Budget":
- df.update({
- "insert_after": "cost_center",
- "depends_on": "eval:doc.budget_against == '{0}'".format(doc.document_type)
- })
-
- create_custom_field(doctype, df)
-
- property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options")
-
- if property_setter:
- property_setter_doc = frappe.get_doc("Property Setter", "Budget-budget_against-options")
- property_setter_doc.value = property_setter_doc.value + "\n" + doc.document_type
- property_setter_doc.save()
-
- frappe.clear_cache(doctype='Budget')
- else:
- frappe.get_doc({
- "doctype": "Property Setter",
- "doctype_or_field": "DocField",
- "doc_type": "Budget",
- "field_name": "budget_against",
- "property": "options",
- "property_type": "Text",
- "value": "\nCost Center\nProject\n" + doc.document_type
- }).insert(ignore_permissions=True)
+ add_dimensions_to_budget_doctype(df, doc)
else:
create_custom_field(doctype, df)
+ count += 1
+
+ frappe.publish_progress(count*100/len(doclist), title = _("Creating Dimensions..."))
frappe.clear_cache(doctype=doctype)
+def add_dimension_to_budget_doctype(df, doc):
+ df.update({
+ "insert_after": "cost_center",
+ "depends_on": "eval:doc.budget_against == '{0}'".format(doc.document_type)
+ })
+
+ create_custom_field("Budget", df)
+
+ property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options")
+
+ if property_setter:
+ property_setter_doc = frappe.get_doc("Property Setter", "Budget-budget_against-options")
+ property_setter_doc.value = property_setter_doc.value + "\n" + doc.document_type
+ property_setter_doc.save()
+
+ frappe.clear_cache(doctype='Budget')
+ else:
+ frappe.get_doc({
+ "doctype": "Property Setter",
+ "doctype_or_field": "DocField",
+ "doc_type": "Budget",
+ "field_name": "budget_against",
+ "property": "options",
+ "property_type": "Text",
+ "value": "\nCost Center\nProject\n" + doc.document_type
+ }).insert(ignore_permissions=True)
+
+
def delete_accounting_dimension(doc):
- doclist = get_doclist()
+ doclist = get_doctypes_with_dimensions()
frappe.db.sql("""
DELETE FROM `tabCustom Field`
@@ -122,7 +131,7 @@
else:
df = {"read_only": 0}
- doclist = get_doclist()
+ doclist = get_doctypes_with_dimensions()
for doctype in doclist:
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": doc.get('fieldname')})
@@ -133,7 +142,7 @@
frappe.clear_cache(doctype=doctype)
-def get_doclist():
+def get_doctypes_with_dimensions():
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
"Expense Claim", "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",
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index cd4f794..4c617c7 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -84,15 +84,17 @@
def validate_dimensions_for_pl_and_bs(self):
+ account_type = frappe.db.get_value("Account", self.account, "report_type")
+
for dimension in get_accounting_dimensions(as_list=False):
- if frappe.db.get_value("Account", self.account, "report_type") == "Profit and Loss" \
+ if account_type == "Profit and Loss" \
and dimension.mandatory_for_pl and not dimension.disabled:
if not self.get(dimension.fieldname):
frappe.throw(_("{0} is required for 'Profit and Loss' account {1}.")
.format(dimension.label, self.account))
- if frappe.db.get_value("Account", self.account, "report_type") == "Balance Sheet" \
+ if account_type == "Balance Sheet" \
and dimension.mandatory_for_bs and not dimension.disabled:
if not self.get(dimension.fieldname):
frappe.throw(_("{0} is required for 'Balance Sheet' account {1}.")
diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js
index 827095a..16c1d4d 100644
--- a/erpnext/public/js/utils/dimension_tree_filter.js
+++ b/erpnext/public/js/utils/dimension_tree_filter.js
@@ -1,6 +1,6 @@
frappe.provide('frappe.ui.form');
-let doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
+erpnext.doctypes_with_dimensions = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "Asset",
"Expense Claim", "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",
@@ -9,7 +9,7 @@
let dimension_filters = erpnext.get_dimension_filters();
-doclist.forEach((doctype) => {
+erpnext.doctypes_with_dimensions.forEach((doctype) => {
frappe.ui.form.on(doctype, {
onload: function(frm) {
dimension_filters.then((dimensions) => {