Merge pull request #356 from frappe/develop
chore: Merge develop to main
This commit is contained in:
commit
7898f2b5b7
@ -80,8 +80,7 @@
|
|||||||
"fetch_from": ".website",
|
"fetch_from": ".website",
|
||||||
"fieldname": "website",
|
"fieldname": "website",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Website",
|
"label": "Website"
|
||||||
"options": "URL"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "close_date",
|
"fieldname": "close_date",
|
||||||
@ -339,7 +338,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-06-20 12:55:41.602364",
|
"modified": "2024-09-17 18:34:15.873610",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Deal",
|
"name": "CRM Deal",
|
||||||
@ -371,8 +370,10 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"show_title_field_in_link": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
|
"title_field": "organization",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
@ -18,6 +18,10 @@ frappe.ui.form.on("CRM Form Script", {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!frappe.boot.developer_mode) {
|
||||||
|
frm.toggle_enable("is_standard", 0);
|
||||||
|
}
|
||||||
|
|
||||||
frm.trigger("add_enable_button");
|
frm.trigger("add_enable_button");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
"default": "0",
|
"default": "0",
|
||||||
"fieldname": "enabled",
|
"fieldname": "enabled",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
|
"hidden": 1,
|
||||||
"label": "Enabled"
|
"label": "Enabled"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -64,7 +65,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-09-11 12:56:09.288849",
|
"modified": "2024-09-16 19:40:19.340948",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Form Script",
|
"name": "CRM Form Script",
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class CRMFormScript(Document):
|
|||||||
or frappe.flags.in_test
|
or frappe.flags.in_test
|
||||||
or frappe.flags.in_fixtures
|
or frappe.flags.in_fixtures
|
||||||
)
|
)
|
||||||
if in_user_env and self.is_standard and not frappe.conf.developer_mode:
|
if in_user_env and not self.is_new() and self.is_standard and not frappe.conf.developer_mode:
|
||||||
# only enabled can be changed for standard form scripts
|
# only enabled can be changed for standard form scripts
|
||||||
if self.has_value_changed("enabled"):
|
if self.has_value_changed("enabled"):
|
||||||
enabled_value = self.enabled
|
enabled_value = self.enabled
|
||||||
|
|||||||
@ -107,8 +107,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "website",
|
"fieldname": "website",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Website",
|
"label": "Website"
|
||||||
"options": "URL"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "mobile_no",
|
"fieldname": "mobile_no",
|
||||||
@ -291,7 +290,7 @@
|
|||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-02-05 00:58:07.321058",
|
"modified": "2024-09-17 18:36:57.289897",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Lead",
|
"name": "CRM Lead",
|
||||||
@ -325,6 +324,7 @@
|
|||||||
],
|
],
|
||||||
"sender_field": "email",
|
"sender_field": "email",
|
||||||
"sender_name_field": "first_name",
|
"sender_name_field": "first_name",
|
||||||
|
"show_title_field_in_link": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
|
|||||||
@ -28,8 +28,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "website",
|
"fieldname": "website",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "Website",
|
"label": "Website"
|
||||||
"options": "URL"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "organization_logo",
|
"fieldname": "organization_logo",
|
||||||
@ -80,7 +79,7 @@
|
|||||||
"image_field": "organization_logo",
|
"image_field": "organization_logo",
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-09-13 15:52:05.106389",
|
"modified": "2024-09-17 18:37:10.341062",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Organization",
|
"name": "CRM Organization",
|
||||||
|
|||||||
0
crm/fcrm/doctype/erpnext_crm_settings/__init__.py
Normal file
0
crm/fcrm/doctype/erpnext_crm_settings/__init__.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
// For license information, please see license.txt
|
||||||
|
|
||||||
|
frappe.ui.form.on("ERPNext CRM Settings", {
|
||||||
|
refresh(frm) {
|
||||||
|
if (!frm.doc.enabled) return;
|
||||||
|
frm.add_custom_button(__("Reset ERPNext Form Script"), () => {
|
||||||
|
frappe.confirm(
|
||||||
|
__(
|
||||||
|
"Are you sure you want to reset 'Create Quotation from CRM Deal' Form Script?"
|
||||||
|
),
|
||||||
|
() => frm.trigger("reset_erpnext_form_script")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async reset_erpnext_form_script(frm) {
|
||||||
|
let script = await frm.call("reset_erpnext_form_script");
|
||||||
|
script.message &&
|
||||||
|
frappe.msgprint(__("Form Script updated successfully"));
|
||||||
|
},
|
||||||
|
});
|
||||||
124
crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.json
Normal file
124
crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.json
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
{
|
||||||
|
"actions": [],
|
||||||
|
"allow_rename": 1,
|
||||||
|
"creation": "2024-07-02 15:23:17.022214",
|
||||||
|
"doctype": "DocType",
|
||||||
|
"engine": "InnoDB",
|
||||||
|
"field_order": [
|
||||||
|
"enabled",
|
||||||
|
"is_erpnext_in_different_site",
|
||||||
|
"column_break_vfru",
|
||||||
|
"erpnext_company",
|
||||||
|
"section_break_oubd",
|
||||||
|
"erpnext_site_url",
|
||||||
|
"column_break_fllx",
|
||||||
|
"api_key",
|
||||||
|
"api_secret",
|
||||||
|
"section_break_jnbn",
|
||||||
|
"create_customer_on_status_change",
|
||||||
|
"column_break_kbhw",
|
||||||
|
"deal_status"
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||||
|
"fieldname": "api_key",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "API Key",
|
||||||
|
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||||
|
"fieldname": "api_secret",
|
||||||
|
"fieldtype": "Password",
|
||||||
|
"label": "API Secret",
|
||||||
|
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "enabled",
|
||||||
|
"fieldname": "section_break_oubd",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_fllx",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||||
|
"fieldname": "erpnext_site_url",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "ERPNext Site URL",
|
||||||
|
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "enabled",
|
||||||
|
"fieldname": "erpnext_company",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Company in ERPNext Site",
|
||||||
|
"mandatory_depends_on": "enabled"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_vfru",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "enabled",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Enabled"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "enabled",
|
||||||
|
"fieldname": "is_erpnext_in_different_site",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is ERPNext installed on a different site?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_jnbn",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "enabled",
|
||||||
|
"fieldname": "create_customer_on_status_change",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Create customer on status change"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_kbhw",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.enabled && doc.create_customer_on_status_change",
|
||||||
|
"fieldname": "deal_status",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Deal Status",
|
||||||
|
"mandatory_depends_on": "create_customer_on_status_change",
|
||||||
|
"options": "CRM Deal Status"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"index_web_pages_for_search": 1,
|
||||||
|
"issingle": 1,
|
||||||
|
"links": [],
|
||||||
|
"modified": "2024-09-17 19:21:11.060901",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "FCRM",
|
||||||
|
"name": "ERPNext CRM Settings",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"permissions": [
|
||||||
|
{
|
||||||
|
"create": 1,
|
||||||
|
"delete": 1,
|
||||||
|
"email": 1,
|
||||||
|
"print": 1,
|
||||||
|
"read": 1,
|
||||||
|
"role": "System Manager",
|
||||||
|
"share": 1,
|
||||||
|
"write": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sort_field": "creation",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"states": []
|
||||||
|
}
|
||||||
262
crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py
Normal file
262
crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
# Copyright (c) 2024, Frappe and contributors
|
||||||
|
# For license information, please see license.txt
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from frappe import _
|
||||||
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
|
from frappe.model.document import Document
|
||||||
|
from frappe.frappeclient import FrappeClient
|
||||||
|
from frappe.utils import get_url_to_form
|
||||||
|
import json
|
||||||
|
|
||||||
|
class ERPNextCRMSettings(Document):
|
||||||
|
def validate(self):
|
||||||
|
if self.enabled:
|
||||||
|
self.validate_if_erpnext_installed()
|
||||||
|
self.add_quotation_to_option()
|
||||||
|
self.create_custom_fields()
|
||||||
|
self.create_crm_form_script()
|
||||||
|
|
||||||
|
def validate_if_erpnext_installed(self):
|
||||||
|
if not self.is_erpnext_in_different_site:
|
||||||
|
if "erpnext" not in frappe.get_installed_apps():
|
||||||
|
frappe.throw(_("ERPNext is not installed in the current site"))
|
||||||
|
|
||||||
|
def add_quotation_to_option(self):
|
||||||
|
if not self.is_erpnext_in_different_site:
|
||||||
|
if not frappe.db.exists("Property Setter", {"name": "Quotation-quotation_to-link_filters"}):
|
||||||
|
make_property_setter(
|
||||||
|
doctype="Quotation",
|
||||||
|
fieldname="quotation_to",
|
||||||
|
property="link_filters",
|
||||||
|
value='[["DocType","name","in", ["Customer", "Lead", "Prospect", "Frappe CRM Deal"]]]',
|
||||||
|
property_type="JSON",
|
||||||
|
validate_fields_for_doctype=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_custom_fields(self):
|
||||||
|
if not self.is_erpnext_in_different_site:
|
||||||
|
from erpnext.crm.frappe_crm_api import create_custom_fields_for_frappe_crm
|
||||||
|
create_custom_fields_for_frappe_crm()
|
||||||
|
else:
|
||||||
|
self.create_custom_fields_in_remote_site()
|
||||||
|
|
||||||
|
def create_custom_fields_in_remote_site(self):
|
||||||
|
client = get_erpnext_site_client(self)
|
||||||
|
try:
|
||||||
|
client.post_api("erpnext.crm.frappe_crm_api.create_custom_fields_for_frappe_crm")
|
||||||
|
except Exception:
|
||||||
|
frappe.log_error(
|
||||||
|
frappe.get_traceback(),
|
||||||
|
f"Error while creating custom field in the remote erpnext site: {self.erpnext_site_url}"
|
||||||
|
)
|
||||||
|
frappe.throw("Error while creating custom field in ERPNext, check error log for more details")
|
||||||
|
|
||||||
|
def create_crm_form_script(self):
|
||||||
|
if not frappe.db.exists("CRM Form Script", "Create Quotation from CRM Deal"):
|
||||||
|
script = get_crm_form_script()
|
||||||
|
frappe.get_doc({
|
||||||
|
"doctype": "CRM Form Script",
|
||||||
|
"name": "Create Quotation from CRM Deal",
|
||||||
|
"dt": "CRM Deal",
|
||||||
|
"view": "Form",
|
||||||
|
"script": script,
|
||||||
|
"enabled": 1,
|
||||||
|
"is_standard": 1
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def reset_erpnext_form_script(self):
|
||||||
|
try:
|
||||||
|
if frappe.db.exists("CRM Form Script", "Create Quotation from CRM Deal"):
|
||||||
|
script = get_crm_form_script()
|
||||||
|
frappe.db.set_value("CRM Form Script", "Create Quotation from CRM Deal", "script", script)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
except Exception:
|
||||||
|
frappe.log_error(frappe.get_traceback(), "Error while resetting form script")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_erpnext_site_client(erpnext_crm_settings):
|
||||||
|
site_url = erpnext_crm_settings.erpnext_site_url
|
||||||
|
api_key = erpnext_crm_settings.api_key
|
||||||
|
api_secret = erpnext_crm_settings.get_password("api_secret", raise_exception=False)
|
||||||
|
|
||||||
|
return FrappeClient(
|
||||||
|
site_url, api_key=api_key, api_secret=api_secret
|
||||||
|
)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_customer_link(crm_deal):
|
||||||
|
erpnext_crm_settings = frappe.get_single("ERPNext CRM Settings")
|
||||||
|
if not erpnext_crm_settings.enabled:
|
||||||
|
frappe.throw(_("ERPNext is not integrated with the CRM"))
|
||||||
|
|
||||||
|
if not erpnext_crm_settings.is_erpnext_in_different_site:
|
||||||
|
customer_url = get_url_to_form("Customer")
|
||||||
|
customer = frappe.db.exists("Customer", {"crm_deal": crm_deal})
|
||||||
|
if customer:
|
||||||
|
return f"{customer_url}/{customer}"
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
else:
|
||||||
|
client = get_erpnext_site_client(erpnext_crm_settings)
|
||||||
|
try:
|
||||||
|
customer = client.get_list("Customer", {"crm_deal": crm_deal})[0]["name"]
|
||||||
|
if customer:
|
||||||
|
return f"{erpnext_crm_settings.erpnext_site_url}/app/customer/{customer}"
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
except Exception:
|
||||||
|
frappe.log_error(
|
||||||
|
frappe.get_traceback(),
|
||||||
|
f"Error while fetching customer in remote site: {erpnext_crm_settings.erpnext_site_url}"
|
||||||
|
)
|
||||||
|
frappe.throw(_("Error while fetching customer in ERPNext, check error log for more details"))
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_quotation_url(crm_deal, organization):
|
||||||
|
erpnext_crm_settings = frappe.get_single("ERPNext CRM Settings")
|
||||||
|
if not erpnext_crm_settings.enabled:
|
||||||
|
frappe.throw(_("ERPNext is not integrated with the CRM"))
|
||||||
|
|
||||||
|
if not erpnext_crm_settings.is_erpnext_in_different_site:
|
||||||
|
quotation_url = get_url_to_form("Quotation")
|
||||||
|
return f"{quotation_url}/new?quotation_to=CRM Deal&crm_deal={crm_deal}&party_name={crm_deal}&company={erpnext_crm_settings.erpnext_company}"
|
||||||
|
else:
|
||||||
|
site_url = erpnext_crm_settings.get("erpnext_site_url")
|
||||||
|
quotation_url = f"{site_url}/app/quotation"
|
||||||
|
|
||||||
|
prospect = create_prospect_in_remote_site(crm_deal, erpnext_crm_settings)
|
||||||
|
return f"{quotation_url}/new?quotation_to=Prospect&crm_deal={crm_deal}&party_name={prospect}&company={erpnext_crm_settings.erpnext_company}"
|
||||||
|
|
||||||
|
def create_prospect_in_remote_site(crm_deal, erpnext_crm_settings):
|
||||||
|
try:
|
||||||
|
client = get_erpnext_site_client(erpnext_crm_settings)
|
||||||
|
doc = frappe.get_doc("CRM Deal", crm_deal)
|
||||||
|
contacts = get_contacts(doc)
|
||||||
|
address = get_organization_address(doc.organization)
|
||||||
|
return client.post_api("erpnext.crm.frappe_crm_api.create_prospect_against_crm_deal",
|
||||||
|
{
|
||||||
|
"organization": doc.organization,
|
||||||
|
"lead_name": doc.lead_name,
|
||||||
|
"no_of_employees": doc.no_of_employees,
|
||||||
|
"deal_owner": doc.deal_owner,
|
||||||
|
"crm_deal": doc.name,
|
||||||
|
"territory": doc.territory,
|
||||||
|
"industry": doc.industry,
|
||||||
|
"website": doc.website,
|
||||||
|
"annual_revenue": doc.annual_revenue,
|
||||||
|
"contacts": json.dumps(contacts),
|
||||||
|
"erpnext_company": erpnext_crm_settings.erpnext_company,
|
||||||
|
"address": address.as_dict() if address else None
|
||||||
|
},
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
frappe.log_error(
|
||||||
|
frappe.get_traceback(),
|
||||||
|
f"Error while creating prospect in remote site: {erpnext_crm_settings.erpnext_site_url}"
|
||||||
|
)
|
||||||
|
frappe.throw(_("Error while creating prospect in ERPNext, check error log for more details"))
|
||||||
|
|
||||||
|
def get_contacts(doc):
|
||||||
|
contacts = []
|
||||||
|
for c in doc.contacts:
|
||||||
|
contacts.append({
|
||||||
|
"contact": c.contact,
|
||||||
|
"full_name": c.full_name,
|
||||||
|
"email": c.email,
|
||||||
|
"mobile_no": c.mobile_no,
|
||||||
|
"gender": c.gender,
|
||||||
|
"is_primary": c.is_primary,
|
||||||
|
})
|
||||||
|
return contacts
|
||||||
|
|
||||||
|
def get_organization_address(organization):
|
||||||
|
address = frappe.get_value("CRM Organization", organization, "address")
|
||||||
|
address = frappe.get_doc("Address", address) if address else None
|
||||||
|
return address
|
||||||
|
|
||||||
|
def create_customer_in_erpnext(doc, method):
|
||||||
|
erpnext_crm_settings = frappe.get_single("ERPNext CRM Settings")
|
||||||
|
if (
|
||||||
|
not erpnext_crm_settings.enabled
|
||||||
|
or not erpnext_crm_settings.create_customer_on_status_change
|
||||||
|
or doc.status != erpnext_crm_settings.deal_status
|
||||||
|
):
|
||||||
|
return
|
||||||
|
|
||||||
|
contacts = get_contacts(doc)
|
||||||
|
address = get_organization_address(doc.organization)
|
||||||
|
customer = {
|
||||||
|
"customer_name": doc.organization,
|
||||||
|
"customer_group": "All Customer Groups",
|
||||||
|
"customer_type": "Company",
|
||||||
|
"territory": doc.territory,
|
||||||
|
"default_currency": doc.currency,
|
||||||
|
"industry": doc.industry,
|
||||||
|
"website": doc.website,
|
||||||
|
"crm_deal": doc.name,
|
||||||
|
"contacts": json.dumps(contacts),
|
||||||
|
"address": address.as_dict() if address else None,
|
||||||
|
}
|
||||||
|
if not erpnext_crm_settings.is_erpnext_in_different_site:
|
||||||
|
from erpnext.crm.frappe_crm_api import create_customer
|
||||||
|
create_customer(customer)
|
||||||
|
else:
|
||||||
|
create_customer_in_remote_site(customer, erpnext_crm_settings)
|
||||||
|
|
||||||
|
frappe.publish_realtime("crm_customer_created")
|
||||||
|
|
||||||
|
def create_customer_in_remote_site(customer, erpnext_crm_settings):
|
||||||
|
client = get_erpnext_site_client(erpnext_crm_settings)
|
||||||
|
try:
|
||||||
|
client.post_api("erpnext.crm.frappe_crm_api.create_customer", customer)
|
||||||
|
except Exception:
|
||||||
|
frappe.log_error(
|
||||||
|
frappe.get_traceback(),
|
||||||
|
"Error while creating customer in remote site"
|
||||||
|
)
|
||||||
|
frappe.throw(_("Error while creating customer in ERPNext, check error log for more details"))
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_crm_form_script():
|
||||||
|
return """
|
||||||
|
async function setupForm({ doc, call, $dialog, updateField, createToast }) {
|
||||||
|
let actions = [];
|
||||||
|
let is_erpnext_integration_enabled = await call("frappe.client.get_single_value", {doctype: "ERPNext CRM Settings", field: "enabled"});
|
||||||
|
if (!["Lost", "Won"].includes(doc?.status) && is_erpnext_integration_enabled) {
|
||||||
|
actions.push({
|
||||||
|
label: __("Create Quotation"),
|
||||||
|
onClick: async () => {
|
||||||
|
let quotation_url = await call(
|
||||||
|
"crm.fcrm.doctype.erpnext_crm_settings.erpnext_crm_settings.get_quotation_url",
|
||||||
|
{
|
||||||
|
crm_deal: doc.name,
|
||||||
|
organization: doc.organization
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (quotation_url) {
|
||||||
|
window.open(quotation_url, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (is_erpnext_integration_enabled) {
|
||||||
|
let customer_url = await call("crm.fcrm.doctype.erpnext_crm_settings.erpnext_crm_settings.get_customer_link", {
|
||||||
|
crm_deal: doc.name
|
||||||
|
});
|
||||||
|
if (customer_url) {
|
||||||
|
actions.push({
|
||||||
|
label: __("View Customer"),
|
||||||
|
onClick: () => window.open(customer_url, '_blank')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
actions: actions,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
"""
|
||||||
@ -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 TestERPNextCRMSettings(FrappeTestCase):
|
||||||
|
pass
|
||||||
@ -152,6 +152,9 @@ doc_events = {
|
|||||||
"validate": ["crm.api.whatsapp.validate"],
|
"validate": ["crm.api.whatsapp.validate"],
|
||||||
"on_update": ["crm.api.whatsapp.on_update"],
|
"on_update": ["crm.api.whatsapp.on_update"],
|
||||||
},
|
},
|
||||||
|
"CRM Deal": {
|
||||||
|
"on_update": ["crm.fcrm.doctype.erpnext_crm_settings.erpnext_crm_settings.create_customer_in_erpnext"],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Scheduled Tasks
|
# Scheduled Tasks
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
/>
|
/>
|
||||||
<title>Frappe CRM</title>
|
<title>Frappe CRM</title>
|
||||||
|
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
<meta name="mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Frappe CRM" />
|
<meta name="apple-mobile-web-app-title" content="Frappe CRM" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="white" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="white" />
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
<div
|
<div
|
||||||
v-for="section in sections"
|
v-for="section in sections"
|
||||||
:key="section.label"
|
:key="section.label"
|
||||||
class="first:border-t-0 first:pt-0"
|
class="section first:border-t-0 first:pt-0"
|
||||||
:class="section.hideBorder ? '' : 'border-t pt-4'"
|
:class="section.hideBorder ? '' : 'border-t pt-4'"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@ -22,12 +22,13 @@
|
|||||||
>
|
>
|
||||||
<div v-for="field in section.fields" :key="field.name">
|
<div v-for="field in section.fields" :key="field.name">
|
||||||
<div
|
<div
|
||||||
|
class="settings-field"
|
||||||
v-if="
|
v-if="
|
||||||
(field.type == 'Check' ||
|
(field.type == 'Check' ||
|
||||||
(field.read_only && data[field.name]) ||
|
(field.read_only && data[field.name]) ||
|
||||||
!field.read_only ||
|
!field.read_only ||
|
||||||
!field.hidden) &&
|
!field.hidden) &&
|
||||||
(!field.depends_on || field.display_depends_on)
|
(!field.depends_on || field.display_via_depends_on)
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@ -35,7 +36,14 @@
|
|||||||
class="mb-2 text-sm text-gray-600"
|
class="mb-2 text-sm text-gray-600"
|
||||||
>
|
>
|
||||||
{{ __(field.label) }}
|
{{ __(field.label) }}
|
||||||
<span class="text-red-500" v-if="field.mandatory">*</span>
|
<span
|
||||||
|
class="text-red-500"
|
||||||
|
v-if="
|
||||||
|
field.mandatory ||
|
||||||
|
(field.mandatory_depends_on && field.mandatory_via_depends_on)
|
||||||
|
"
|
||||||
|
>*</span
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<FormControl
|
<FormControl
|
||||||
v-if="field.read_only && field.type !== 'Check'"
|
v-if="field.read_only && field.type !== 'Check'"
|
||||||
@ -231,4 +239,12 @@ const props = defineProps({
|
|||||||
:deep(.form-control.prefix select) {
|
:deep(.form-control.prefix select) {
|
||||||
padding-left: 2rem;
|
padding-left: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section:has(.settings-field) {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
20
frontend/src/components/Icons/ERPNextIcon.vue
Normal file
20
frontend/src/components/Icons/ERPNextIcon.vue
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<template>
|
||||||
|
<svg
|
||||||
|
width="18"
|
||||||
|
height="18"
|
||||||
|
viewBox="0 0 18 18"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M1 5C1 2.79086 2.79086 1 5 1H13C15.2091 1 17 2.79086 17 5V13C17 15.2091 15.2091 17 13 17H5C2.79086 17 1 15.2091 1 13V5Z"
|
||||||
|
stroke="currentColor"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
d="M11.7819 6.27142H11.5136H8.02453H6.28001V4.84002H11.7819V6.27142ZM8.02451 9.62623V11.5944H11.8267V13.0258H6.27999V8.19484H8.02451H11.5135V9.62623H8.02451Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
@ -19,7 +19,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import EditValueModal from '@/components/Modals/EditValueModal.vue'
|
import EditValueModal from '@/components/Modals/EditValueModal.vue'
|
||||||
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
|
import AssignmentModal from '@/components/Modals/AssignmentModal.vue'
|
||||||
import { setupListActions, createToast } from '@/utils'
|
import { setupListCustomizations, createToast } from '@/utils'
|
||||||
import { globalStore } from '@/stores/global'
|
import { globalStore } from '@/stores/global'
|
||||||
import { capture } from '@/telemetry'
|
import { capture } from '@/telemetry'
|
||||||
import { call } from 'frappe-ui'
|
import { call } from 'frappe-ui'
|
||||||
@ -45,7 +45,7 @@ const list = defineModel()
|
|||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const { $dialog } = globalStore()
|
const { $dialog, $socket } = globalStore()
|
||||||
|
|
||||||
const showEditModal = ref(false)
|
const showEditModal = ref(false)
|
||||||
const selectedValues = ref([])
|
const selectedValues = ref([])
|
||||||
@ -230,17 +230,20 @@ function reload(unselectAll) {
|
|||||||
list.value?.reload()
|
list.value?.reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
if (!list.value?.data) return
|
if (!list.value?.data) return
|
||||||
setupListActions(list.value.data, {
|
let customization = await setupListCustomizations(list.value.data, {
|
||||||
list: list.value,
|
list: list.value,
|
||||||
call,
|
call,
|
||||||
createToast,
|
createToast,
|
||||||
$dialog,
|
$dialog,
|
||||||
|
$socket,
|
||||||
router,
|
router,
|
||||||
})
|
})
|
||||||
customBulkActions.value = list.value?.data?.bulkActions || []
|
customBulkActions.value =
|
||||||
customListActions.value = list.value?.data?.listActions || []
|
customization?.bulkActions || list.value?.data?.bulkActions || []
|
||||||
|
customListActions.value =
|
||||||
|
customization?.actions || list.value?.data?.listActions || []
|
||||||
})
|
})
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
|||||||
@ -69,10 +69,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div v-else-if="column.key === 'organization'">
|
<div v-else-if="column.key === 'organization'">
|
||||||
<Avatar
|
<Avatar
|
||||||
v-if="item.label"
|
v-if="item"
|
||||||
class="flex items-center"
|
class="flex items-center"
|
||||||
:image="item.logo"
|
:image="item"
|
||||||
:label="item.label"
|
:label="item"
|
||||||
size="sm"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<FadedScrollableDiv
|
<FadedScrollableDiv
|
||||||
class="flex max-h-[300px] flex-col gap-1.5 overflow-y-auto"
|
class="flex flex-col gap-1.5 overflow-y-auto"
|
||||||
|
:class="[isLastSection ? '' : 'max-h-[300px]']"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-for="field in _fields"
|
v-for="field in _fields"
|
||||||
:key="field.label"
|
:key="field.label"
|
||||||
:class="[field.hidden && 'hidden']"
|
:class="[field.hidden && 'hidden']"
|
||||||
class="flex items-center gap-2 px-3 leading-5 first:mt-3"
|
class="section-field flex items-center gap-2 px-3 leading-5 first:mt-3"
|
||||||
>
|
>
|
||||||
<Tooltip :text="__(field.label)" :hoverDelay="1">
|
<Tooltip :text="__(field.label)" :hoverDelay="1">
|
||||||
<div class="sm:w-[106px] w-36 shrink-0 truncate text-sm text-gray-600">
|
<div class="sm:w-[106px] w-36 shrink-0 truncate text-sm text-gray-600">
|
||||||
@ -124,6 +125,10 @@ const props = defineProps({
|
|||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
isLastSection: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { getUser } = usersStore()
|
const { getUser } = usersStore()
|
||||||
|
|||||||
11
frontend/src/components/Settings/ERPNextSettings.vue
Normal file
11
frontend/src/components/Settings/ERPNextSettings.vue
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<template>
|
||||||
|
<SettingsPage
|
||||||
|
doctype="ERPNext CRM Settings"
|
||||||
|
:title="__('ERPNext Settings')"
|
||||||
|
:successMessage="__('ERPNext Settings updated')"
|
||||||
|
class="p-8"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<script setup>
|
||||||
|
import SettingsPage from '@/components/Settings/SettingsPage.vue'
|
||||||
|
</script>
|
||||||
@ -39,10 +39,12 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
|
import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
|
||||||
import WhatsAppIcon from '@/components/Icons/WhatsAppIcon.vue'
|
import WhatsAppIcon from '@/components/Icons/WhatsAppIcon.vue'
|
||||||
|
import ERPNextIcon from '@/components/Icons/ERPNextIcon.vue'
|
||||||
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
||||||
import InviteMemberPage from '@/components/Settings/InviteMemberPage.vue'
|
import InviteMemberPage from '@/components/Settings/InviteMemberPage.vue'
|
||||||
import ProfileSettings from '@/components/Settings/ProfileSettings.vue'
|
import ProfileSettings from '@/components/Settings/ProfileSettings.vue'
|
||||||
import WhatsAppSettings from '@/components/Settings/WhatsAppSettings.vue'
|
import WhatsAppSettings from '@/components/Settings/WhatsAppSettings.vue'
|
||||||
|
import ERPNextSettings from '@/components/Settings/ERPNextSettings.vue'
|
||||||
import TwilioSettings from '@/components/Settings/TwilioSettings.vue'
|
import TwilioSettings from '@/components/Settings/TwilioSettings.vue'
|
||||||
import SidebarLink from '@/components/SidebarLink.vue'
|
import SidebarLink from '@/components/SidebarLink.vue'
|
||||||
import { isWhatsappInstalled } from '@/composables/settings'
|
import { isWhatsappInstalled } from '@/composables/settings'
|
||||||
@ -83,6 +85,11 @@ const tabs = computed(() => {
|
|||||||
component: markRaw(WhatsAppSettings),
|
component: markRaw(WhatsAppSettings),
|
||||||
condition: () => isWhatsappInstalled.value,
|
condition: () => isWhatsappInstalled.value,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: __('ERPNext'),
|
||||||
|
icon: ERPNextIcon,
|
||||||
|
component: markRaw(ERPNextSettings),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex h-full flex-col gap-8">
|
<div class="flex h-full flex-col gap-8">
|
||||||
<h2 class="flex gap-2 text-xl font-semibold leading-none h-5">
|
<h2 class="flex gap-2 text-xl font-semibold leading-none h-5">
|
||||||
<div>{{ __(doctype) }}</div>
|
<div>{{ title || __(doctype) }}</div>
|
||||||
<Badge
|
<Badge
|
||||||
v-if="data.isDirty"
|
v-if="data.isDirty"
|
||||||
:label="__('Not Saved')"
|
:label="__('Not Saved')"
|
||||||
@ -15,6 +15,7 @@
|
|||||||
:sections="sections"
|
:sections="sections"
|
||||||
:data="data.doc"
|
:data="data.doc"
|
||||||
/>
|
/>
|
||||||
|
<ErrorMessage class="mt-2" :message="error" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="flex flex-1 items-center justify-center">
|
<div v-else class="flex flex-1 items-center justify-center">
|
||||||
<Spinner class="size-8" />
|
<Spinner class="size-8" />
|
||||||
@ -36,15 +37,20 @@ import {
|
|||||||
createResource,
|
createResource,
|
||||||
Spinner,
|
Spinner,
|
||||||
Badge,
|
Badge,
|
||||||
|
ErrorMessage,
|
||||||
} from 'frappe-ui'
|
} from 'frappe-ui'
|
||||||
import { evaluate_depends_on_value, createToast } from '@/utils'
|
import { evaluate_depends_on_value, createToast } from '@/utils'
|
||||||
import { computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
doctype: {
|
doctype: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
successMessage: {
|
successMessage: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'Updated Successfully',
|
default: 'Updated Successfully',
|
||||||
@ -61,6 +67,8 @@ const fields = createResource({
|
|||||||
auto: true,
|
auto: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const error = ref(null)
|
||||||
|
|
||||||
const data = createDocumentResource({
|
const data = createDocumentResource({
|
||||||
doctype: props.doctype,
|
doctype: props.doctype,
|
||||||
name: props.doctype,
|
name: props.doctype,
|
||||||
@ -69,6 +77,7 @@ const data = createDocumentResource({
|
|||||||
auto: true,
|
auto: true,
|
||||||
setValue: {
|
setValue: {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
error.value = null
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Success'),
|
title: __('Success'),
|
||||||
text: __(props.successMessage),
|
text: __(props.successMessage),
|
||||||
@ -113,10 +122,14 @@ const sections = computed(() => {
|
|||||||
} else {
|
} else {
|
||||||
_sections[_sections.length - 1].fields.push({
|
_sections[_sections.length - 1].fields.push({
|
||||||
...field,
|
...field,
|
||||||
display_depends_on: evaluate_depends_on_value(
|
display_via_depends_on: evaluate_depends_on_value(
|
||||||
field.depends_on,
|
field.depends_on,
|
||||||
data.doc,
|
data.doc,
|
||||||
),
|
),
|
||||||
|
mandatory_via_depends_on: evaluate_depends_on_value(
|
||||||
|
field.mandatory_depends_on,
|
||||||
|
data.doc,
|
||||||
|
),
|
||||||
name: field.value,
|
name: field.value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -126,6 +139,24 @@ const sections = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
|
error.value = null
|
||||||
|
if (validateMandatoryFields()) return
|
||||||
data.save.submit()
|
data.save.submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateMandatoryFields() {
|
||||||
|
for (let section of sections.value) {
|
||||||
|
for (let field of section.fields) {
|
||||||
|
if (
|
||||||
|
(field.mandatory ||
|
||||||
|
(field.mandatory_depends_on && field.mandatory_via_depends_on)) &&
|
||||||
|
!data.doc[field.name]
|
||||||
|
) {
|
||||||
|
error.value = __('{0} is mandatory', [__(field.label)])
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -43,7 +43,11 @@
|
|||||||
:class="{ 'border-b': i !== sections.data.length - 1 }"
|
:class="{ 'border-b': i !== sections.data.length - 1 }"
|
||||||
>
|
>
|
||||||
<Section :is-opened="section.opened" :label="section.label">
|
<Section :is-opened="section.opened" :label="section.label">
|
||||||
<SectionFields :fields="section.fields" v-model="data" />
|
<SectionFields
|
||||||
|
:fields="section.fields"
|
||||||
|
:isLastSection="i == section.data.length - 1"
|
||||||
|
v-model="data"
|
||||||
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -8,19 +8,14 @@
|
|||||||
</Breadcrumbs>
|
</Breadcrumbs>
|
||||||
</template>
|
</template>
|
||||||
<template #right-header>
|
<template #right-header>
|
||||||
<CustomActions
|
<CustomActions v-if="customActions" :actions="customActions" />
|
||||||
v-if="deal.data._customActions"
|
|
||||||
:actions="deal.data._customActions"
|
|
||||||
/>
|
|
||||||
<component :is="deal.data._assignedTo?.length == 1 ? 'Button' : 'div'">
|
<component :is="deal.data._assignedTo?.length == 1 ? 'Button' : 'div'">
|
||||||
<MultipleAvatar
|
<MultipleAvatar
|
||||||
:avatars="deal.data._assignedTo"
|
:avatars="deal.data._assignedTo"
|
||||||
@click="showAssignmentModal = true"
|
@click="showAssignmentModal = true"
|
||||||
/>
|
/>
|
||||||
</component>
|
</component>
|
||||||
<Dropdown
|
<Dropdown :options="statusOptions('deal', updateField, customStatuses)">
|
||||||
:options="statusOptions('deal', updateField, deal.data._customStatuses)"
|
|
||||||
>
|
|
||||||
<template #default="{ open }">
|
<template #default="{ open }">
|
||||||
<Button
|
<Button
|
||||||
:label="deal.data.status"
|
:label="deal.data.status"
|
||||||
@ -64,15 +59,15 @@
|
|||||||
<Avatar
|
<Avatar
|
||||||
size="3xl"
|
size="3xl"
|
||||||
class="size-12"
|
class="size-12"
|
||||||
:label="organization?.name || __('Untitled')"
|
:label="organization.data?.name || __('Untitled')"
|
||||||
:image="organization?.organization_logo"
|
:image="organization.data?.organization_logo"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<div class="flex flex-col gap-2.5 truncate">
|
<div class="flex flex-col gap-2.5 truncate">
|
||||||
<Tooltip :text="organization?.name || __('Set an organization')">
|
<Tooltip :text="organization.data?.name || __('Set an organization')">
|
||||||
<div class="truncate text-2xl font-medium">
|
<div class="truncate text-2xl font-medium">
|
||||||
{{ organization?.name || __('Untitled') }}
|
{{ organization.data?.name || __('Untitled') }}
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<div class="flex gap-1.5">
|
<div class="flex gap-1.5">
|
||||||
@ -121,7 +116,7 @@
|
|||||||
<div
|
<div
|
||||||
v-for="(section, i) in fieldsLayout.data"
|
v-for="(section, i) in fieldsLayout.data"
|
||||||
:key="section.label"
|
:key="section.label"
|
||||||
class="flex flex-col p-3"
|
class="section flex flex-col p-3"
|
||||||
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
|
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
|
||||||
>
|
>
|
||||||
<Section :is-opened="section.opened" :label="section.label">
|
<Section :is-opened="section.opened" :label="section.label">
|
||||||
@ -166,13 +161,14 @@
|
|||||||
<SectionFields
|
<SectionFields
|
||||||
v-if="section.fields"
|
v-if="section.fields"
|
||||||
:fields="section.fields"
|
:fields="section.fields"
|
||||||
|
:isLastSection="i == fieldsLayout.data.length - 1"
|
||||||
v-model="deal.data"
|
v-model="deal.data"
|
||||||
@update="updateField"
|
@update="updateField"
|
||||||
/>
|
/>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div
|
<div
|
||||||
v-if="
|
v-if="
|
||||||
deal_contacts?.loading && deal_contacts?.data?.length == 0
|
dealContacts?.loading && dealContacts?.data?.length == 0
|
||||||
"
|
"
|
||||||
class="flex min-h-20 flex-1 items-center justify-center gap-3 text-base text-gray-500"
|
class="flex min-h-20 flex-1 items-center justify-center gap-3 text-base text-gray-500"
|
||||||
>
|
>
|
||||||
@ -180,8 +176,8 @@
|
|||||||
<span>{{ __('Loading...') }}</span>
|
<span>{{ __('Loading...') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-else-if="deal_contacts?.data?.length"
|
v-else-if="dealContacts?.data?.length"
|
||||||
v-for="(contact, i) in deal_contacts.data"
|
v-for="(contact, i) in dealContacts.data"
|
||||||
:key="contact.name"
|
:key="contact.name"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@ -257,7 +253,7 @@
|
|||||||
</Section>
|
</Section>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="i != deal_contacts.data.length - 1"
|
v-if="i != dealContacts.data.length - 1"
|
||||||
class="mx-2 h-px border-t border-gray-200"
|
class="mx-2 h-px border-t border-gray-200"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -279,10 +275,7 @@
|
|||||||
v-model:organization="_organization"
|
v-model:organization="_organization"
|
||||||
:options="{
|
:options="{
|
||||||
redirect: false,
|
redirect: false,
|
||||||
afterInsert: (doc) =>
|
afterInsert: (doc) => updateField('organization', doc.name),
|
||||||
updateField('organization', doc.name, () => {
|
|
||||||
organizations.reload()
|
|
||||||
}),
|
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<ContactModal
|
<ContactModal
|
||||||
@ -340,14 +333,12 @@ import {
|
|||||||
openWebsite,
|
openWebsite,
|
||||||
createToast,
|
createToast,
|
||||||
setupAssignees,
|
setupAssignees,
|
||||||
setupCustomActions,
|
setupCustomizations,
|
||||||
setupCustomStatuses,
|
|
||||||
errorMessage,
|
errorMessage,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { globalStore } from '@/stores/global'
|
import { globalStore } from '@/stores/global'
|
||||||
import { organizationsStore } from '@/stores/organizations'
|
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { whatsappEnabled, callEnabled } from '@/composables/settings'
|
import { whatsappEnabled, callEnabled } from '@/composables/settings'
|
||||||
@ -361,11 +352,10 @@ import {
|
|||||||
call,
|
call,
|
||||||
usePageMeta,
|
usePageMeta,
|
||||||
} from 'frappe-ui'
|
} from 'frappe-ui'
|
||||||
import { ref, computed, h, onMounted } from 'vue'
|
import { ref, computed, h, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
const { $dialog, makeCall } = globalStore()
|
const { $dialog, $socket, makeCall } = globalStore()
|
||||||
const { organizations, getOrganization } = organizationsStore()
|
|
||||||
const { statusOptions, getDealStatus } = statusesStore()
|
const { statusOptions, getDealStatus } = statusesStore()
|
||||||
const { isManager } = usersStore()
|
const { isManager } = usersStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -378,41 +368,71 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const customActions = ref([])
|
||||||
|
const customStatuses = ref([])
|
||||||
|
|
||||||
const deal = createResource({
|
const deal = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_deal.api.get_deal',
|
url: 'crm.fcrm.doctype.crm_deal.api.get_deal',
|
||||||
params: { name: props.dealId },
|
params: { name: props.dealId },
|
||||||
cache: ['deal', props.dealId],
|
cache: ['deal', props.dealId],
|
||||||
onSuccess: (data) => {
|
onSuccess: async (data) => {
|
||||||
|
organization.update({
|
||||||
|
params: { doctype: 'CRM Organization', name: data.organization },
|
||||||
|
})
|
||||||
|
organization.fetch()
|
||||||
let obj = {
|
let obj = {
|
||||||
doc: data,
|
doc: data,
|
||||||
$dialog,
|
$dialog,
|
||||||
|
$socket,
|
||||||
router,
|
router,
|
||||||
updateField,
|
updateField,
|
||||||
createToast,
|
createToast,
|
||||||
deleteDoc: deleteDeal,
|
deleteDoc: deleteDeal,
|
||||||
|
resource: {
|
||||||
|
deal,
|
||||||
|
dealContacts,
|
||||||
|
fieldsLayout,
|
||||||
|
},
|
||||||
call,
|
call,
|
||||||
}
|
}
|
||||||
setupAssignees(data)
|
setupAssignees(data)
|
||||||
setupCustomStatuses(data, obj)
|
let customization = await setupCustomizations(data, obj)
|
||||||
setupCustomActions(data, obj)
|
customActions.value = customization.actions || []
|
||||||
|
customStatuses.value = customization.statuses || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const organization = createResource({
|
||||||
|
url: 'frappe.client.get',
|
||||||
|
onSuccess: (data) => (deal.data._organizationObj = data),
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (deal.data) return
|
$socket.on('crm_customer_created', () => {
|
||||||
|
createToast({
|
||||||
|
title: __('Customer created successfully'),
|
||||||
|
icon: 'check',
|
||||||
|
iconClasses: 'text-green-600',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if (deal.data) {
|
||||||
|
organization.data = deal.data._organizationObj
|
||||||
|
return
|
||||||
|
}
|
||||||
deal.fetch()
|
deal.fetch()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
$socket.off('crm_customer_created')
|
||||||
|
})
|
||||||
|
|
||||||
const reload = ref(false)
|
const reload = ref(false)
|
||||||
const showOrganizationModal = ref(false)
|
const showOrganizationModal = ref(false)
|
||||||
const showAssignmentModal = ref(false)
|
const showAssignmentModal = ref(false)
|
||||||
const showSidePanelModal = ref(false)
|
const showSidePanelModal = ref(false)
|
||||||
const _organization = ref({})
|
const _organization = ref({})
|
||||||
|
|
||||||
const organization = computed(() => {
|
|
||||||
return deal.data?.organization && getOrganization(deal.data.organization)
|
|
||||||
})
|
|
||||||
|
|
||||||
function updateDeal(fieldname, value, callback) {
|
function updateDeal(fieldname, value, callback) {
|
||||||
value = Array.isArray(fieldname) ? '' : value
|
value = Array.isArray(fieldname) ? '' : value
|
||||||
|
|
||||||
@ -481,7 +501,7 @@ const breadcrumbs = computed(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
label: organization.value?.name || __('Untitled'),
|
label: organization.data?.name || __('Untitled'),
|
||||||
route: { name: 'Deal', params: { dealId: deal.data.name } },
|
route: { name: 'Deal', params: { dealId: deal.data.name } },
|
||||||
})
|
})
|
||||||
return items
|
return items
|
||||||
@ -489,7 +509,7 @@ const breadcrumbs = computed(() => {
|
|||||||
|
|
||||||
usePageMeta(() => {
|
usePageMeta(() => {
|
||||||
return {
|
return {
|
||||||
title: organization.value?.name || deal.data?.name,
|
title: organization.data?.name || deal.data?.name,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -595,7 +615,7 @@ async function addContact(contact) {
|
|||||||
contact,
|
contact,
|
||||||
})
|
})
|
||||||
if (d) {
|
if (d) {
|
||||||
deal_contacts.reload()
|
dealContacts.reload()
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Contact added'),
|
title: __('Contact added'),
|
||||||
icon: 'check',
|
icon: 'check',
|
||||||
@ -610,7 +630,7 @@ async function removeContact(contact) {
|
|||||||
contact,
|
contact,
|
||||||
})
|
})
|
||||||
if (d) {
|
if (d) {
|
||||||
deal_contacts.reload()
|
dealContacts.reload()
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Contact removed'),
|
title: __('Contact removed'),
|
||||||
icon: 'check',
|
icon: 'check',
|
||||||
@ -625,7 +645,7 @@ async function setPrimaryContact(contact) {
|
|||||||
contact,
|
contact,
|
||||||
})
|
})
|
||||||
if (d) {
|
if (d) {
|
||||||
deal_contacts.reload()
|
dealContacts.reload()
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Primary contact set'),
|
title: __('Primary contact set'),
|
||||||
icon: 'check',
|
icon: 'check',
|
||||||
@ -634,7 +654,7 @@ async function setPrimaryContact(contact) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const deal_contacts = createResource({
|
const dealContacts = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_deal.api.get_deal_contacts',
|
url: 'crm.fcrm.doctype.crm_deal.api.get_deal_contacts',
|
||||||
params: { name: props.dealId },
|
params: { name: props.dealId },
|
||||||
cache: ['deal_contacts', props.dealId],
|
cache: ['deal_contacts', props.dealId],
|
||||||
@ -648,7 +668,7 @@ const deal_contacts = createResource({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function triggerCall() {
|
function triggerCall() {
|
||||||
let primaryContact = deal_contacts.data?.find((c) => c.is_primary)
|
let primaryContact = dealContacts.data?.find((c) => c.is_primary)
|
||||||
let mobile_no = primaryContact.mobile_no || null
|
let mobile_no = primaryContact.mobile_no || null
|
||||||
|
|
||||||
if (!primaryContact) {
|
if (!primaryContact) {
|
||||||
@ -685,3 +705,12 @@ function openEmailBox() {
|
|||||||
activities.value.emailBox.show = true
|
activities.value.emailBox.show = true
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
:deep(.section:has(.section-field.hidden)) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
:deep(.section:has(.section-field:not(.hidden))) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@ -290,6 +290,7 @@ import {
|
|||||||
dateFormat,
|
dateFormat,
|
||||||
dateTooltipFormat,
|
dateTooltipFormat,
|
||||||
timeAgo,
|
timeAgo,
|
||||||
|
website,
|
||||||
formatNumberIntoCurrency,
|
formatNumberIntoCurrency,
|
||||||
formatTime,
|
formatTime,
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
@ -394,6 +395,8 @@ function parseRows(rows) {
|
|||||||
label: deal.organization,
|
label: deal.organization,
|
||||||
logo: getOrganization(deal.organization)?.organization_logo,
|
logo: getOrganization(deal.organization)?.organization_logo,
|
||||||
}
|
}
|
||||||
|
} else if (row === 'website') {
|
||||||
|
_rows[row] = website(deal.website)
|
||||||
} else if (row == 'annual_revenue') {
|
} else if (row == 'annual_revenue') {
|
||||||
_rows[row] = formatNumberIntoCurrency(
|
_rows[row] = formatNumberIntoCurrency(
|
||||||
deal.annual_revenue,
|
deal.annual_revenue,
|
||||||
|
|||||||
@ -8,17 +8,14 @@
|
|||||||
</Breadcrumbs>
|
</Breadcrumbs>
|
||||||
</template>
|
</template>
|
||||||
<template #right-header>
|
<template #right-header>
|
||||||
<CustomActions
|
<CustomActions v-if="customActions" :actions="customActions" />
|
||||||
v-if="lead.data._customActions"
|
|
||||||
:actions="lead.data._customActions"
|
|
||||||
/>
|
|
||||||
<component :is="lead.data._assignedTo?.length == 1 ? 'Button' : 'div'">
|
<component :is="lead.data._assignedTo?.length == 1 ? 'Button' : 'div'">
|
||||||
<MultipleAvatar
|
<MultipleAvatar
|
||||||
:avatars="lead.data._assignedTo"
|
:avatars="lead.data._assignedTo"
|
||||||
@click="showAssignmentModal = true"
|
@click="showAssignmentModal = true"
|
||||||
/>
|
/>
|
||||||
</component>
|
</component>
|
||||||
<Dropdown :options="statusOptions('lead', updateField, lead.data._customStatuses)">
|
<Dropdown :options="statusOptions('lead', updateField, customStatuses)">
|
||||||
<template #default="{ open }">
|
<template #default="{ open }">
|
||||||
<Button
|
<Button
|
||||||
:label="lead.data.status"
|
:label="lead.data.status"
|
||||||
@ -179,6 +176,7 @@
|
|||||||
<Section :is-opened="section.opened" :label="section.label">
|
<Section :is-opened="section.opened" :label="section.label">
|
||||||
<SectionFields
|
<SectionFields
|
||||||
:fields="section.fields"
|
:fields="section.fields"
|
||||||
|
:isLastSection="i == fieldsLayout.data.length - 1"
|
||||||
v-model="lead.data"
|
v-model="lead.data"
|
||||||
@update="updateField"
|
@update="updateField"
|
||||||
/>
|
/>
|
||||||
@ -307,15 +305,13 @@ import {
|
|||||||
openWebsite,
|
openWebsite,
|
||||||
createToast,
|
createToast,
|
||||||
setupAssignees,
|
setupAssignees,
|
||||||
setupCustomActions,
|
setupCustomizations,
|
||||||
setupCustomStatuses,
|
|
||||||
errorMessage,
|
errorMessage,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { globalStore } from '@/stores/global'
|
import { globalStore } from '@/stores/global'
|
||||||
import { contactsStore } from '@/stores/contacts'
|
import { contactsStore } from '@/stores/contacts'
|
||||||
import { organizationsStore } from '@/stores/organizations'
|
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { whatsappEnabled, callEnabled } from '@/composables/settings'
|
import { whatsappEnabled, callEnabled } from '@/composables/settings'
|
||||||
@ -335,9 +331,8 @@ import {
|
|||||||
import { ref, computed, onMounted, watch } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
|
|
||||||
const { $dialog, makeCall } = globalStore()
|
const { $dialog, $socket, makeCall } = globalStore()
|
||||||
const { getContactByName, contacts } = contactsStore()
|
const { getContactByName, contacts } = contactsStore()
|
||||||
const { organizations } = organizationsStore()
|
|
||||||
const { statusOptions, getLeadStatus } = statusesStore()
|
const { statusOptions, getLeadStatus } = statusesStore()
|
||||||
const { isManager } = usersStore()
|
const { isManager } = usersStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -350,23 +345,32 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const customActions = ref([])
|
||||||
|
const customStatuses = ref([])
|
||||||
|
|
||||||
const lead = createResource({
|
const lead = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_lead.api.get_lead',
|
url: 'crm.fcrm.doctype.crm_lead.api.get_lead',
|
||||||
params: { name: props.leadId },
|
params: { name: props.leadId },
|
||||||
cache: ['lead', props.leadId],
|
cache: ['lead', props.leadId],
|
||||||
onSuccess: (data) => {
|
onSuccess: async (data) => {
|
||||||
let obj = {
|
let obj = {
|
||||||
doc: data,
|
doc: data,
|
||||||
$dialog,
|
$dialog,
|
||||||
|
$socket,
|
||||||
router,
|
router,
|
||||||
updateField,
|
updateField,
|
||||||
createToast,
|
createToast,
|
||||||
deleteDoc: deleteLead,
|
deleteDoc: deleteLead,
|
||||||
|
resource: {
|
||||||
|
lead,
|
||||||
|
fieldsLayout,
|
||||||
|
},
|
||||||
call,
|
call,
|
||||||
}
|
}
|
||||||
setupAssignees(data)
|
setupAssignees(data)
|
||||||
setupCustomStatuses(data, obj)
|
let customization = await setupCustomizations(data, obj)
|
||||||
setupCustomActions(data, obj)
|
customActions.value = customization.actions || []
|
||||||
|
customStatuses.value = customization.statuses || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -615,7 +619,6 @@ async function convertToDeal(updated) {
|
|||||||
if (deal) {
|
if (deal) {
|
||||||
capture('convert_lead_to_deal')
|
capture('convert_lead_to_deal')
|
||||||
if (updated) {
|
if (updated) {
|
||||||
await organizations.reload()
|
|
||||||
await contacts.reload()
|
await contacts.reload()
|
||||||
}
|
}
|
||||||
router.push({ name: 'Deal', params: { dealId: deal } })
|
router.push({ name: 'Deal', params: { dealId: deal } })
|
||||||
|
|||||||
@ -305,17 +305,21 @@ import QuickEntryModal from '@/components/Modals/QuickEntryModal.vue'
|
|||||||
import ViewControls from '@/components/ViewControls.vue'
|
import ViewControls from '@/components/ViewControls.vue'
|
||||||
import { globalStore } from '@/stores/global'
|
import { globalStore } from '@/stores/global'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { organizationsStore } from '@/stores/organizations'
|
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import { callEnabled } from '@/composables/settings'
|
import { callEnabled } from '@/composables/settings'
|
||||||
import { dateFormat, dateTooltipFormat, timeAgo, formatTime } from '@/utils'
|
import {
|
||||||
|
dateFormat,
|
||||||
|
dateTooltipFormat,
|
||||||
|
timeAgo,
|
||||||
|
website,
|
||||||
|
formatTime,
|
||||||
|
} from '@/utils'
|
||||||
import { Avatar, Tooltip, Dropdown } from 'frappe-ui'
|
import { Avatar, Tooltip, Dropdown } from 'frappe-ui'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { ref, computed, reactive, h } from 'vue'
|
import { ref, computed, reactive, h } from 'vue'
|
||||||
|
|
||||||
const { makeCall } = globalStore()
|
const { makeCall } = globalStore()
|
||||||
const { getUser } = usersStore()
|
const { getUser } = usersStore()
|
||||||
const { getOrganization } = organizationsStore()
|
|
||||||
const { getLeadStatus } = statusesStore()
|
const { getLeadStatus } = statusesStore()
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -412,10 +416,9 @@ function parseRows(rows) {
|
|||||||
image_label: lead.first_name,
|
image_label: lead.first_name,
|
||||||
}
|
}
|
||||||
} else if (row == 'organization') {
|
} else if (row == 'organization') {
|
||||||
_rows[row] = {
|
_rows[row] = lead.organization
|
||||||
label: lead.organization,
|
} else if (row === 'website') {
|
||||||
logo: getOrganization(lead.organization)?.organization_logo,
|
_rows[row] = website(lead.website)
|
||||||
}
|
|
||||||
} else if (row == 'status') {
|
} else if (row == 'status') {
|
||||||
_rows[row] = {
|
_rows[row] = {
|
||||||
label: lead.status,
|
label: lead.status,
|
||||||
|
|||||||
@ -9,11 +9,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</Breadcrumbs>
|
</Breadcrumbs>
|
||||||
<div class="absolute right-0">
|
<div class="absolute right-0">
|
||||||
<Dropdown
|
<Dropdown :options="statusOptions('deal', updateField, customStatuses)">
|
||||||
:options="
|
|
||||||
statusOptions('deal', updateField, deal.data._customStatuses)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<template #default="{ open }">
|
<template #default="{ open }">
|
||||||
<Button
|
<Button
|
||||||
:label="deal.data.status"
|
:label="deal.data.status"
|
||||||
@ -45,10 +41,7 @@
|
|||||||
/>
|
/>
|
||||||
</component>
|
</component>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<CustomActions
|
<CustomActions v-if="customActions" :actions="customActions" />
|
||||||
v-if="deal.data._customActions"
|
|
||||||
:actions="deal.data._customActions"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="deal.data" class="flex h-full overflow-hidden">
|
<div v-if="deal.data" class="flex h-full overflow-hidden">
|
||||||
@ -108,13 +101,14 @@
|
|||||||
<SectionFields
|
<SectionFields
|
||||||
v-if="section.fields"
|
v-if="section.fields"
|
||||||
:fields="section.fields"
|
:fields="section.fields"
|
||||||
|
:isLastSection="i == fieldsLayout.data.length - 1"
|
||||||
v-model="deal.data"
|
v-model="deal.data"
|
||||||
@update="updateField"
|
@update="updateField"
|
||||||
/>
|
/>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div
|
<div
|
||||||
v-if="
|
v-if="
|
||||||
deal_contacts?.loading && deal_contacts?.data?.length == 0
|
dealContacts?.loading && dealContacts?.data?.length == 0
|
||||||
"
|
"
|
||||||
class="flex min-h-20 flex-1 items-center justify-center gap-3 text-base text-gray-500"
|
class="flex min-h-20 flex-1 items-center justify-center gap-3 text-base text-gray-500"
|
||||||
>
|
>
|
||||||
@ -230,10 +224,7 @@
|
|||||||
v-model:organization="_organization"
|
v-model:organization="_organization"
|
||||||
:options="{
|
:options="{
|
||||||
redirect: false,
|
redirect: false,
|
||||||
afterInsert: (doc) =>
|
afterInsert: (doc) => updateField('organization', doc.name),
|
||||||
updateField('organization', doc.name, () => {
|
|
||||||
organizations.reload()
|
|
||||||
}),
|
|
||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<ContactModal
|
<ContactModal
|
||||||
@ -278,15 +269,9 @@ import Section from '@/components/Section.vue'
|
|||||||
import SectionFields from '@/components/SectionFields.vue'
|
import SectionFields from '@/components/SectionFields.vue'
|
||||||
import SLASection from '@/components/SLASection.vue'
|
import SLASection from '@/components/SLASection.vue'
|
||||||
import CustomActions from '@/components/CustomActions.vue'
|
import CustomActions from '@/components/CustomActions.vue'
|
||||||
import {
|
import { createToast, setupAssignees, setupCustomizations } from '@/utils'
|
||||||
createToast,
|
|
||||||
setupAssignees,
|
|
||||||
setupCustomActions,
|
|
||||||
setupCustomStatuses,
|
|
||||||
} from '@/utils'
|
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { globalStore } from '@/stores/global'
|
import { globalStore } from '@/stores/global'
|
||||||
import { organizationsStore } from '@/stores/organizations'
|
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import {
|
import {
|
||||||
whatsappEnabled,
|
whatsappEnabled,
|
||||||
@ -304,8 +289,7 @@ import {
|
|||||||
import { ref, computed, h, onMounted } from 'vue'
|
import { ref, computed, h, onMounted } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
const { $dialog } = globalStore()
|
const { $dialog, $socket } = globalStore()
|
||||||
const { organizations, getOrganization } = organizationsStore()
|
|
||||||
const { statusOptions, getDealStatus } = statusesStore()
|
const { statusOptions, getDealStatus } = statusesStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -317,26 +301,45 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const customActions = ref([])
|
||||||
|
const customStatuses = ref([])
|
||||||
|
|
||||||
const deal = createResource({
|
const deal = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_deal.api.get_deal',
|
url: 'crm.fcrm.doctype.crm_deal.api.get_deal',
|
||||||
params: { name: props.dealId },
|
params: { name: props.dealId },
|
||||||
cache: ['deal', props.dealId],
|
cache: ['deal', props.dealId],
|
||||||
onSuccess: (data) => {
|
onSuccess: async (data) => {
|
||||||
|
organization.update({
|
||||||
|
params: { doctype: 'CRM Organization', name: data.organization },
|
||||||
|
})
|
||||||
|
organization.fetch()
|
||||||
let obj = {
|
let obj = {
|
||||||
doc: data,
|
doc: data,
|
||||||
$dialog,
|
$dialog,
|
||||||
|
$socket,
|
||||||
router,
|
router,
|
||||||
updateField,
|
updateField,
|
||||||
createToast,
|
createToast,
|
||||||
deleteDoc: deleteDeal,
|
deleteDoc: deleteDeal,
|
||||||
|
resource: {
|
||||||
|
deal,
|
||||||
|
dealContacts,
|
||||||
|
fieldsLayout,
|
||||||
|
},
|
||||||
call,
|
call,
|
||||||
}
|
}
|
||||||
setupAssignees(data)
|
setupAssignees(data)
|
||||||
setupCustomStatuses(data, obj)
|
let customization = await setupCustomizations(data, obj)
|
||||||
setupCustomActions(data, obj)
|
customActions.value = customization.actions || []
|
||||||
|
customStatuses.value = customization.statuses || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const organization = createResource({
|
||||||
|
url: 'frappe.client.get',
|
||||||
|
onSuccess: (data) => (deal.data._organizationObj = data),
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (deal.data) return
|
if (deal.data) return
|
||||||
deal.fetch()
|
deal.fetch()
|
||||||
@ -347,10 +350,6 @@ const showOrganizationModal = ref(false)
|
|||||||
const showAssignmentModal = ref(false)
|
const showAssignmentModal = ref(false)
|
||||||
const _organization = ref({})
|
const _organization = ref({})
|
||||||
|
|
||||||
const organization = computed(() => {
|
|
||||||
return deal.data?.organization && getOrganization(deal.data.organization)
|
|
||||||
})
|
|
||||||
|
|
||||||
function updateDeal(fieldname, value, callback) {
|
function updateDeal(fieldname, value, callback) {
|
||||||
value = Array.isArray(fieldname) ? '' : value
|
value = Array.isArray(fieldname) ? '' : value
|
||||||
|
|
||||||
@ -419,7 +418,7 @@ const breadcrumbs = computed(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
label: organization.value?.name || __('Untitled'),
|
label: organization.data?.name || __('Untitled'),
|
||||||
route: { name: 'Deal', params: { dealId: deal.data.name } },
|
route: { name: 'Deal', params: { dealId: deal.data.name } },
|
||||||
})
|
})
|
||||||
return items
|
return items
|
||||||
@ -533,7 +532,7 @@ async function addContact(contact) {
|
|||||||
contact,
|
contact,
|
||||||
})
|
})
|
||||||
if (d) {
|
if (d) {
|
||||||
deal_contacts.reload()
|
dealContacts.reload()
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Contact added'),
|
title: __('Contact added'),
|
||||||
icon: 'check',
|
icon: 'check',
|
||||||
@ -548,7 +547,7 @@ async function removeContact(contact) {
|
|||||||
contact,
|
contact,
|
||||||
})
|
})
|
||||||
if (d) {
|
if (d) {
|
||||||
deal_contacts.reload()
|
dealContacts.reload()
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Contact removed'),
|
title: __('Contact removed'),
|
||||||
icon: 'check',
|
icon: 'check',
|
||||||
@ -563,7 +562,7 @@ async function setPrimaryContact(contact) {
|
|||||||
contact,
|
contact,
|
||||||
})
|
})
|
||||||
if (d) {
|
if (d) {
|
||||||
deal_contacts.reload()
|
dealContacts.reload()
|
||||||
createToast({
|
createToast({
|
||||||
title: __('Primary contact set'),
|
title: __('Primary contact set'),
|
||||||
icon: 'check',
|
icon: 'check',
|
||||||
@ -572,7 +571,7 @@ async function setPrimaryContact(contact) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const deal_contacts = createResource({
|
const dealContacts = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_deal.api.get_deal_contacts',
|
url: 'crm.fcrm.doctype.crm_deal.api.get_deal_contacts',
|
||||||
params: { name: props.dealId },
|
params: { name: props.dealId },
|
||||||
cache: ['deal_contacts', props.dealId],
|
cache: ['deal_contacts', props.dealId],
|
||||||
|
|||||||
@ -9,11 +9,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</Breadcrumbs>
|
</Breadcrumbs>
|
||||||
<div class="absolute right-0">
|
<div class="absolute right-0">
|
||||||
<Dropdown
|
<Dropdown :options="statusOptions('lead', updateField, customStatuses)">
|
||||||
:options="
|
|
||||||
statusOptions('lead', updateField, lead.data._customStatuses)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<template #default="{ open }">
|
<template #default="{ open }">
|
||||||
<Button
|
<Button
|
||||||
:label="lead.data.status"
|
:label="lead.data.status"
|
||||||
@ -45,10 +41,7 @@
|
|||||||
/>
|
/>
|
||||||
</component>
|
</component>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<CustomActions
|
<CustomActions v-if="customActions" :actions="customActions" />
|
||||||
v-if="lead.data._customActions"
|
|
||||||
:actions="lead.data._customActions"
|
|
||||||
/>
|
|
||||||
<Button
|
<Button
|
||||||
:label="__('Convert')"
|
:label="__('Convert')"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
@ -84,6 +77,7 @@
|
|||||||
<Section :is-opened="section.opened" :label="section.label">
|
<Section :is-opened="section.opened" :label="section.label">
|
||||||
<SectionFields
|
<SectionFields
|
||||||
:fields="section.fields"
|
:fields="section.fields"
|
||||||
|
:isLastSection="i == fieldsLayout.data.length - 1"
|
||||||
v-model="lead.data"
|
v-model="lead.data"
|
||||||
@update="updateField"
|
@update="updateField"
|
||||||
/>
|
/>
|
||||||
@ -199,16 +193,10 @@ import Section from '@/components/Section.vue'
|
|||||||
import SectionFields from '@/components/SectionFields.vue'
|
import SectionFields from '@/components/SectionFields.vue'
|
||||||
import SLASection from '@/components/SLASection.vue'
|
import SLASection from '@/components/SLASection.vue'
|
||||||
import CustomActions from '@/components/CustomActions.vue'
|
import CustomActions from '@/components/CustomActions.vue'
|
||||||
import {
|
import { createToast, setupAssignees, setupCustomizations } from '@/utils'
|
||||||
createToast,
|
|
||||||
setupAssignees,
|
|
||||||
setupCustomActions,
|
|
||||||
setupCustomStatuses,
|
|
||||||
} from '@/utils'
|
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { globalStore } from '@/stores/global'
|
import { globalStore } from '@/stores/global'
|
||||||
import { contactsStore } from '@/stores/contacts'
|
import { contactsStore } from '@/stores/contacts'
|
||||||
import { organizationsStore } from '@/stores/organizations'
|
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import {
|
import {
|
||||||
whatsappEnabled,
|
whatsappEnabled,
|
||||||
@ -226,9 +214,8 @@ import {
|
|||||||
import { ref, computed, onMounted, watch } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
|
|
||||||
const { $dialog } = globalStore()
|
const { $dialog, $socket } = globalStore()
|
||||||
const { getContactByName, contacts } = contactsStore()
|
const { getContactByName, contacts } = contactsStore()
|
||||||
const { organizations } = organizationsStore()
|
|
||||||
const { statusOptions, getLeadStatus } = statusesStore()
|
const { statusOptions, getLeadStatus } = statusesStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -240,23 +227,32 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const customActions = ref([])
|
||||||
|
const customStatuses = ref([])
|
||||||
|
|
||||||
const lead = createResource({
|
const lead = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_lead.api.get_lead',
|
url: 'crm.fcrm.doctype.crm_lead.api.get_lead',
|
||||||
params: { name: props.leadId },
|
params: { name: props.leadId },
|
||||||
cache: ['lead', props.leadId],
|
cache: ['lead', props.leadId],
|
||||||
onSuccess: (data) => {
|
onSuccess: async (data) => {
|
||||||
let obj = {
|
let obj = {
|
||||||
doc: data,
|
doc: data,
|
||||||
$dialog,
|
$dialog,
|
||||||
|
$socket,
|
||||||
router,
|
router,
|
||||||
updateField,
|
updateField,
|
||||||
createToast,
|
createToast,
|
||||||
deleteDoc: deleteLead,
|
deleteDoc: deleteLead,
|
||||||
|
resource: {
|
||||||
|
lead,
|
||||||
|
fieldsLayout,
|
||||||
|
},
|
||||||
call,
|
call,
|
||||||
}
|
}
|
||||||
setupAssignees(data)
|
setupAssignees(data)
|
||||||
setupCustomStatuses(data, obj)
|
let customization = await setupCustomizations(data, obj)
|
||||||
setupCustomActions(data, obj)
|
customActions.value = customization.actions || []
|
||||||
|
customStatuses.value = customization.statuses || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -496,7 +492,6 @@ async function convertToDeal(updated) {
|
|||||||
)
|
)
|
||||||
if (deal) {
|
if (deal) {
|
||||||
if (updated) {
|
if (updated) {
|
||||||
await organizations.reload()
|
|
||||||
await contacts.reload()
|
await contacts.reload()
|
||||||
}
|
}
|
||||||
router.push({ name: 'Deal', params: { dealId: deal } })
|
router.push({ name: 'Deal', params: { dealId: deal } })
|
||||||
|
|||||||
@ -82,6 +82,7 @@ import {
|
|||||||
dateFormat,
|
dateFormat,
|
||||||
dateTooltipFormat,
|
dateTooltipFormat,
|
||||||
timeAgo,
|
timeAgo,
|
||||||
|
website,
|
||||||
formatNumberIntoCurrency,
|
formatNumberIntoCurrency,
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
@ -130,8 +131,4 @@ const rows = computed(() => {
|
|||||||
return _rows
|
return _rows
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function website(url) {
|
|
||||||
return url && url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '')
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -57,7 +57,7 @@ export function taskStatusOptions(action, data) {
|
|||||||
label: status,
|
label: status,
|
||||||
onClick: () => action && action(status, data),
|
onClick: () => action && action(status, data),
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +72,16 @@ export function taskPriorityOptions(action, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function openWebsite(url) {
|
export function openWebsite(url) {
|
||||||
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
||||||
|
url = 'https://' + url
|
||||||
|
}
|
||||||
window.open(url, '_blank')
|
window.open(url, '_blank')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function website(url) {
|
||||||
|
return url && url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '')
|
||||||
|
}
|
||||||
|
|
||||||
export function htmlToText(html) {
|
export function htmlToText(html) {
|
||||||
const div = document.createElement('div')
|
const div = document.createElement('div')
|
||||||
div.innerHTML = html
|
div.innerHTML = html
|
||||||
@ -125,77 +132,61 @@ export function setupAssignees(data) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActionsFromScript(script, obj) {
|
async function getFromScript(script, obj) {
|
||||||
let scriptFn = new Function(script + '\nreturn setupForm')()
|
let scriptFn = new Function(script + '\nreturn setupForm')()
|
||||||
let formScript = scriptFn(obj)
|
let formScript = await scriptFn(obj)
|
||||||
return formScript?.actions || []
|
return formScript || {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatusFromScript(script, obj) {
|
export async function setupCustomizations(data, obj) {
|
||||||
let scriptFn = new Function(script + '\nreturn setupForm')()
|
|
||||||
let formScript = scriptFn(obj)
|
|
||||||
return formScript?.statuses || []
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setupCustomStatuses(data, obj) {
|
|
||||||
if (!data._form_script) return []
|
if (!data._form_script) return []
|
||||||
|
|
||||||
let statuses = []
|
let statuses = []
|
||||||
|
let actions = []
|
||||||
if (Array.isArray(data._form_script)) {
|
if (Array.isArray(data._form_script)) {
|
||||||
data._form_script.forEach((script) => {
|
for (let script of data._form_script) {
|
||||||
statuses = statuses.concat(getStatusFromScript(script, obj))
|
let _script = await getFromScript(script, obj)
|
||||||
})
|
actions = actions.concat(_script?.actions || [])
|
||||||
|
statuses = statuses.concat(_script?.statuses || [])
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
statuses = getStatusFromScript(data._form_script, data)
|
let _script = await getFromScript(data._form_script, obj)
|
||||||
|
actions = _script?.actions || []
|
||||||
|
statuses = _script?.statuses || []
|
||||||
}
|
}
|
||||||
|
|
||||||
data._customStatuses = statuses
|
data._customStatuses = statuses
|
||||||
}
|
|
||||||
|
|
||||||
export function setupCustomActions(data, obj) {
|
|
||||||
if (!data._form_script) return []
|
|
||||||
|
|
||||||
let actions = []
|
|
||||||
if (Array.isArray(data._form_script)) {
|
|
||||||
data._form_script.forEach((script) => {
|
|
||||||
actions = actions.concat(getActionsFromScript(script, obj))
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
actions = getActionsFromScript(data._form_script, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
data._customActions = actions
|
data._customActions = actions
|
||||||
|
return { statuses, actions }
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActionsFromListScript(script, obj) {
|
async function getListScript(script, obj) {
|
||||||
let scriptFn = new Function(script + '\nreturn setupList')()
|
let scriptFn = new Function(script + '\nreturn setupList')()
|
||||||
let listScript = scriptFn(obj)
|
let listScript = await scriptFn(obj)
|
||||||
return {
|
return listScript || {}
|
||||||
actions: listScript?.actions || [],
|
|
||||||
bulk_actions: listScript?.bulk_actions || [],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setupListActions(data, obj = {}) {
|
export async function setupListCustomizations(data, obj = {}) {
|
||||||
if (!data.list_script) return []
|
if (!data.list_script) return []
|
||||||
|
|
||||||
let actions = []
|
let actions = []
|
||||||
let bulkActions = []
|
let bulkActions = []
|
||||||
|
|
||||||
if (Array.isArray(data.list_script)) {
|
if (Array.isArray(data.list_script)) {
|
||||||
data.list_script.forEach((script) => {
|
for (let script of data.list_script) {
|
||||||
let _actions = getActionsFromListScript(script, obj)
|
let _script = await getListScript(script, obj)
|
||||||
actions = actions.concat(_actions.actions)
|
actions = actions.concat(_script?.actions || [])
|
||||||
bulkActions = bulkActions.concat(_actions.bulk_actions)
|
bulkActions = bulkActions.concat(_script?.bulk_actions || [])
|
||||||
})
|
}
|
||||||
} else {
|
} else {
|
||||||
let _actions = getActionsFromListScript(data.list_script, obj)
|
let _script = await getListScript(data.list_script, obj)
|
||||||
actions = _actions.actions
|
actions = _script?.actions || []
|
||||||
bulkActions = _actions.bulk_actions
|
bulkActions = _script?.bulk_actions || []
|
||||||
}
|
}
|
||||||
|
|
||||||
data.listActions = actions
|
data.listActions = actions
|
||||||
data.bulkActions = bulkActions
|
data.bulkActions = bulkActions
|
||||||
|
return { actions, bulkActions }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function errorMessage(title, message) {
|
export function errorMessage(title, message) {
|
||||||
@ -235,7 +226,7 @@ export function isEmoji(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isTouchScreenDevice() {
|
export function isTouchScreenDevice() {
|
||||||
return "ontouchstart" in document.documentElement;
|
return 'ontouchstart' in document.documentElement
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertArrayToString(array) {
|
export function convertArrayToString(array) {
|
||||||
@ -282,4 +273,4 @@ export function evaluate_depends_on_value(expression, doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user