Merge pull request #352 from shariquerik/crm-erpnext-1
fix: ERPNext Integration fixes & async form/list custom actions
This commit is contained in:
commit
5e5d4756b1
@ -339,7 +339,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-16 19:44:19.553715",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Deal",
|
"name": "CRM Deal",
|
||||||
@ -371,8 +371,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
|
||||||
}
|
}
|
||||||
@ -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",
|
||||||
|
|||||||
@ -291,7 +291,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-16 19:46:01.307171",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "CRM Lead",
|
"name": "CRM Lead",
|
||||||
@ -325,6 +325,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": [],
|
||||||
|
|||||||
@ -6,29 +6,33 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"enabled",
|
"enabled",
|
||||||
"is_erpnext_in_the_current_site",
|
"is_erpnext_in_different_site",
|
||||||
"column_break_vfru",
|
"column_break_vfru",
|
||||||
"erpnext_company",
|
"erpnext_company",
|
||||||
"section_break_oubd",
|
"section_break_oubd",
|
||||||
"erpnext_site_url",
|
"erpnext_site_url",
|
||||||
"column_break_fllx",
|
"column_break_fllx",
|
||||||
"api_key",
|
"api_key",
|
||||||
"api_secret"
|
"api_secret",
|
||||||
|
"section_break_jnbn",
|
||||||
|
"create_customer_on_status_change",
|
||||||
|
"column_break_kbhw",
|
||||||
|
"deal_status"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.enabled && !doc.is_erpnext_in_the_current_site",
|
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||||
"fieldname": "api_key",
|
"fieldname": "api_key",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "API Key",
|
"label": "API Key",
|
||||||
"mandatory_depends_on": "eval:!doc.is_erpnext_in_the_current_site"
|
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.enabled && !doc.is_erpnext_in_the_current_site",
|
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||||
"fieldname": "api_secret",
|
"fieldname": "api_secret",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "API Secret",
|
"label": "API Secret",
|
||||||
"mandatory_depends_on": "eval:!doc.is_erpnext_in_the_current_site"
|
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "enabled",
|
"depends_on": "enabled",
|
||||||
@ -40,11 +44,11 @@
|
|||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.enabled && !doc.is_erpnext_in_the_current_site",
|
"depends_on": "eval:doc.enabled && doc.is_erpnext_in_different_site",
|
||||||
"fieldname": "erpnext_site_url",
|
"fieldname": "erpnext_site_url",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"label": "ERPNext Site URL",
|
"label": "ERPNext Site URL",
|
||||||
"mandatory_depends_on": "eval:!doc.is_erpnext_in_the_current_site"
|
"mandatory_depends_on": "is_erpnext_in_different_site"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "enabled",
|
"depends_on": "enabled",
|
||||||
@ -57,24 +61,47 @@
|
|||||||
"fieldname": "column_break_vfru",
|
"fieldname": "column_break_vfru",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"default": "0",
|
|
||||||
"depends_on": "enabled",
|
|
||||||
"fieldname": "is_erpnext_in_the_current_site",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"label": "Is ERPNext in the current site?"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"default": "0",
|
"default": "0",
|
||||||
"fieldname": "enabled",
|
"fieldname": "enabled",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Enabled"
|
"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,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-09-13 15:06:23.317262",
|
"modified": "2024-09-16 21:30:40.097360",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "ERPNext CRM Settings",
|
"name": "ERPNext CRM Settings",
|
||||||
|
|||||||
@ -18,12 +18,12 @@ class ERPNextCRMSettings(Document):
|
|||||||
self.create_crm_form_script()
|
self.create_crm_form_script()
|
||||||
|
|
||||||
def validate_if_erpnext_installed(self):
|
def validate_if_erpnext_installed(self):
|
||||||
if self.is_erpnext_in_the_current_site:
|
if not self.is_erpnext_in_different_site:
|
||||||
if "erpnext" not in frappe.get_installed_apps():
|
if "erpnext" not in frappe.get_installed_apps():
|
||||||
frappe.throw(_("ERPNext is not installed in the current site"))
|
frappe.throw(_("ERPNext is not installed in the current site"))
|
||||||
|
|
||||||
def add_quotation_to_option(self):
|
def add_quotation_to_option(self):
|
||||||
if self.is_erpnext_in_the_current_site:
|
if not self.is_erpnext_in_different_site:
|
||||||
if not frappe.db.exists("Property Setter", {"name": "Quotation-quotation_to-link_filters"}):
|
if not frappe.db.exists("Property Setter", {"name": "Quotation-quotation_to-link_filters"}):
|
||||||
make_property_setter(
|
make_property_setter(
|
||||||
doctype="Quotation",
|
doctype="Quotation",
|
||||||
@ -35,7 +35,7 @@ class ERPNextCRMSettings(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def create_custom_fields(self):
|
def create_custom_fields(self):
|
||||||
if self.is_erpnext_in_the_current_site:
|
if not self.is_erpnext_in_different_site:
|
||||||
from erpnext.crm.frappe_crm_api import create_custom_fields_for_frappe_crm
|
from erpnext.crm.frappe_crm_api import create_custom_fields_for_frappe_crm
|
||||||
create_custom_fields_for_frappe_crm()
|
create_custom_fields_for_frappe_crm()
|
||||||
else:
|
else:
|
||||||
@ -80,7 +80,7 @@ def get_quotation_url(crm_deal, organization):
|
|||||||
if not erpnext_crm_settings.enabled:
|
if not erpnext_crm_settings.enabled:
|
||||||
frappe.throw(_("ERPNext is not integrated with the CRM"))
|
frappe.throw(_("ERPNext is not integrated with the CRM"))
|
||||||
|
|
||||||
if erpnext_crm_settings.is_erpnext_in_the_current_site:
|
if not erpnext_crm_settings.is_erpnext_in_different_site:
|
||||||
quotation_url = get_url_to_form("Quotation")
|
quotation_url = get_url_to_form("Quotation")
|
||||||
return f"{quotation_url}/new?quotation_to=CRM Deal&crm_deal={crm_deal}&party_name={crm_deal}"
|
return f"{quotation_url}/new?quotation_to=CRM Deal&crm_deal={crm_deal}&party_name={crm_deal}"
|
||||||
else:
|
else:
|
||||||
@ -95,6 +95,7 @@ def create_prospect_in_remote_site(crm_deal, erpnext_crm_settings):
|
|||||||
client = get_erpnext_site_client(erpnext_crm_settings)
|
client = get_erpnext_site_client(erpnext_crm_settings)
|
||||||
doc = frappe.get_doc("CRM Deal", crm_deal)
|
doc = frappe.get_doc("CRM Deal", crm_deal)
|
||||||
contacts = get_contacts(doc)
|
contacts = get_contacts(doc)
|
||||||
|
address = get_organization_address(doc.organization)
|
||||||
return client.post_api("erpnext.crm.frappe_crm_api.create_prospect_against_crm_deal",
|
return client.post_api("erpnext.crm.frappe_crm_api.create_prospect_against_crm_deal",
|
||||||
{
|
{
|
||||||
"organization": doc.organization,
|
"organization": doc.organization,
|
||||||
@ -107,7 +108,8 @@ def create_prospect_in_remote_site(crm_deal, erpnext_crm_settings):
|
|||||||
"website": doc.website,
|
"website": doc.website,
|
||||||
"annual_revenue": doc.annual_revenue,
|
"annual_revenue": doc.annual_revenue,
|
||||||
"contacts": json.dumps(contacts),
|
"contacts": json.dumps(contacts),
|
||||||
"erpnext_company": erpnext_crm_settings.erpnext_company
|
"erpnext_company": erpnext_crm_settings.erpnext_company,
|
||||||
|
"address": address.as_dict() if address else None
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -130,12 +132,22 @@ def get_contacts(doc):
|
|||||||
})
|
})
|
||||||
return contacts
|
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):
|
def create_customer_in_erpnext(doc, method):
|
||||||
erpnext_crm_settings = frappe.get_single("ERPNext CRM Settings")
|
erpnext_crm_settings = frappe.get_single("ERPNext CRM Settings")
|
||||||
if not erpnext_crm_settings.enabled or doc.status != "Won":
|
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
|
return
|
||||||
|
|
||||||
contacts = get_contacts(doc)
|
contacts = get_contacts(doc)
|
||||||
|
address = get_organization_address(doc.organization)
|
||||||
customer = {
|
customer = {
|
||||||
"customer_name": doc.organization,
|
"customer_name": doc.organization,
|
||||||
"customer_group": "All Customer Groups",
|
"customer_group": "All Customer Groups",
|
||||||
@ -146,12 +158,15 @@ def create_customer_in_erpnext(doc, method):
|
|||||||
"website": doc.website,
|
"website": doc.website,
|
||||||
"crm_deal": doc.name,
|
"crm_deal": doc.name,
|
||||||
"contacts": json.dumps(contacts),
|
"contacts": json.dumps(contacts),
|
||||||
|
"address": address.as_dict() if address else None,
|
||||||
}
|
}
|
||||||
if erpnext_crm_settings.is_erpnext_in_the_current_site:
|
if not erpnext_crm_settings.is_erpnext_in_different_site:
|
||||||
from erpnext.crm.frappe_crm_api import create_customer
|
from erpnext.crm.frappe_crm_api import create_customer
|
||||||
create_customer(customer)
|
create_customer(customer)
|
||||||
else:
|
else:
|
||||||
create_customer_in_remote_site(customer, erpnext_crm_settings)
|
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):
|
def create_customer_in_remote_site(customer, erpnext_crm_settings):
|
||||||
client = get_erpnext_site_client(erpnext_crm_settings)
|
client = get_erpnext_site_client(erpnext_crm_settings)
|
||||||
@ -166,9 +181,10 @@ def create_customer_in_remote_site(customer, erpnext_crm_settings):
|
|||||||
|
|
||||||
def get_crm_form_script():
|
def get_crm_form_script():
|
||||||
return """
|
return """
|
||||||
function setupForm({ doc, call, $dialog, updateField, createToast }) {
|
async function setupForm({ doc, call, $dialog, updateField, createToast }) {
|
||||||
let actions = [];
|
let actions = [];
|
||||||
if (!["Lost", "Won"].includes(doc?.status)) {
|
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({
|
actions.push({
|
||||||
label: __("Create Quotation"),
|
label: __("Create Quotation"),
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
(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
|
||||||
@ -36,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'"
|
||||||
|
|||||||
@ -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({
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<SettingsPage doctype="ERPNext CRM Settings" :title="__('ERPNext Settings')" class="p-8" />
|
<SettingsPage
|
||||||
|
doctype="ERPNext CRM Settings"
|
||||||
|
:title="__('ERPNext Settings')"
|
||||||
|
:successMessage="__('ERPNext Settings updated')"
|
||||||
|
class="p-8"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import SettingsPage from '@/components/Settings/SettingsPage.vue'
|
import SettingsPage from '@/components/Settings/SettingsPage.vue'
|
||||||
</script>
|
</script>
|
||||||
@ -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,9 +37,10 @@ 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: {
|
||||||
@ -65,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,
|
||||||
@ -73,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),
|
||||||
@ -117,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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -130,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>
|
||||||
|
|||||||
@ -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"
|
||||||
@ -172,7 +167,7 @@
|
|||||||
<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 +175,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 +252,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>
|
||||||
@ -340,8 +335,7 @@ import {
|
|||||||
openWebsite,
|
openWebsite,
|
||||||
createToast,
|
createToast,
|
||||||
setupAssignees,
|
setupAssignees,
|
||||||
setupCustomActions,
|
setupCustomizations,
|
||||||
setupCustomStatuses,
|
|
||||||
errorMessage,
|
errorMessage,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
@ -361,10 +355,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 { organizations, getOrganization } = organizationsStore()
|
||||||
const { statusOptions, getDealStatus } = statusesStore()
|
const { statusOptions, getDealStatus } = statusesStore()
|
||||||
const { isManager } = usersStore()
|
const { isManager } = usersStore()
|
||||||
@ -378,31 +372,53 @@ 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) => {
|
||||||
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 || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
$socket.on('crm_customer_created', () => {
|
||||||
|
createToast({
|
||||||
|
title: __('Customer created successfully'),
|
||||||
|
icon: 'check',
|
||||||
|
iconClasses: 'text-green-600',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
if (deal.data) return
|
if (deal.data) 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)
|
||||||
@ -595,7 +611,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 +626,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 +641,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 +650,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 +664,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) {
|
||||||
|
|||||||
@ -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"
|
||||||
@ -307,8 +304,7 @@ import {
|
|||||||
openWebsite,
|
openWebsite,
|
||||||
createToast,
|
createToast,
|
||||||
setupAssignees,
|
setupAssignees,
|
||||||
setupCustomActions,
|
setupCustomizations,
|
||||||
setupCustomStatuses,
|
|
||||||
errorMessage,
|
errorMessage,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
} from '@/utils'
|
} from '@/utils'
|
||||||
@ -335,7 +331,7 @@ 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 { organizations } = organizationsStore()
|
||||||
const { statusOptions, getLeadStatus } = statusesStore()
|
const { statusOptions, getLeadStatus } = statusesStore()
|
||||||
@ -350,23 +346,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 || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -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">
|
||||||
@ -114,7 +107,7 @@
|
|||||||
<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"
|
||||||
>
|
>
|
||||||
@ -278,12 +271,7 @@ 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 { organizationsStore } from '@/stores/organizations'
|
||||||
@ -304,7 +292,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 { organizations, getOrganization } = organizationsStore()
|
||||||
const { statusOptions, getDealStatus } = statusesStore()
|
const { statusOptions, getDealStatus } = statusesStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -317,23 +305,33 @@ 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) => {
|
||||||
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 || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -533,7 +531,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 +546,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 +561,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 +570,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"
|
||||||
@ -199,12 +192,7 @@ 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'
|
||||||
@ -226,7 +214,7 @@ 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 { organizations } = organizationsStore()
|
||||||
const { statusOptions, getLeadStatus } = statusesStore()
|
const { statusOptions, getLeadStatus } = statusesStore()
|
||||||
@ -240,23 +228,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 || []
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ export function taskStatusOptions(action, data) {
|
|||||||
label: status,
|
label: status,
|
||||||
onClick: () => action && action(status, data),
|
onClick: () => action && action(status, data),
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,77 +125,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, data)
|
||||||
|
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 +219,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 +266,4 @@ export function evaluate_depends_on_value(expression, doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user