fix: Create property setter for budget if dimension is created

This commit is contained in:
deepeshgarg007 2019-05-15 12:20:37 +05:30
parent 60f4dd0736
commit 073f36b766

View File

@ -13,6 +13,8 @@ class AccountingDimension(Document):
def before_insert(self): def before_insert(self):
self.set_fieldname_and_label() self.set_fieldname_and_label()
def after_insert(self):
self.make_accounting_dimension_in_accounting_doctypes() self.make_accounting_dimension_in_accounting_doctypes()
def on_trash(self): def on_trash(self):
@ -51,12 +53,26 @@ class AccountingDimension(Document):
property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options") property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options")
if property_setter: 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: else:
frappe.get_doc({ frappe.get_doc({
"doctype": "Property Setter", "doctype": "Property Setter",
"doctype_or_field": "DocField",
"doc_type": "Budget", "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: else:
create_custom_field(doctype, df) create_custom_field(doctype, df)
@ -76,10 +92,15 @@ class AccountingDimension(Document):
AND doc_type IN (%s)""" % AND doc_type IN (%s)""" %
('%s', ', '.join(['%s']* len(doclist))), tuple([self.fieldname] + doclist)) ('%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: for doc in doclist:
frappe.clear_cache(doctype=doc) frappe.clear_cache(doctype=doc)
def get_last_created_accounting_dimension(): def get_last_created_accounting_dimension():
last_created_accounting_dimension = frappe.db.sql("select fieldname, max(creation) from `tabAccounting Dimension`", as_dict=1) last_created_accounting_dimension = frappe.db.sql("select fieldname, max(creation) from `tabAccounting Dimension`", as_dict=1)