fix: Ability to disable dimensions
This commit is contained in:
parent
705c03c093
commit
d0a1ed9017
@ -6,5 +6,11 @@ frappe.ui.form.on('Accounting Dimension', {
|
|||||||
document_type: function(frm){
|
document_type: function(frm){
|
||||||
frm.set_value('label', frm.doc.document_type);
|
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) {
|
||||||
|
frm.set_df_property('document_type', 'description', "Document type is already set as dimension");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
"document_type",
|
"document_type",
|
||||||
"label",
|
"label",
|
||||||
"fieldname",
|
"fieldname",
|
||||||
"is_mandatory"
|
"is_mandatory",
|
||||||
|
"disable"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -30,12 +31,19 @@
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"default": "0",
|
||||||
"fieldname": "is_mandatory",
|
"fieldname": "is_mandatory",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Is Mandatory"
|
"label": "Is Mandatory"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "disable",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Disable"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2019-05-16 13:37:04.240148",
|
"modified": "2019-05-17 20:35:31.014495",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Accounting Dimension",
|
"name": "Accounting Dimension",
|
||||||
|
@ -4,19 +4,23 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
import json
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
||||||
from frappe import scrub
|
from frappe import scrub
|
||||||
from frappe.utils import cstr
|
from frappe.utils import cstr
|
||||||
|
from frappe.utils.background_jobs import enqueue
|
||||||
|
|
||||||
class AccountingDimension(Document):
|
class AccountingDimension(Document):
|
||||||
|
def on_update(self):
|
||||||
|
frappe.enqueue(disable_dimension, doc=self)
|
||||||
|
|
||||||
def before_insert(self):
|
def before_insert(self):
|
||||||
self.set_fieldname_and_label()
|
self.set_fieldname_and_label()
|
||||||
self.make_accounting_dimension_in_accounting_doctypes()
|
frappe.enqueue(make_accounting_dimension_in_accounting_doctypes, doc=self)
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_accounting_dimension()
|
frappe.enqueue(delete_accounting_dimension, doc=self)
|
||||||
|
|
||||||
def set_fieldname_and_label(self):
|
def set_fieldname_and_label(self):
|
||||||
if not self.label:
|
if not self.label:
|
||||||
@ -25,14 +29,10 @@ class AccountingDimension(Document):
|
|||||||
if not self.fieldname:
|
if not self.fieldname:
|
||||||
self.fieldname = scrub(self.label)
|
self.fieldname = scrub(self.label)
|
||||||
|
|
||||||
def make_accounting_dimension_in_accounting_doctypes(self):
|
def make_accounting_dimension_in_accounting_doctypes(doc):
|
||||||
|
doclist = get_doclist()
|
||||||
|
|
||||||
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order", "Asset",
|
if doc.is_mandatory:
|
||||||
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Sales Invoice Item", "Purchase Invoice Item", "Sales Order Item",
|
|
||||||
"Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item",
|
|
||||||
"Purchase Order Item"]
|
|
||||||
|
|
||||||
if self.is_mandatory:
|
|
||||||
df.update({
|
df.update({
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
})
|
})
|
||||||
@ -40,16 +40,16 @@ class AccountingDimension(Document):
|
|||||||
for doctype in doclist:
|
for doctype in doclist:
|
||||||
|
|
||||||
df = {
|
df = {
|
||||||
"fieldname": self.fieldname,
|
"fieldname": doc.fieldname,
|
||||||
"label": self.label,
|
"label": doc.label,
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"options": self.document_type,
|
"options": doc.document_type,
|
||||||
"insert_after": "cost_center"
|
"insert_after": "cost_center"
|
||||||
}
|
}
|
||||||
|
|
||||||
if doctype == "Budget":
|
if doctype == "Budget":
|
||||||
df.update({
|
df.update({
|
||||||
"depends_on": "eval:doc.budget_against == '{0}'".format(self.document_type)
|
"depends_on": "eval:doc.budget_against == '{0}'".format(doc.document_type)
|
||||||
})
|
})
|
||||||
|
|
||||||
create_custom_field(doctype, df)
|
create_custom_field(doctype, df)
|
||||||
@ -63,7 +63,7 @@ class AccountingDimension(Document):
|
|||||||
property_setter_doc.fiel_dname = "budget_against"
|
property_setter_doc.fiel_dname = "budget_against"
|
||||||
property_setter_doc.property = "options"
|
property_setter_doc.property = "options"
|
||||||
property_setter_doc.property_type = "Text"
|
property_setter_doc.property_type = "Text"
|
||||||
property_setter_doc.value = property_setter_doc.value + "\n" + self.document_type
|
property_setter_doc.value = property_setter_doc.value + "\n" + doc.document_type
|
||||||
property_setter_doc.save()
|
property_setter_doc.save()
|
||||||
|
|
||||||
frappe.clear_cache(doctype='Budget')
|
frappe.clear_cache(doctype='Budget')
|
||||||
@ -75,40 +75,63 @@ class AccountingDimension(Document):
|
|||||||
"field_name": "budget_against",
|
"field_name": "budget_against",
|
||||||
"property": "options",
|
"property": "options",
|
||||||
"property_type": "Text",
|
"property_type": "Text",
|
||||||
"value": "\nCost Center\nProject\n" + self.document_type
|
"value": "\nCost Center\nProject\n" + doc.document_type
|
||||||
}).insert(ignore_permissions=True)
|
}).insert(ignore_permissions=True)
|
||||||
frappe.clear_cache(doctype=doctype)
|
frappe.clear_cache(doctype=doctype)
|
||||||
else:
|
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(self):
|
def delete_accounting_dimension(doc):
|
||||||
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order", "Asset",
|
doclist = get_doclist()
|
||||||
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note", "Sales Invoice Item", "Purchase Invoice Item", "Sales Order Item",
|
|
||||||
"Purchase Order Item", "Journal Entry Account", "Material Request Item", "Delivery Note Item", "Purchase Receipt Item",
|
|
||||||
"Purchase Order Item"]
|
|
||||||
|
|
||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
DELETE FROM `tabCustom Field`
|
DELETE FROM `tabCustom Field`
|
||||||
WHERE fieldname = %s
|
WHERE fieldname = %s
|
||||||
AND dt IN (%s)""" %
|
AND dt IN (%s)""" %
|
||||||
('%s', ', '.join(['%s']* len(doclist))), tuple([self.fieldname] + doclist))
|
('%s', ', '.join(['%s']* len(doclist))), tuple([doc.fieldname] + doclist))
|
||||||
|
|
||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
DELETE FROM `tabProperty Setter`
|
DELETE FROM `tabProperty Setter`
|
||||||
WHERE field_name = %s
|
WHERE field_name = %s
|
||||||
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([doc.fieldname] + doclist))
|
||||||
|
|
||||||
budget_against_property = frappe.get_doc("Property Setter", "Budget-budget_against-options")
|
budget_against_property = frappe.get_doc("Property Setter", "Budget-budget_against-options")
|
||||||
value_list = budget_against_property.value.split('\n')[3:]
|
value_list = budget_against_property.value.split('\n')[3:]
|
||||||
value_list.remove(self.document_type)
|
value_list.remove(doc.document_type)
|
||||||
|
|
||||||
budget_against_property.value = "\nCost Center\nProject\n" + "\n".join(value_list)
|
budget_against_property.value = "\nCost Center\nProject\n" + "\n".join(value_list)
|
||||||
budget_against_property.save()
|
budget_against_property.save()
|
||||||
|
|
||||||
for doc in doclist:
|
for doctype in doclist:
|
||||||
frappe.clear_cache(doctype=doc)
|
frappe.clear_cache(doctype=doctype)
|
||||||
|
|
||||||
|
def disable_dimension(doc):
|
||||||
|
if doc.disable:
|
||||||
|
df = {"read_only": 1}
|
||||||
|
else:
|
||||||
|
df = {"read_only": 0}
|
||||||
|
|
||||||
|
doclist = get_doclist()
|
||||||
|
|
||||||
|
for doctype in doclist:
|
||||||
|
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": doc.fieldname})
|
||||||
|
if field:
|
||||||
|
custom_field = frappe.get_doc("Custom Field", field)
|
||||||
|
custom_field.update(df)
|
||||||
|
custom_field.save()
|
||||||
|
|
||||||
|
frappe.clear_cache(doctype=doctype)
|
||||||
|
|
||||||
|
def get_doclist():
|
||||||
|
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",
|
||||||
|
"Stock Entry Detail", "Payment Entry Deduction"]
|
||||||
|
|
||||||
|
return doclist
|
||||||
|
|
||||||
|
|
||||||
def get_accounting_dimensions():
|
def get_accounting_dimensions():
|
||||||
accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["fieldname"])
|
accounting_dimensions = frappe.get_all("Accounting Dimension", fields=["fieldname"])
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from frappe import _
|
|
||||||
|
|
||||||
def get_data():
|
|
||||||
return {
|
|
||||||
'transactions': [
|
|
||||||
{
|
|
||||||
'label': _('Accounting Doctypes')
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user