From 073f36b76689a9ff0436abc2b42575ca9b770177 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Wed, 15 May 2019 12:20:37 +0530 Subject: [PATCH] fix: Create property setter for budget if dimension is created --- .../accounting_dimension.py | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index e56492c18d..ab66fe3b3d 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -13,6 +13,8 @@ class AccountingDimension(Document): def before_insert(self): self.set_fieldname_and_label() + + def after_insert(self): self.make_accounting_dimension_in_accounting_doctypes() def on_trash(self): @@ -51,12 +53,26 @@ class AccountingDimension(Document): 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.doc_type = 'Budget' + property_setter_doc.doctype_or_field = "DocField" + property_setter_doc.fiel_dname = "budget_against" + property_setter_doc.property = "options" + property_setter_doc.property_type = "Text" + property_setter_doc.value = property_setter_doc.value + "\n" + self.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", - "fieldname": "budget_against" - }) + "field_name": "budget_against", + "property": "options", + "property_type": "Text", + "value": "\nCost Center\nProject\n" + self.document_type + }).insert(ignore_permissions=True) else: create_custom_field(doctype, df) @@ -76,10 +92,15 @@ class AccountingDimension(Document): AND doc_type IN (%s)""" % ('%s', ', '.join(['%s']* len(doclist))), tuple([self.fieldname] + doclist)) + # budget_against_property = frappe.get_doc("Property Setter", "Budget-budget_against-options") + # value_list = budget_against_property.value.split('\n')[3:] + # value_list.remove(self.document_type) + + # budget_against_property.value = "\nCost Center\nProject\n" + "\n".join(value_list) + for doc in doclist: frappe.clear_cache(doctype=doc) - def get_last_created_accounting_dimension(): last_created_accounting_dimension = frappe.db.sql("select fieldname, max(creation) from `tabAccounting Dimension`", as_dict=1)