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

Data api override #420

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
20 changes: 20 additions & 0 deletions crm/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,26 @@ def get_data(
page_length=page_length,
) or []


# Fetch child table data if requested
include_child_tables = frappe.get_all('Data Doctype', fields=['name'])
include_child_tables_list = [entry['name'] for entry in include_child_tables]

if doctype in include_child_tables_list:
meta = frappe.get_meta(doctype)
child_tables = [df for df in meta.fields if df.fieldtype in ["Table","Table MultiSelect" ] ]

for record in data:
record['child_tables'] = {}
for child_table in child_tables:
child_doctype = child_table.options
child_records = frappe.get_all(
child_doctype,
fields="*",
filters={"parent": record['name']}
)
record['child_tables'][child_table.fieldname] = child_records

if view_type == "kanban":
if not rows:
rows = default_rows
Expand Down
47 changes: 46 additions & 1 deletion crm/fcrm/doctype/crm_deal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ def get_deal(name):
frappe.throw(_("Deal not found"), frappe.DoesNotExistError)
deal = deal.pop()

# Get all child table doctypes linked to CRM Deal
meta = frappe.get_meta("CRM Deal")
child_tables = [df for df in meta.fields if df.fieldtype in ["Table","Table MultiSelect" ] ]

deal['child_tables'] = {}

for child_table in child_tables:
child_doctype = child_table.options
child_records = frappe.get_all(
child_doctype,
fields="*",
filters={"parent": deal['name']}
)
deal['child_tables'][child_table.fieldname] = child_records

deal["contacts"] = frappe.get_all(
"CRM Contacts",
Expand Down Expand Up @@ -63,4 +77,35 @@ def get_primary_mobile_no(contact):
"is_primary": is_primary,
}
deal_contacts.append(_contact)
return deal_contacts
return deal_contacts

@frappe.whitelist(methods=["POST", "PUT"])
def update_crm_deal_elements(name, deal_elements):
# Fetch the CRM Deal by name
deal = frappe.get_doc("CRM Deal", name)

# Clear the existing deal elements
deal.set("deal_elements", [])

# Add new deal elements from the list of strings
for element in deal_elements:
deal.append("deal_elements", {
"deal_elements": element, # now element is the string itself
"parent": name,
"parentfield": "deal_elements",
"parenttype": "CRM Deal",
"doctype": "CRM Deal Elements"
})

# Save the updated CRM Deal document
deal.save(ignore_permissions=True)
frappe.db.commit()

return {"name":name, "deal_elements":deal.deal_elements}


@frappe.whitelist(methods=["GET"])
def get_deal_elements():
# Fetch all CRM Deal Elements
deal_elements = frappe.get_all("CRM Deal Element", fields=["name"])
return deal_elements
39 changes: 29 additions & 10 deletions crm/fcrm/doctype/crm_deal/crm_deal.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"organization_tab",
"tab_6_tab",
"details_section",
"deal_elements",
"probability",
"close_date",
"naming_series",
"organization",
"column_break_tukx",
"next_step",
"probability",
"column_break_ijan",
"status",
"close_date",
"deal_owner",
"organization_tab",
"organization",
"contacts_tab",
"contacts",
"contact",
Expand Down Expand Up @@ -259,10 +262,6 @@
"fieldtype": "Data",
"label": "Lead Name"
},
{
"fieldname": "column_break_ijan",
"fieldtype": "Column Break"
},
{
"fieldname": "lead_details_tab",
"fieldtype": "Tab Break",
Expand Down Expand Up @@ -334,11 +333,31 @@
"fieldtype": "Link",
"label": "Currency",
"options": "Currency"
},
{
"fieldname": "tab_6_tab",
"fieldtype": "Tab Break",
"label": "Details"
},
{
"fieldname": "details_section",
"fieldtype": "Section Break",
"label": "Details"
},
{
"fieldname": "deal_elements",
"fieldtype": "Table MultiSelect",
"label": "Deal Elements",
"options": "CRM Deal Elements"
},
{
"fieldname": "column_break_tukx",
"fieldtype": "Column Break"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-09-17 18:34:15.873610",
"modified": "2024-10-17 09:18:00.677849",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal",
Expand Down
8 changes: 8 additions & 0 deletions crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def default_list_data():
'options': 'CRM Organization',
'width': '11rem',
},
{
'label': 'Deal Elements',
'type': 'Table MultiSelect',
'key': 'deal_elements',
'options': 'CRM Deal Elements',
'width': '12rem',
},
{
'label': 'Amount',
'type': 'Currency',
Expand Down Expand Up @@ -175,6 +182,7 @@ def default_list_data():
rows = [
"name",
"organization",
"deal_elements",
"annual_revenue",
"status",
"email",
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions crm/fcrm/doctype/crm_deal_element/crm_deal_element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

// frappe.ui.form.on("CRM Deal Element", {
// refresh(frm) {

// },
// });
81 changes: 81 additions & 0 deletions crm/fcrm/doctype/crm_deal_element/crm_deal_element.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:element",
"creation": "2024-10-13 07:26:41.773925",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"element",
"description"
],
"fields": [
{
"allow_in_quick_entry": 1,
"fieldname": "element",
"fieldtype": "Data",
"in_filter": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Element",
"unique": 1
},
{
"allow_in_quick_entry": 1,
"fieldname": "description",
"fieldtype": "Data",
"in_filter": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Description"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-10-17 09:22:09.844125",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal Element",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Sales Manager",
"share": 1,
"write": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Sales User",
"share": 1,
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_deal_element/crm_deal_element.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 CRMDealElement(Document):
pass
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_deal_element/test_crm_deal_element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

# import frappe
from frappe.tests.utils import FrappeTestCase


class TestCRMDealElement(FrappeTestCase):
pass
Empty file.
34 changes: 34 additions & 0 deletions crm/fcrm/doctype/crm_deal_elements/crm_deal_elements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2024-10-13 13:06:22.305044",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"deal_elements"
],
"fields": [
{
"fieldname": "deal_elements",
"fieldtype": "Link",
"in_filter": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Deal Elements",
"options": "CRM Deal Element"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-10-17 09:22:29.942549",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal Elements",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_deal_elements/crm_deal_elements.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 CRMDealElements(Document):
pass
8 changes: 8 additions & 0 deletions crm/fcrm/doctype/data_doctype/data_doctype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Data Doctype", {
// refresh(frm) {

// },
// });
46 changes: 46 additions & 0 deletions crm/fcrm/doctype/data_doctype/data_doctype.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:data_doctype",
"creation": "2024-10-18 05:14:39.520861",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"data_doctype"
],
"fields": [
{
"fieldname": "data_doctype",
"fieldtype": "Link",
"label": "Data Doctype",
"link_filters": "[[\"DocType\",\"istable\",\"=\",0],[\"DocType\",\"issingle\",\"=\",0]]",
"options": "DocType",
"unique": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-10-18 05:16:12.696953",
"modified_by": "Administrator",
"module": "FCRM",
"name": "Data Doctype",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Loading