feat(doctype link): add links to doctype for link dashboard

This commit is contained in:
Rushabh Mehta 2019-09-24 12:50:51 +05:30
parent 34b4b069ba
commit 3e4e6d4b3f
14 changed files with 191 additions and 25 deletions

View file

@ -1,4 +1,5 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "Prompt",
"creation": "2013-02-18 13:36:19",
@ -59,6 +60,8 @@
"in_create",
"actions_section",
"actions",
"links_section",
"links",
"web_view",
"has_web_view",
"allow_guest_to_view",
@ -467,11 +470,22 @@
"fieldtype": "Table",
"label": "Actions",
"options": "DocType Action"
},
{
"fieldname": "links_section",
"fieldtype": "Section Break",
"label": "Links Section"
},
{
"fieldname": "links",
"fieldtype": "Table",
"label": "Links",
"options": "DocType Link"
}
],
"icon": "fa fa-bolt",
"idx": 6,
"modified": "2019-09-23 16:29:21.209832",
"modified": "2019-09-24 11:42:18.081499",
"modified_by": "Administrator",
"module": "Core",
"name": "DocType",

View file

@ -0,0 +1,46 @@
{
"actions": [],
"creation": "2019-09-24 11:41:25.291377",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"link_doctype",
"link_fieldname",
"group"
],
"fields": [
{
"fieldname": "link_doctype",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Link DocType",
"options": "DocType",
"reqd": 1
},
{
"fieldname": "link_fieldname",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Link Fieldname",
"reqd": 1
},
{
"fieldname": "group",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Group"
}
],
"istable": 1,
"modified": "2019-09-24 11:41:25.291377",
"modified_by": "Administrator",
"module": "Core",
"name": "DocType Link",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View file

@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document
class DocTypeLink(Document):
pass

View file

@ -2,10 +2,8 @@
"actions": [
{
"action": "frappe.core.doctype.scheduled_job_type.scheduled_job_type.execute_event",
"action_path": "frappe.core.doctype.scheduled_job_type.scheduled_job_type.execute_event",
"action_type": "Server Action",
"label": "Execute",
"method": "frappe.core.doctype.scheduled_job_type.scheduled_job_type.execute_event"
"label": "Execute"
}
],
"creation": "2019-09-23 14:34:09.205368",
@ -68,7 +66,13 @@
}
],
"in_create": 1,
"modified": "2019-09-24 09:11:29.115423",
"links": [
{
"link_doctype": "Scheduled Job Log",
"link_fieldname": "scheduled_job"
}
],
"modified": "2019-09-24 11:45:34.748779",
"modified_by": "Administrator",
"module": "Core",
"name": "Scheduled Job Type",

View file

