From 7aef9f3b43cf64a5b214ac4f5f0accb88b354e46 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Fri, 8 Nov 2019 12:42:38 +0530 Subject: [PATCH] fix: Accounting Dimension custom fields should be admin owned (#19525) * fix: Accounting Dimension custom fileds should be admin owned * fix: Update query * fix: Travis --- .../accounting_dimension.py | 8 +++++++- erpnext/patches.txt | 1 + ...ner_fields_in_acc_dimension_custom_fields.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v12_0/update_owner_fields_in_acc_dimension_custom_fields.py diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index af51fc5d8e..522ed4ffa4 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -24,6 +24,11 @@ class AccountingDimension(Document): msg = _("Not allowed to create accounting dimension for {0}").format(self.document_type) frappe.throw(msg) + exists = frappe.db.get_value("Accounting Dimension", {'document_type': self.document_type}, ['name']) + + if exists and self.is_new(): + frappe.throw("Document Type already used as a dimension") + def after_insert(self): if frappe.flags.in_test: make_dimension_in_accounting_doctypes(doc=self) @@ -60,7 +65,8 @@ def make_dimension_in_accounting_doctypes(doc): "label": doc.label, "fieldtype": "Link", "options": doc.document_type, - "insert_after": insert_after_field + "insert_after": insert_after_field, + "owner": "Administrator" } if doctype == "Budget": diff --git a/erpnext/patches.txt b/erpnext/patches.txt index cc00b7e412..f594f96aea 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -642,3 +642,4 @@ erpnext.patches.v12_0.generate_leave_ledger_entries erpnext.patches.v12_0.set_default_shopify_app_type erpnext.patches.v12_0.replace_accounting_with_accounts_in_home_settings erpnext.patches.v12_0.set_payment_entry_status +erpnext.patches.v12_0.update_owner_fields_in_acc_dimension_custom_fields diff --git a/erpnext/patches/v12_0/update_owner_fields_in_acc_dimension_custom_fields.py b/erpnext/patches/v12_0/update_owner_fields_in_acc_dimension_custom_fields.py new file mode 100644 index 0000000000..e4dcecd9bd --- /dev/null +++ b/erpnext/patches/v12_0/update_owner_fields_in_acc_dimension_custom_fields.py @@ -0,0 +1,17 @@ +from __future__ import unicode_literals +import frappe +from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_doctypes_with_dimensions + +def execute(): + accounting_dimensions = frappe.db.sql("""select fieldname from + `tabAccounting Dimension`""", as_dict=1) + + doclist = get_doctypes_with_dimensions() + + for dimension in accounting_dimensions: + frappe.db.sql(""" + UPDATE `tabCustom Field` + SET owner = 'Administrator' + WHERE fieldname = %s + AND dt IN (%s)""" % #nosec + ('%s', ', '.join(['%s']* len(doclist))), tuple([dimension.fieldname] + doclist)) \ No newline at end of file