Skip to content

Commit

Permalink
Merge pull request #485 from shariquerik/child-table-support
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik authored Dec 29, 2024
2 parents ff1c373 + a70d875 commit 2be808b
Show file tree
Hide file tree
Showing 20 changed files with 1,128 additions and 242 deletions.
12 changes: 8 additions & 4 deletions crm/api/doc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import frappe
import json

import frappe
from frappe import _
from frappe.model.document import get_controller
from frappe.model import no_value_fields
from pypika import Criterion
from frappe.model.document import get_controller
from frappe.utils import make_filter_tuple
from pypika import Criterion

from crm.api.views import get_views
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
Expand Down Expand Up @@ -557,6 +558,9 @@ def get_fields_meta(doctype, restricted_fieldtypes=None, as_array=False):
fields_meta = {}
for field in fields:
fields_meta[field.get("fieldname")] = field
if field.get("fieldtype") == "Table":
_fields = frappe.get_meta(field.get("options")).fields
fields_meta[field.get("fieldname")] = {"df": field, "fields": _fields}

return fields_meta

Expand Down Expand Up @@ -672,7 +676,7 @@ def get_assigned_users(doctype, name, default_assigned_to=None):

@frappe.whitelist()
def get_fields(doctype: str, allow_all_fieldtypes: bool = False):
not_allowed_fieldtypes = list(frappe.model.no_value_fields) + ["Read Only"]
not_allowed_fieldtypes = [*list(frappe.model.no_value_fields), "Read Only"]
if allow_all_fieldtypes:
not_allowed_fieldtypes = []
fields = frappe.get_meta(doctype).fields
Expand Down
109 changes: 65 additions & 44 deletions crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import json

import frappe
from frappe import _
from frappe.desk.form.assign_to import add as assign
from frappe.model.document import Document

from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
from crm.fcrm.doctype.crm_status_change_log.crm_status_change_log import add_status_change_log
from crm.fcrm.doctype.crm_status_change_log.crm_status_change_log import (
add_status_change_log,
)


class CRMDeal(Document):
Expand Down Expand Up @@ -94,19 +95,26 @@ def share_with_agent(self, agent):
shared_with = [d.user for d in docshares] + [agent]

for user in shared_with:
if user == agent and not frappe.db.exists("DocShare", {"user": agent, "share_name": self.name, "share_doctype": self.doctype}):
if user == agent and not frappe.db.exists(
"DocShare",
{"user": agent, "share_name": self.name, "share_doctype": self.doctype},
):
frappe.share.add_docshare(
self.doctype, self.name, agent, write=1, flags={"ignore_share_permission": True}
self.doctype,
self.name,
agent,
write=1,
flags={"ignore_share_permission": True},
)
elif user != agent:
frappe.share.remove(self.doctype, self.name, user)


def set_sla(self):
"""
Find an SLA to apply to the deal.
"""
if self.sla: return
if self.sla:
return

sla = get_sla(self)
if not sla:
Expand All @@ -129,48 +137,48 @@ def apply_sla(self):
def default_list_data():
columns = [
{
'label': 'Organization',
'type': 'Link',
'key': 'organization',
'options': 'CRM Organization',
'width': '11rem',
"label": "Organization",
"type": "Link",
"key": "organization",
"options": "CRM Organization",
"width": "11rem",
},
{
'label': 'Amount',
'type': 'Currency',
'key': 'annual_revenue',
'align': 'right',
'width': '9rem',
"label": "Annual Revenue",
"type": "Currency",
"key": "annual_revenue",
"align": "right",
"width": "9rem",
},
{
'label': 'Status',
'type': 'Select',
'key': 'status',
'width': '10rem',
"label": "Status",
"type": "Select",
"key": "status",
"width": "10rem",
},
{
'label': 'Email',
'type': 'Data',
'key': 'email',
'width': '12rem',
"label": "Email",
"type": "Data",
"key": "email",
"width": "12rem",
},
{
'label': 'Mobile No',
'type': 'Data',
'key': 'mobile_no',
'width': '11rem',
"label": "Mobile No",
"type": "Data",
"key": "mobile_no",
"width": "11rem",
},
{
'label': 'Assigned To',
'type': 'Text',
'key': '_assign',
'width': '10rem',
"label": "Assigned To",
"type": "Text",
"key": "_assign",
"width": "10rem",
},
{
'label': 'Last Modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
"label": "Last Modified",
"type": "Datetime",
"key": "modified",
"width": "8rem",
},
]
rows = [
Expand All @@ -189,16 +197,17 @@ def default_list_data():
"modified",
"_assign",
]
return {'columns': columns, 'rows': rows}
return {"columns": columns, "rows": rows}

