fix: get child table meta
This commit is contained in:
parent
1450163379
commit
ed11fb48cb
@ -557,6 +557,9 @@ def get_fields_meta(doctype, restricted_fieldtypes=None, as_array=False):
|
|||||||
fields_meta = {}
|
fields_meta = {}
|
||||||
for field in fields:
|
for field in fields:
|
||||||
fields_meta[field.get("fieldname")] = field
|
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
|
return fields_meta
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
import json
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@ -8,7 +7,9 @@ from frappe.desk.form.assign_to import add as assign
|
|||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
|
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):
|
class CRMDeal(Document):
|
||||||
@ -94,19 +95,26 @@ class CRMDeal(Document):
|
|||||||
shared_with = [d.user for d in docshares] + [agent]
|
shared_with = [d.user for d in docshares] + [agent]
|
||||||
|
|
||||||
for user in shared_with:
|
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(
|
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:
|
elif user != agent:
|
||||||
frappe.share.remove(self.doctype, self.name, user)
|
frappe.share.remove(self.doctype, self.name, user)
|
||||||
|
|
||||||
|
|
||||||
def set_sla(self):
|
def set_sla(self):
|
||||||
"""
|
"""
|
||||||
Find an SLA to apply to the deal.
|
Find an SLA to apply to the deal.
|
||||||
"""
|
"""
|
||||||
if self.sla: return
|
if self.sla:
|
||||||
|
return
|
||||||
|
|
||||||
sla = get_sla(self)
|
sla = get_sla(self)
|
||||||
if not sla:
|
if not sla:
|
||||||
@ -129,48 +137,48 @@ class CRMDeal(Document):
|
|||||||
def default_list_data():
|
def default_list_data():
|
||||||
columns = [
|
columns = [
|
||||||
{
|
{
|
||||||
'label': 'Organization',
|
"label": "Organization",
|
||||||
'type': 'Link',
|
"type": "Link",
|
||||||
'key': 'organization',
|
"key": "organization",
|
||||||
'options': 'CRM Organization',
|
"options": "CRM Organization",
|
||||||
'width': '11rem',
|
"width": "11rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Amount',
|
"label": "Annual Revenue",
|
||||||
'type': 'Currency',
|
"type": "Currency",
|
||||||
'key': 'annual_revenue',
|
"key": "annual_revenue",
|
||||||
'align': 'right',
|
"align": "right",
|
||||||
'width': '9rem',
|
"width": "9rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Status',
|
"label": "Status",
|
||||||
'type': 'Select',
|
"type": "Select",
|
||||||
'key': 'status',
|
"key": "status",
|
||||||
'width': '10rem',
|
"width": "10rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Email',
|
"label": "Email",
|
||||||
'type': 'Data',
|
"type": "Data",
|
||||||
'key': 'email',
|
"key": "email",
|
||||||
'width': '12rem',
|
"width": "12rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Mobile No',
|
"label": "Mobile No",
|
||||||
'type': 'Data',
|
"type": "Data",
|
||||||
'key': 'mobile_no',
|
"key": "mobile_no",
|
||||||
'width': '11rem',
|
"width": "11rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Assigned To',
|
"label": "Assigned To",
|
||||||
'type': 'Text',
|
"type": "Text",
|
||||||
'key': '_assign',
|
"key": "_assign",
|
||||||
'width': '10rem',
|
"width": "10rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Last Modified',
|
"label": "Last Modified",
|
||||||
'type': 'Datetime',
|
"type": "Datetime",
|
||||||
'key': 'modified',
|
"key": "modified",
|
||||||
'width': '8rem',
|
"width": "8rem",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
rows = [
|
rows = [
|
||||||
@ -189,16 +197,17 @@ class CRMDeal(Document):
|
|||||||
"modified",
|
"modified",
|
||||||
"_assign",
|
"_assign",
|
||||||
]
|
]
|
||||||
return {'columns': columns, 'rows': rows}
|
return {"columns": columns, "rows": rows}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_kanban_settings():
|
def default_kanban_settings():
|
||||||
return {
|
return {
|
||||||
"column_field": "status",
|
"column_field": "status",
|
||||||
"title_field": "organization",
|
"title_field": "organization",
|
||||||
"kanban_fields": '["annual_revenue", "email", "mobile_no", "_assign", "modified"]'
|
"kanban_fields": '["annual_revenue", "email", "mobile_no", "_assign", "modified"]',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def add_contact(deal, contact):
|
def add_contact(deal, contact):
|
||||||
if not frappe.has_permission("CRM Deal", "write", deal):
|
if not frappe.has_permission("CRM Deal", "write", deal):
|
||||||
@ -209,6 +218,7 @@ def add_contact(deal, contact):
|
|||||||
deal.save()
|
deal.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def remove_contact(deal, contact):
|
def remove_contact(deal, contact):
|
||||||
if not frappe.has_permission("CRM Deal", "write", deal):
|
if not frappe.has_permission("CRM Deal", "write", deal):
|
||||||
@ -219,6 +229,7 @@ def remove_contact(deal, contact):
|
|||||||
deal.save()
|
deal.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def set_primary_contact(deal, contact):
|
def set_primary_contact(deal, contact):
|
||||||
if not frappe.has_permission("CRM Deal", "write", deal):
|
if not frappe.has_permission("CRM Deal", "write", deal):
|
||||||
@ -229,11 +240,14 @@ def set_primary_contact(deal, contact):
|
|||||||
deal.save()
|
deal.save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def create_organization(doc):
|
def create_organization(doc):
|
||||||
if not doc.get("organization_name"):
|
if not doc.get("organization_name"):
|
||||||
return
|
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:
|
if existing_organization:
|
||||||
return existing_organization
|
return existing_organization
|
||||||
|
|
||||||
@ -250,6 +264,7 @@ def create_organization(doc):
|
|||||||
organization.insert(ignore_permissions=True)
|
organization.insert(ignore_permissions=True)
|
||||||
return organization.name
|
return organization.name
|
||||||
|
|
||||||
|
|
||||||
def contact_exists(doc):
|
def contact_exists(doc):
|
||||||
email_exist = frappe.db.exists("Contact Email", {"email_id": doc.get("email")})
|
email_exist = frappe.db.exists("Contact Email", {"email_id": doc.get("email")})
|
||||||
mobile_exist = frappe.db.exists("Contact Phone", {"phone": doc.get("mobile_no")})
|
mobile_exist = frappe.db.exists("Contact Phone", {"phone": doc.get("mobile_no")})
|
||||||
@ -262,6 +277,7 @@ def contact_exists(doc):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def create_contact(doc):
|
def create_contact(doc):
|
||||||
existing_contact = contact_exists(doc)
|
existing_contact = contact_exists(doc)
|
||||||
if existing_contact:
|
if existing_contact:
|
||||||
@ -288,18 +304,23 @@ def create_contact(doc):
|
|||||||
|
|
||||||
return contact.name
|
return contact.name
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def create_deal(args):
|
def create_deal(args):
|
||||||
deal = frappe.new_doc("CRM Deal")
|
deal = frappe.new_doc("CRM Deal")
|
||||||
|
|
||||||
contact = args.get("contact")
|
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)
|
contact = create_contact(args)
|
||||||
|
|
||||||
deal.update({
|
deal.update(
|
||||||
"organization": args.get("organization") or create_organization(args),
|
{
|
||||||
"contacts": [{"contact": contact, "is_primary": 1}] if contact else [],
|
"organization": args.get("organization") or create_organization(args),
|
||||||
})
|
"contacts": [{"contact": contact, "is_primary": 1}] if contact else [],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
args.pop("organization", None)
|
args.pop("organization", None)
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,16 @@
|
|||||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
import json
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.desk.form.assign_to import add as assign
|
from frappe.desk.form.assign_to import add as assign
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
from frappe.utils import has_gravatar, validate_email_address
|
from frappe.utils import has_gravatar, validate_email_address
|
||||||
|
|
||||||
from crm.fcrm.doctype.crm_service_level_agreement.utils import get_sla
|
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 CRMLead(Document):
|
class CRMLead(Document):
|
||||||
@ -37,7 +38,15 @@ class CRMLead(Document):
|
|||||||
def set_full_name(self):
|
def set_full_name(self):
|
||||||
if self.first_name:
|
if self.first_name:
|
||||||
self.lead_name = " ".join(
|
self.lead_name = " ".join(
|
||||||
filter(None, [self.salutation, self.first_name, self.middle_name, self.last_name])
|
filter(
|
||||||
|
None,
|
||||||
|
[
|
||||||
|
self.salutation,
|
||||||
|
self.first_name,
|
||||||
|
self.middle_name,
|
||||||
|
self.last_name,
|
||||||
|
],
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_lead_name(self):
|
def set_lead_name(self):
|
||||||
@ -92,9 +101,16 @@ class CRMLead(Document):
|
|||||||
shared_with = [d.user for d in docshares] + [agent]
|
shared_with = [d.user for d in docshares] + [agent]
|
||||||
|
|
||||||
for user in shared_with:
|
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(
|
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:
|
elif user != agent:
|
||||||
frappe.share.remove(self.doctype, self.name, user)
|
frappe.share.remove(self.doctype, self.name, user)
|
||||||
@ -188,8 +204,36 @@ class CRMLead(Document):
|
|||||||
"lead_owner": "deal_owner",
|
"lead_owner": "deal_owner",
|
||||||
}
|
}
|
||||||
|
|
||||||
restricted_fieldtypes = ["Tab Break", "Section Break", "Column Break", "HTML", "Button", "Attach", "Table"]
|
restricted_fieldtypes = [
|
||||||
restricted_map_fields = ["name", "naming_series", "creation", "owner", "modified", "modified_by", "idx", "docstatus", "status", "email", "mobile_no", "phone", "sla", "sla_status", "response_by", "first_response_time", "first_responded_on", "communication_status", "sla_creation"]
|
"Tab Break",
|
||||||
|
"Section Break",
|
||||||
|
"Column Break",
|
||||||
|
"HTML",
|
||||||
|
"Button",
|
||||||
|
"Attach",
|
||||||
|
"Table",
|
||||||
|
]
|
||||||
|
restricted_map_fields = [
|
||||||
|
"name",
|
||||||
|
"naming_series",
|
||||||
|
"creation",
|
||||||
|
"owner",
|
||||||
|
"modified",
|
||||||
|
"modified_by",
|
||||||
|
"idx",
|
||||||
|
"docstatus",
|
||||||
|
"status",
|
||||||
|
"email",
|
||||||
|
"mobile_no",
|
||||||
|
"phone",
|
||||||
|
"sla",
|
||||||
|
"sla_status",
|
||||||
|
"response_by",
|
||||||
|
"first_response_time",
|
||||||
|
"first_responded_on",
|
||||||
|
"communication_status",
|
||||||
|
"sla_creation",
|
||||||
|
]
|
||||||
|
|
||||||
for field in self.meta.fields:
|
for field in self.meta.fields:
|
||||||
if field.fieldtype in restricted_fieldtypes:
|
if field.fieldtype in restricted_fieldtypes:
|
||||||
@ -222,7 +266,7 @@ class CRMLead(Document):
|
|||||||
"sla_status": self.sla_status,
|
"sla_status": self.sla_status,
|
||||||
"communication_status": self.communication_status,
|
"communication_status": self.communication_status,
|
||||||
"first_response_time": self.first_response_time,
|
"first_response_time": self.first_response_time,
|
||||||
"first_responded_on": self.first_responded_on
|
"first_responded_on": self.first_responded_on,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -233,7 +277,8 @@ class CRMLead(Document):
|
|||||||
"""
|
"""
|
||||||
Find an SLA to apply to the lead.
|
Find an SLA to apply to the lead.
|
||||||
"""
|
"""
|
||||||
if self.sla: return
|
if self.sla:
|
||||||
|
return
|
||||||
|
|
||||||
sla = get_sla(self)
|
sla = get_sla(self)
|
||||||
if not sla:
|
if not sla:
|
||||||
@ -263,47 +308,47 @@ class CRMLead(Document):
|
|||||||
def default_list_data():
|
def default_list_data():
|
||||||
columns = [
|
columns = [
|
||||||
{
|
{
|
||||||
'label': 'Name',
|
"label": "Name",
|
||||||
'type': 'Data',
|
"type": "Data",
|
||||||
'key': 'lead_name',
|
"key": "lead_name",
|
||||||
'width': '12rem',
|
"width": "12rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Organization',
|
"label": "Organization",
|
||||||
'type': 'Link',
|
"type": "Link",
|
||||||
'key': 'organization',
|
"key": "organization",
|
||||||
'options': 'CRM Organization',
|
"options": "CRM Organization",
|
||||||
'width': '10rem',
|
"width": "10rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Status',
|
"label": "Status",
|
||||||
'type': 'Select',
|
"type": "Select",
|
||||||
'key': 'status',
|
"key": "status",
|
||||||
'width': '8rem',
|
"width": "8rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Email',
|
"label": "Email",
|
||||||
'type': 'Data',
|
"type": "Data",
|
||||||
'key': 'email',
|
"key": "email",
|
||||||
'width': '12rem',
|
"width": "12rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Mobile No',
|
"label": "Mobile No",
|
||||||
'type': 'Data',
|
"type": "Data",
|
||||||
'key': 'mobile_no',
|
"key": "mobile_no",
|
||||||
'width': '11rem',
|
"width": "11rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Assigned To',
|
"label": "Assigned To",
|
||||||
'type': 'Text',
|
"type": "Text",
|
||||||
'key': '_assign',
|
"key": "_assign",
|
||||||
'width': '10rem',
|
"width": "10rem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'label': 'Last Modified',
|
"label": "Last Modified",
|
||||||
'type': 'Datetime',
|
"type": "Datetime",
|
||||||
'key': 'modified',
|
"key": "modified",
|
||||||
'width': '8rem',
|
"width": "8rem",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
rows = [
|
rows = [
|
||||||
@ -323,20 +368,22 @@ class CRMLead(Document):
|
|||||||
"_assign",
|
"_assign",
|
||||||
"image",
|
"image",
|
||||||
]
|
]
|
||||||
return {'columns': columns, 'rows': rows}
|
return {"columns": columns, "rows": rows}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_kanban_settings():
|
def default_kanban_settings():
|
||||||
return {
|
return {
|
||||||
"column_field": "status",
|
"column_field": "status",
|
||||||
"title_field": "lead_name",
|
"title_field": "lead_name",
|
||||||
"kanban_fields": '["organization", "email", "mobile_no", "_assign", "modified"]'
|
"kanban_fields": '["organization", "email", "mobile_no", "_assign", "modified"]',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def convert_to_deal(lead, doc=None):
|
def convert_to_deal(lead, doc=None):
|
||||||
if not (doc and doc.flags.get("ignore_permissions")) and not frappe.has_permission("CRM Lead", "write", lead):
|
if not (doc and doc.flags.get("ignore_permissions")) and not frappe.has_permission(
|
||||||
|
"CRM Lead", "write", lead
|
||||||
|
):
|
||||||
frappe.throw(_("Not allowed to convert Lead to Deal"), frappe.PermissionError)
|
frappe.throw(_("Not allowed to convert Lead to Deal"), frappe.PermissionError)
|
||||||
|
|
||||||
lead = frappe.get_cached_doc("CRM Lead", lead)
|
lead = frappe.get_cached_doc("CRM Lead", lead)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user