@ -11,20 +11,6 @@ from datetime import datetime
from croniter import croniter
from frappe.utils.background_jobs import enqueue
CRON_MAP = {
"Yearly": "0 0 1 1 *",
"Annual": "0 0 1 1 *",
"Monthly": "0 0 1 * *",
"Monthly Long": "0 0 1 * *",
"Weekly": "0 0 * * 0",
"Weekly Long": "0 0 * * 0",
"Daily": "0 0 * * *",
"Daily Long": "0 0 * * *",
"Hourly": "0 * * * *",
"Hourly Long": "0 * * * *",
"All": "0/" + str((frappe.get_conf().scheduler_interval or 240) // 60) + " * * * *",
}
class ScheduledJobType(Document):
def autoname(self):
self.name = '.'.join(self.method.split('.')[-2:])
@ -54,6 +40,20 @@ class ScheduledJobType(Document):
return self.last_execution <= (current_time or now_datetime())
def get_next_execution(self):
CRON_MAP = {
"Yearly": "0 0 1 1 *",
"Annual": "0 0 1 1 *",
"Monthly": "0 0 1 * *",
"Monthly Long": "0 0 1 * *",
"Weekly": "0 0 * * 0",
"Weekly Long": "0 0 * * 0",
"Daily": "0 0 * * *",
"Daily Long": "0 0 * * *",
"Hourly": "0 * * * *",
"Hourly Long": "0 * * * *",
"All": "0/" + str((frappe.get_conf().scheduler_interval or 240) // 60) + " * * * *",
}
if not self.cron_format:
self.cron_format = CRON_MAP[self.queue]

View file

@ -109,7 +109,7 @@ CREATE TABLE `tabDocPerm` (
-- Table structure for table `tabDocType Action`
--
| tabDocType Action | CREATE TABLE `tabDocType Action` (
CREATE TABLE `tabDocType Action` (
`name` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
@ -127,7 +127,30 @@ CREATE TABLE `tabDocPerm` (
PRIMARY KEY (`name`),
KEY `parent` (`parent`),
KEY `modified` (`modified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED;
--
-- Table structure for table `tabDocType Action`
--
CREATE TABLE `tabDocType Link` (
`name` varchar(140) COLLATE utf8mb4_unicode_ci NOT NULL,
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
`modified_by` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`owner` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`docstatus` int(1) NOT NULL DEFAULT 0,
`parent` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`parentfield` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`parenttype` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`idx` int(8) NOT NULL DEFAULT 0,
`group` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`link_doctype` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`link_fieldname` varchar(140) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`name`),
KEY `parent` (`parent`),
KEY `modified` (`modified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED;
--
-- Table structure for table `tabDocType`

View file

@ -131,6 +131,32 @@ CREATE TABLE "tabDocType Action" (
create index on "tabDocType Action" ("parent");
--
-- Table structure for table "tabDocType Link"
--
DROP TABLE IF EXISTS "tabDocType Link";
CREATE TABLE "tabDocType Link" (
"name" varchar(255) NOT NULL,
"creation" timestamp(6) DEFAULT NULL,
"modified" timestamp(6) DEFAULT NULL,
"modified_by" varchar(255) DEFAULT NULL,
"owner" varchar(255) DEFAULT NULL,
"docstatus" smallint NOT NULL DEFAULT 0,
"parent" varchar(255) DEFAULT NULL,
"parentfield" varchar(255) DEFAULT NULL,
"parenttype" varchar(255) DEFAULT NULL,
"idx" bigint NOT NULL DEFAULT 0,
"label" varchar(140) DEFAULT NOT NULL,
"group" varchar(140) DEFAULT NULL,
"link_doctype" varchar(140) DEFAULT NOT NULL,
"link_fieldname" varchar(140) DEFAULT NOT NULL,
PRIMARY KEY ("name")
) ;
create index on "tabDocType Link" ("parent");
--
-- Table structure for table "tabDocType"
--

View file

@ -18,6 +18,7 @@ from frappe.utils.fixtures import sync_fixtures
from frappe.website import render
from frappe.modules.utils import sync_customizations
from frappe.database import setup_database
from frappe.core.doctype.scheduled_job_type.scheduled_job_type import sync_jobs
def install_db(root_login="root", root_password=None, db_name=None, source_sql=None,
admin_password=None, verbose=True, force=0, site_config=None, reinstall=False,
@ -91,6 +92,7 @@ def install_app(name, verbose=False, set_as_patched=True):
for after_install in app_hooks.after_install or []:
frappe.get_attr(after_install)()
sync_jobs()
sync_fixtures(name)
sync_customizations(name)

View file

@ -45,7 +45,7 @@ default_fields = ('doctype','name','owner','creation','modified','modified_by',
'parent','parentfield','parenttype','idx','docstatus')
optional_fields = ("_user_tags", "_comments", "_assign", "_liked_by", "_seen")
table_fields = ('Table', 'Table MultiSelect')
core_doctypes_list = ('DocType', 'DocField', 'DocPerm', 'DocType Action','User', 'Role', 'Has Role',
core_doctypes_list = ('DocType', 'DocField', 'DocPerm', 'DocType Action', 'DocType Link', 'User', 'Role', 'Has Role',
'Page', 'Module Def', 'Print Format', 'Report', 'Customize Form',
'Customize Form Field', 'Property Setter', 'Custom Field', 'Custom Script')

View file

@ -22,7 +22,7 @@ max_positive_value = {
'bigint': 2 ** 63
}
DOCTYPES_FOR_DOCTYPE = ('DocType', 'DocField', 'DocPerm', 'DocType Action')
DOCTYPES_FOR_DOCTYPE = ('DocType', 'DocField', 'DocPerm', 'DocType Action', 'DocType Link')
_classes = {}

View file

@ -165,7 +165,7 @@ class Meta(Document):
def get_valid_columns(self):
if not hasattr(self, "_valid_columns"):
if self.name in ("DocType", "DocField", "DocPerm", 'DocType Action',"Property Setter"):
if self.name in ("DocType", "DocField", "DocPerm", 'DocType Action', 'DocType Link', "Property Setter"):
self._valid_columns = get_table_columns(self.name)
else:
self._valid_columns = self.default_fields + \
@ -174,7 +174,12 @@ class Meta(Document):
return self._valid_columns
def get_table_field_doctype(self, fieldname):
return { "fields": "DocField", "permissions": "DocPerm", "actions": "DocType Action"}.get(fieldname)
return {
"fields": "DocField",
"permissions": "DocPerm",
"actions": "DocType Action",
'links': 'DocType Link'
}.get(fieldname)
def get_field(self, fieldname):
'''Return docfield from meta'''
@ -419,11 +424,44 @@ class Meta(Document):
except ImportError:
pass
self.add_doctype_links(data)
for hook in frappe.get_hooks("override_doctype_dashboards", {}).get(self.name, []):
data = frappe.get_attr(hook)(data=data)
return data
def add_doctype_links(self, data):
'''add `links` child table in standard link dashboard format'''
if self.links:
if not data.transactions:
# init groups
data.transactions = []
data.non_standard_fieldnames = {}
for link in self.links:
link.added = False
for group in data.transactions:
# group found
if group.label == link.label:
if not link.link_doctype in group.items:
group.items.append(link.link_doctype)
link.added = True
if not link.added:
# group not found, make a new group
data.transactions.append(dict(
label = link.group,
items = [link.link_doctype]
))
if link.link_fieldname != data.fieldname:
if data.fieldname:
data.non_standard_fieldnames[link.link_doctype] = link.link_fieldname
else:
data.fieldname = link.link_fieldname
def get_row_template(self):
return self.get_web_template(suffix='_row')
@ -445,6 +483,7 @@ DOCTYPE_TABLE_FIELDS = [
frappe._dict({"fieldname": "fields", "options": "DocField"}),
frappe._dict({"fieldname": "permissions", "options": "DocPerm"}),
frappe._dict({"fieldname": "actions", "options": "DocType Action"}),
frappe._dict({"fieldname": "links", "options": "DocType Link"}),
]
#######

View file

@ -30,6 +30,7 @@ def sync_for(app_name, force=0, sync_everything = False, verbose=False, reset_pe
for d in (("core", "docfield"),
("core", "docperm"),
("core", "doctype_action"),
("core", "doctype_link"),
("core", "role"),
("core", "has_role"),
("core", "doctype"),

View file

@ -10,6 +10,7 @@ frappe.patches.v11_0.drop_column_apply_user_permissions
execute:frappe.reload_doc('core', 'doctype', 'doctype', force=True) #2017-09-22
execute:frappe.reload_doc('core', 'doctype', 'docfield', force=True) #2018-02-20
execute:frappe.reload_doc('core', 'doctype', 'doctype_action', force=True) #2019-09-23
execute:frappe.reload_doc('core', 'doctype', 'doctype_link', force=True) #2019-09-23
execute:frappe.reload_doc('core', 'doctype', 'custom_docperm')
execute:frappe.reload_doc('core', 'doctype', 'docperm') #2018-05-29
execute:frappe.reload_doc('core', 'doctype', 'comment')