@staticmethod
def default_kanban_settings():
return {
"column_field": "status",
"title_field": "organization",
"kanban_fields": '["annual_revenue", "email", "mobile_no", "_assign", "modified"]'
"kanban_fields": '["annual_revenue", "email", "mobile_no", "_assign", "modified"]',
}


@frappe.whitelist()
def add_contact(deal, contact):
if not frappe.has_permission("CRM Deal", "write", deal):
Expand All @@ -209,6 +218,7 @@ def add_contact(deal, contact):
deal.save()
return True


@frappe.whitelist()
def remove_contact(deal, contact):
if not frappe.has_permission("CRM Deal", "write", deal):
Expand All @@ -219,6 +229,7 @@ def remove_contact(deal, contact):
deal.save()
return True


@frappe.whitelist()
def set_primary_contact(deal, contact):
if not frappe.has_permission("CRM Deal", "write", deal):
Expand All @@ -229,11 +240,14 @@ def set_primary_contact(deal, contact):
deal.save()
return True


def create_organization(doc):
if not doc.get("organization_name"):
return

existing_organization = frappe.db.exists("CRM Organization", {"organization_name": doc.get("organization_name")})
existing_organization = frappe.db.exists(
"CRM Organization", {"organization_name": doc.get("organization_name")}
)
if existing_organization:
return existing_organization

Expand All @@ -250,6 +264,7 @@ def create_organization(doc):
organization.insert(ignore_permissions=True)
return organization.name


def contact_exists(doc):
email_exist = frappe.db.exists("Contact Email", {"email_id": doc.get("email")})
mobile_exist = frappe.db.exists("Contact Phone", {"phone": doc.get("mobile_no")})
Expand All @@ -262,6 +277,7 @@ def contact_exists(doc):

return False


def create_contact(doc):
existing_contact = contact_exists(doc)
if existing_contact:
Expand All @@ -288,18 +304,23 @@ def create_contact(doc):

return contact.name


@frappe.whitelist()
def create_deal(args):
deal = frappe.new_doc("CRM Deal")

contact = args.get("contact")
if not contact and (args.get("first_name") or args.get("last_name") or args.get("email") or args.get("mobile_no")):
if not contact and (
args.get("first_name") or args.get("last_name") or args.get("email") or args.get("mobile_no")
):
contact = create_contact(args)

deal.update({
"organization": args.get("organization") or create_organization(args),
"contacts": [{"contact": contact, "is_primary": 1}] if contact else [],
})
deal.update(
{
"organization": args.get("organization") or create_organization(args),
"contacts": [{"contact": contact, "is_primary": 1}] if contact else [],
}
)

args.pop("organization", None)

Expand Down
4 changes: 2 additions & 2 deletions crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Type",
"options": "Quick Entry\nSide Panel\nData Fields"
"options": "Quick Entry\nSide Panel\nData Fields\nGrid Row"
},
{
"fieldname": "section_break_ttpm",
Expand All @@ -46,7 +46,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-12-05 13:29:37.021412",
"modified": "2024-12-29 12:58:54.280569",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Fields Layout",
Expand Down
Loading

0 comments on commit 2be808b

Please sign in to comment.