Skip to content

Commit

Permalink
Merge pull request #29 from shariquerik/custom-fields
Browse files Browse the repository at this point in the history
feat: Custom fields
  • Loading branch information
shariquerik authored Nov 22, 2023
2 parents 9deb9af + eae4734 commit b58523a
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 624 deletions.
76 changes: 76 additions & 0 deletions crm/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,79 @@ def get_filterable_fields(doctype: str):
res = []
res.extend(from_doc_fields)
return res

@frappe.whitelist()
def get_doctype_fields(doctype):
not_allowed_fieldtypes = [
"Section Break",
"Column Break",
]

fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]

sections = {}
section_fields = []
last_section = None

for field in fields:
if field.fieldtype == "Tab Break" and last_section:
sections[last_section]["fields"] = section_fields
last_section = None
if field.read_only:
section_fields = []
continue
if field.fieldtype == "Tab Break":
if field.read_only:
section_fields = []
continue
section_fields = []
last_section = field.fieldname
sections[field.fieldname] = {
"label": field.label,
"opened": True,
"fields": [],
}
else:
section_fields.append(get_field_obj(field))

all_fields = []
for section in sections:
all_fields.append(sections[section])

return all_fields

def get_field_obj(field):
obj = {
"label": field.label,
"type": get_type(field),
"name": field.fieldname,
}

obj["placeholder"] = "Add " + field.label.lower() + "..."

if field.fieldtype == "Link":
obj["placeholder"] = "Select " + field.label.lower() + "..."
obj["doctype"] = field.options
elif field.fieldtype == "Select":
obj["options"] = [{"label": option, "value": option} for option in field.options.split("\n")]

if field.read_only:
obj["tooltip"] = "This field is read only and cannot be edited."

return obj

def get_type(field):
if field.fieldtype == "Data" and field.options == "Phone":
return "phone"
elif field.fieldtype == "Data" and field.options == "Email":
return "email"
elif field.fieldtype == "Check":
return "checkbox"
elif field.fieldtype == "Int":
return "number"
elif field.fieldtype in ["Small Text", "Text", "Long Text"]:
return "textarea"
elif field.read_only:
return "read_only"
return field.fieldtype.lower()
45 changes: 28 additions & 17 deletions crm/fcrm/doctype/crm_deal/crm_deal.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"naming_series",
"organization_tab",
"organization",
"website",
"annual_revenue",
"column_break_afce",
"deal_owner",
"close_date",
"status",
"probability",
"next_step",
"section_break_eepu",
"lead",
"column_break_bqvs",
"contacts_tab",
"email",
"mobile_no",
"contacts"
"contacts",
"others_tab",
"naming_series",
"status",
"deal_owner",
"section_break_eepu",
"lead",
"column_break_bqvs"
],
"fields": [
{
Expand All @@ -39,19 +40,17 @@
{
"fetch_from": "organization.annual_revenue",
"fieldname": "annual_revenue",
"fieldtype": "Int",
"label": "Annual Revenue"
},
{
"fieldname": "column_break_afce",
"fieldtype": "Column Break"
"fieldtype": "Currency",
"label": "Amount",
"read_only": 1
},
{
"fetch_from": "organization.website",
"fieldname": "website",
"fieldtype": "Data",
"label": "Website",
"options": "URL"
"options": "URL",
"read_only": 1
},
{
"fieldname": "close_date",
Expand Down Expand Up @@ -92,7 +91,8 @@
{
"fieldname": "contacts_tab",
"fieldtype": "Tab Break",
"label": "Contacts"
"label": "Contacts",
"read_only": 1
},
{
"fieldname": "email",
Expand Down Expand Up @@ -121,11 +121,22 @@
"fieldtype": "Table",
"label": "Contacts",
"options": "CRM Contacts"
},
{
"fieldname": "others_tab",
"fieldtype": "Tab Break",
"label": "Others",
"read_only": 1
},
{
"fieldname": "organization_tab",
"fieldtype": "Tab Break",
"label": "Organization"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-09 19:58:15.620483",
"modified": "2023-11-22 17:52:31.595525",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal",
Expand Down
12 changes: 2 additions & 10 deletions crm/fcrm/doctype/crm_lead/api.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import json

import frappe
from frappe import _
from frappe.desk.form.load import get_docinfo


@frappe.whitelist()
def get_lead(name):
Lead = frappe.qb.DocType("CRM Lead")

query = (
frappe.qb.from_(Lead)
.select("*")
.where(Lead.name == name)
.limit(1)
)
query = frappe.qb.from_(Lead).select("*").where(Lead.name == name).limit(1)

lead = query.run(as_dict=True)
if not len(lead):
frappe.throw(_("Lead not found"), frappe.DoesNotExistError)
lead = lead.pop()

return lead
return lead
80 changes: 31 additions & 49 deletions crm/fcrm/doctype/crm_lead/crm_lead.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,32 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"naming_series",
"details",
"organization",
"website",
"industry",
"job_title",
"source",
"person_tab",
"salutation",
"first_name",
"middle_name",
"last_name",
"column_break_izjs",
"email",
"mobile_no",
"organization_tab",
"section_break_uixv",
"naming_series",
"lead_name",
"middle_name",
"gender",
"image",
"column_break_lcuv",
"lead_owner",
"phone",
"column_break_dbsv",
"status",
"job_title",
"source",
"converted",
"organization_tab",
"section_break_uixv",
"organization",
"lead_owner",
"no_of_employees",
"column_break_dbsv",
"website",
"annual_revenue",
"industry",
"contact_tab",
"section_break_ymew",
"email",
"column_break_sijm",
"mobile_no",
"column_break_sjtw",
"phone"
"image",
"converted"
],
"fields": [
{
Expand Down Expand Up @@ -67,20 +63,12 @@
"fieldtype": "Data",
"label": "Last Name"
},
{
"fieldname": "column_break_lcuv",
"fieldtype": "Column Break"
},
{
"fieldname": "gender",
"fieldtype": "Link",
"label": "Gender",
"options": "Gender"
},
{
"fieldname": "column_break_izjs",
"fieldtype": "Column Break"
},
{
"default": "Open",
"fieldname": "status",
Expand All @@ -91,10 +79,6 @@
"reqd": 1,
"search_index": 1
},
{
"fieldname": "section_break_ymew",
"fieldtype": "Section Break"
},
{
"fieldname": "email",
"fieldtype": "Data",
Expand All @@ -110,20 +94,12 @@
"options": "URL",
"read_only": 1
},
{
"fieldname": "column_break_sijm",
"fieldtype": "Column Break"
},
{
"fieldname": "mobile_no",
"fieldtype": "Data",
"label": "Mobile No",
"options": "Phone"
},
{
"fieldname": "column_break_sjtw",
"fieldtype": "Column Break"
},
{
"fieldname": "phone",
"fieldtype": "Data",
Expand Down Expand Up @@ -192,12 +168,8 @@
{
"fieldname": "organization_tab",
"fieldtype": "Tab Break",
"label": "Organization"
},
{
"fieldname": "contact_tab",
"fieldtype": "Tab Break",
"label": "Contact"
"label": "Others",
"read_only": 1
},
{
"fieldname": "organization",
Expand All @@ -212,12 +184,22 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Converted"
},
{
"fieldname": "person_tab",
"fieldtype": "Tab Break",
"label": "Person"
},
{
"fieldname": "details",
"fieldtype": "Tab Break",
"label": "Details"
}
],
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-13 13:35:35.783003",
"modified": "2023-11-22 13:03:02.261001",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Lead",
Expand Down
Loading

0 comments on commit b58523a

Please sign in to comment.