Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom dropdown items #489

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
94 changes: 94 additions & 0 deletions crm/fcrm/doctype/crm_dropdown_item/crm_dropdown_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2024-12-27 17:42:33.089685",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"name1",
"label",
"type",
"route",
"open_in_new_window",
"hidden",
"is_standard",
"column_break_mvbq",
"icon"
],
"fields": [
{
"fieldname": "label",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Label",
"mandatory_depends_on": "eval:doc.type == 'Route'"
},
{
"fieldname": "type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Type",
"options": "Route\nSeparator",
"read_only_depends_on": "eval:doc.is_standard"
},
{
"depends_on": "eval:doc.type == 'Route'",
"fieldname": "route",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Route",
"mandatory_depends_on": "eval:doc.type == 'Route'"
},
{
"default": "0",
"fieldname": "hidden",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Hidden"
},
{
"default": "0",
"fieldname": "is_standard",
"fieldtype": "Check",
"label": "Is Standard",
"read_only": 1
},
{
"fieldname": "column_break_mvbq",
"fieldtype": "Column Break"
},
{
"description": "Add svg code or use feather icons e.g 'settings'",
"fieldname": "icon",
"fieldtype": "Code",
"label": "Icon"
},
{
"default": "1",
"depends_on": "eval:doc.type == 'Route'",
"fieldname": "open_in_new_window",
"fieldtype": "Check",
"label": "Open in new window"
},
{
"depends_on": "eval:doc.is_standard",
"fieldname": "name1",
"fieldtype": "Data",
"label": "Name",
"read_only": 1,
"unique": 1
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-12-27 19:35:53.012508",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Dropdown Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_dropdown_item/crm_dropdown_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class CRMDropdownItem(Document):
pass
11 changes: 9 additions & 2 deletions crm/fcrm/doctype/fcrm_settings/fcrm_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"restore_defaults"
"restore_defaults",
"dropdown_items"
],
"fields": [
{
"fieldname": "restore_defaults",
"fieldtype": "Button",
"label": "Restore Defaults"
},
{
"fieldname": "dropdown_items",
"fieldtype": "Table",
"label": "Dropdown Items",
"options": "CRM Dropdown Item"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-09-29 13:49:07.835379",
"modified": "2024-12-27 17:47:29.196692",
"modified_by": "Administrator",
"module": "FCRM",
"name": "FCRM Settings",
Expand Down
26 changes: 26 additions & 0 deletions crm/fcrm/doctype/fcrm_settings/fcrm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@

import frappe
from frappe.model.document import Document

from crm.install import after_install


class FCRMSettings(Document):
@frappe.whitelist()
def restore_defaults(self, force=False):
after_install(force)


def after_migrate():
sync_table("dropdown_items", "standard_dropdown_items")


def sync_table(key, hook):
crm_settings = FCRMSettings("FCRM Settings")
existing_items = {d.name1: d for d in crm_settings.get(key)}
new_standard_items = {}

# add new items
count = 0 # maintain count because list may come from seperate apps
for item in frappe.get_hooks(hook):
if item.get("name1") not in existing_items:
crm_settings.append(key, item, count)
new_standard_items[item.get("name1")] = True
count += 1

# remove unused items
items = crm_settings.get(key)
items = [item for item in items if not (item.is_standard and (item.name1 not in new_standard_items))]
crm_settings.set(key, items)

crm_settings.save()
146 changes: 103 additions & 43 deletions crm/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

# website user home page (by Role)
# role_home_page = {
# "Role": "home_page"
# "Role": "home_page"
# }

website_route_rules = [
Expand All @@ -75,8 +75,8 @@

# add methods and filters to jinja environment
# jinja = {
# "methods": "crm.utils.jinja_methods",
# "filters": "crm.utils.jinja_filters"
# "methods": "crm.utils.jinja_methods",
# "filters": "crm.utils.jinja_filters"
# }

# Installation
Expand Down Expand Up @@ -118,11 +118,11 @@
# Permissions evaluated in scripted ways

# permission_query_conditions = {
# "Event": "frappe.desk.doctype.event.event.get_permission_query_conditions",
# "Event": "frappe.desk.doctype.event.event.get_permission_query_conditions",
# }
#
# has_permission = {
# "Event": "frappe.desk.doctype.event.event.has_permission",
# "Event": "frappe.desk.doctype.event.event.has_permission",
# }

# DocType Class
Expand Down Expand Up @@ -155,32 +155,34 @@
"on_update": ["crm.api.whatsapp.on_update"],
},
"CRM Deal": {
"on_update": ["crm.fcrm.doctype.erpnext_crm_settings.erpnext_crm_settings.create_customer_in_erpnext"],
"on_update": [
"crm.fcrm.doctype.erpnext_crm_settings.erpnext_crm_settings.create_customer_in_erpnext"
],
},
"User": {
"before_validate": ["crm.api.demo.validate_user"],
}
},
}

# Scheduled Tasks
# ---------------

# scheduler_events = {
# "all": [
# "crm.tasks.all"
# ],
# "daily": [
# "crm.tasks.daily"
# ],
# "hourly": [
# "crm.tasks.hourly"
# ],
# "weekly": [
# "crm.tasks.weekly"
# ],
# "monthly": [
# "crm.tasks.monthly"
# ],
# "all": [
# "crm.tasks.all"
# ],
# "daily": [
# "crm.tasks.daily"
# ],
# "hourly": [
# "crm.tasks.hourly"
# ],
# "weekly": [
# "crm.tasks.weekly"
# ],
# "monthly": [
# "crm.tasks.monthly"
# ],
# }

# Testing
Expand All @@ -192,14 +194,14 @@
# ------------------------------
#
# override_whitelisted_methods = {
# "frappe.desk.doctype.event.event.get_events": "crm.event.get_events"
# "frappe.desk.doctype.event.event.get_events": "crm.event.get_events"
# }
#
# each overriding function accepts a `data` argument;
# generated from the base implementation of the doctype dashboard,
# along with any modifications made in other Frappe apps
# override_doctype_dashboards = {
# "Task": "crm.task.get_dashboard_data"
# "Task": "crm.task.get_dashboard_data"
# }

# exempt linked doctypes from being automatically cancelled
Expand All @@ -225,29 +227,87 @@
# --------------------

# user_data_fields = [
# {
# "doctype": "{doctype_1}",
# "filter_by": "{filter_by}",
# "redact_fields": ["{field_1}", "{field_2}"],
# "partial": 1,
# },
# {
# "doctype": "{doctype_2}",
# "filter_by": "{filter_by}",
# "partial": 1,
# },
# {
# "doctype": "{doctype_3}",
# "strict": False,
# },
# {
# "doctype": "{doctype_4}"
# }
# {
# "doctype": "{doctype_1}",
# "filter_by": "{filter_by}",
# "redact_fields": ["{field_1}", "{field_2}"],
# "partial": 1,
# },
# {
# "doctype": "{doctype_2}",
# "filter_by": "{filter_by}",
# "partial": 1,
# },
# {
# "doctype": "{doctype_3}",
# "strict": False,
# },
# {
# "doctype": "{doctype_4}"
# }
# ]

# Authentication and authorization
# --------------------------------

# auth_hooks = [
# "crm.auth.validate"
# "crm.auth.validate"
# ]

after_migrate = ["crm.fcrm.doctype.fcrm_settings.fcrm_settings.after_migrate"]

standard_dropdown_items = [
{
"name1": "app_selector",
"label": "Apps",
"type": "Route",
"route": "#",
"is_standard": 1,
},
{
"name1": "support_link",
"label": "Support",
"type": "Route",
"icon": "life-buoy",
"route": "https://t.me/frappecrm",
"is_standard": 1,
},
{
"name1": "docs_link",
"label": "Docs",
"type": "Route",
"icon": "book-open",
"route": "https://docs.frappe.io/crm",
"is_standard": 1,
},
{
"name1": "toggle_theme",
"label": "Toggle theme",
"type": "Route",
"icon": "moon",
"route": "#",
"is_standard": 1,
},
{
"name1": "settings",
"label": "Settings",
"type": "Route",
"icon": "settings",
"route": "#",
"is_standard": 1,
},
{
"name1": "separator",
"label": "",
"type": "Separator",
"is_standard": 1,
},
{
"name1": "logout",
"label": "Log out",
"type": "Route",
"icon": "log-out",
"route": "#",
"is_standard": 1,
},
]
Loading
Loading