feat: Ability to add custom dimensions
This commit is contained in:
parent
78827d8d79
commit
b4ad5c0158
0
erpnext/accounts/doctype/dimension/__init__.py
Normal file
0
erpnext/accounts/doctype/dimension/__init__.py
Normal file
8
erpnext/accounts/doctype/dimension/dimension.js
Normal file
8
erpnext/accounts/doctype/dimension/dimension.js
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Dimension', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
48
erpnext/accounts/doctype/dimension/dimension.json
Normal file
48
erpnext/accounts/doctype/dimension/dimension.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"autoname": "field:label",
|
||||
"creation": "2019-05-04 18:13:37.002352",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"label",
|
||||
"fieldname"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Label",
|
||||
"reqd": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "fieldname",
|
||||
"fieldtype": "Data",
|
||||
"label": "Fieldname"
|
||||
}
|
||||
],
|
||||
"modified": "2019-05-04 18:59:14.969008",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Dimension",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "ASC",
|
||||
"track_changes": 1
|
||||
}
|
65
erpnext/accounts/doctype/dimension/dimension.py
Normal file
65
erpnext/accounts/doctype/dimension/dimension.py
Normal file
@ -0,0 +1,65 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
|
||||
from frappe import scrub
|
||||
|
||||
class Dimension(Document):
|
||||
|
||||
def before_insert(self):
|
||||
self.set_fieldname()
|
||||
self.make_dimension_in_accounting_doctypes()
|
||||
|
||||
def on_trash(self):
|
||||
self.delete_dimension()
|
||||
|
||||
def set_fieldname(self):
|
||||
if not self.fieldname:
|
||||
self.fieldname = scrub(self.label)
|
||||
|
||||
def make_dimension_in_accounting_doctypes(self):
|
||||
last_created_dimension = get_last_created_dimension()
|
||||
|
||||
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order",
|
||||
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note"]
|
||||
|
||||
df = {
|
||||
"fieldname": self.fieldname,
|
||||
"label": self.label,
|
||||
"fieldtype": "Data",
|
||||
"insert_after": last_created_dimension if last_created_dimension else "project"
|
||||
}
|
||||
|
||||
for doctype in doclist:
|
||||
create_custom_field(doctype, df)
|
||||
|
||||
def delete_dimension(self):
|
||||
doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order",
|
||||
"Stock Entry", "Budget", "Payroll Entry", "Delivery Note"]
|
||||
|
||||
frappe.db.sql("""
|
||||
DELETE FROM `tabCustom Field`
|
||||
WHERE fieldname = %s
|
||||
AND dt IN (%s)""" %
|
||||
('%s', ', '.join(['%s']* len(doclist))), tuple([self.fieldname] + doclist))
|
||||
|
||||
frappe.db.sql("""
|
||||
DELETE FROM `tabProperty Setter`
|
||||
WHERE field_name = %s
|
||||
AND doc_type IN (%s)""" %
|
||||
('%s', ', '.join(['%s']* len(doclist))), tuple([self.fieldname] + doclist))
|
||||
|
||||
for doc in doclist:
|
||||
frappe.clear_cache(doctype=doc)
|
||||
|
||||
|
||||
def get_last_created_dimension():
|
||||
last_created_dimension = frappe.db.sql("select fieldname, max(creation) from `tabDimension`", as_dict=1)
|
||||
|
||||
if last_created_dimension[0]:
|
||||
return last_created_dimension[0].fieldname
|
10
erpnext/accounts/doctype/dimension/test_dimension.py
Normal file
10
erpnext/accounts/doctype/dimension/test_dimension.py
Normal file
@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
|
||||
class TestDimension(unittest.TestCase):
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user