diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js index 4f4876a6dc..1f83d9a052 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.js @@ -13,7 +13,7 @@ frappe.ui.form.on('Accounting Dimension', { document_type: function(frm) { frm.set_value('label', frm.doc.document_type); - frm.set_value('fieldname', frappe.scrub(frm.doc.document_type)) + frm.set_value('fieldname', frappe.scrub(frm.doc.document_type)); frappe.db.get_value('Accounting Dimension', {'document_type': frm.doc.document_type}, 'document_type', (r) => { if (r.document_type) { @@ -29,7 +29,7 @@ frappe.ui.form.on('Accounting Dimension', { doc: frm.doc }, callback: function() { - frappe.msgprint(_("{0} dimension disabled", [frm.doc.label])); + 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 47bdc943a4..18d61f9634 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -71,22 +71,10 @@ def make_dimension_in_accounting_doctypes(doc): "property_type": "Text", "value": "\nCost Center\nProject\n" + doc.document_type }).insert(ignore_permissions=True) - frappe.clear_cache(doctype=doctype) else: - if frappe.db.has_column(doctype, doc.fieldname) and (doc.mandatory_for_pl or doc.mandatory_for_bs): - frappe.get_doc({ - "doctype": "Property Setter", - "doctype_or_field": "DocField", - "doc_type": doctype, - "field_name": doc.fieldname, - "property": "hidden", - "property_type": "Check", - "value": 0 - }).insert(ignore_permissions=True) - else: - create_custom_field(doctype, df) + create_custom_field(doctype, df) - frappe.clear_cache(doctype=doctype) + frappe.clear_cache(doctype=doctype) def delete_accounting_dimension(doc): doclist = get_doclist() @@ -94,13 +82,13 @@ def delete_accounting_dimension(doc): frappe.db.sql(""" DELETE FROM `tabCustom Field` WHERE fieldname = %s - AND dt IN (%s)""" % + AND dt IN (%s)""" % #nosec ('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist)) frappe.db.sql(""" DELETE FROM `tabProperty Setter` WHERE field_name = %s - AND doc_type IN (%s)""" % + AND doc_type IN (%s)""" % #nosec ('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist)) budget_against_property = frappe.get_doc("Property Setter", "Budget-budget_against-options") diff --git a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py index b608685351..8cf2151079 100644 --- a/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/test_accounting_dimension.py @@ -7,6 +7,7 @@ import frappe import unittest from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry +from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import delete_accounting_dimension class TestAccountingDimension(unittest.TestCase): def setUp(self): @@ -17,18 +18,27 @@ class TestAccountingDimension(unittest.TestCase): "doctype": "Accounting Dimension", "document_type": "Department", }).insert() + else: + dimension1 = frappe.get_doc("Accounting Dimension", "Department") + dimension1.disabled = 0 + dimension1.save() + if not frappe.db.exists("Accounting Dimension", {"document_type": "Location"}): dimension1 = frappe.get_doc({ "doctype": "Accounting Dimension", "document_type": "Location", "mandatory_for_pl": 1 }).insert() - - def tearDown(self): - delete_dimension() + else: + dimension1 = frappe.get_doc("Accounting Dimension", "Location") + dimension1.disabled = 0 + dimension1.mandatory_for_pl = 1 + dimension1.save() def test_dimension_against_sales_invoice(self): si = create_sales_invoice(do_not_save=1) + + si.location = "Block 1" si.append("items", { "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC", @@ -37,7 +47,8 @@ class TestAccountingDimension(unittest.TestCase): "income_account": "Sales - _TC", "expense_account": "Cost of Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", - "department": "_Test Department - _TC" + "department": "_Test Department - _TC", + "location": "Block 1" }) si.save() @@ -52,6 +63,9 @@ class TestAccountingDimension(unittest.TestCase): je.accounts[0].update({"department": "_Test Department - _TC"}) je.accounts[1].update({"department": "_Test Department - _TC"}) + je.accounts[0].update({"location": "Block 1"}) + je.accounts[1].update({"location": "Block 1"}) + je.save() je.submit() @@ -74,10 +88,20 @@ class TestAccountingDimension(unittest.TestCase): }) si.save() - self.assertRaises(frappe.ValidationError, si.submit()) + self.assertRaises(frappe.ValidationError, si.submit) + + def tearDown(self): + disable_dimension() -def delete_dimension(): - dimension1 = frappe.delete_doc("Accounting Diemnsion", "Department") - dimension2 = frappe.delete_doc("Accounting Diemnsion", "Location") +def disable_dimension(): + dimension1 = frappe.get_doc("Accounting Dimension", "Department") + dimension1.disabled = 1 + dimension1.save() + + dimension2 = frappe.get_doc("Accounting Dimension", "Location") + dimension2.mandatory_for_pl = 0 + dimension2.disabled = 1 + dimension2.save() + diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 9be61b7b11..4d87edf375 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -468,7 +468,7 @@ class PurchaseInvoice(BuyingController): "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(item.landed_cost_voucher_amount), "project": item.project - }), item=item) + }, item=item)) # sub-contracting warehouse if flt(item.rm_supp_cost): diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py index c68a2ddfae..4511ace225 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py @@ -96,7 +96,7 @@ def get_cost_centers(filters): return frappe.db.sql_list("""select name from `tab{tab}` where company=%s {cond}""".format(tab=filters.get("budget_against"), cond=cond), filters.get("company")) else: - return frappe.db.sql_list("""select name from `tab{tab}`""".format(tab=filters.get("budget_against"))) + return frappe.db.sql_list("""select name from `tab{tab}`""".format(tab=filters.get("budget_against"))) #nosec #Get cost center & target details def get_cost_center_target_details(filters): diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 7f0cbaa263..41205ae2b0 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -365,7 +365,7 @@ def set_gl_entries_by_account( where company=%(company)s {additional_conditions} and posting_date <= %(to_date)s - order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) + order by account, posting_date""".format(additional_conditions=additional_conditions), gl_filters, as_dict=True) #nosec if filters and filters.get('presentation_currency'): convert_to_presentation_currency(gl_entries, get_currency(filters)) diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index e1ce9bccea..73e04c0ff0 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -150,7 +150,7 @@ function get_filters(){ } ] - let dimension_filters = erpnext.get_dimension_filters() + let dimension_filters = erpnext.get_dimension_filters(); dimension_filters.then((dimensions) => { dimensions.forEach((dimension) => { diff --git a/erpnext/public/js/utils/dimension_tree_filter.js b/erpnext/public/js/utils/dimension_tree_filter.js index 68c3d5b98d..79c0ab0565 100644 --- a/erpnext/public/js/utils/dimension_tree_filter.js +++ b/erpnext/public/js/utils/dimension_tree_filter.js @@ -5,9 +5,9 @@ let doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "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"] + "Travel Request", "Fees", "POS Profile"]; -let dimension_filters = erpnext.get_dimension_filters() +let dimension_filters = erpnext.get_dimension_filters(); doclist.forEach((doctype) => { frappe.ui.form.on(doctype, {