fix: option to create customer on status change
This commit is contained in:
parent
cb33d2d3f2
commit
979ef27a9d
@ -13,7 +13,11 @@
|
|||||||
"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": [
|
||||||
{
|
{
|
||||||
@ -69,12 +73,34 @@
|
|||||||
"fieldname": "is_erpnext_in_different_site",
|
"fieldname": "is_erpnext_in_different_site",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Is ERPNext installed on a different site?"
|
"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": "create_customer_on_status_change",
|
||||||
|
"fieldname": "deal_status",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Deal Status",
|
||||||
|
"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-16 13:51:35.141503",
|
"modified": "2024-09-16 19:01:28.694010",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "FCRM",
|
"module": "FCRM",
|
||||||
"name": "ERPNext CRM Settings",
|
"name": "ERPNext CRM Settings",
|
||||||
|
|||||||
@ -139,7 +139,11 @@ def get_organization_address(organization):
|
|||||||
|
|
||||||
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)
|
||||||
@ -160,7 +164,9 @@ def create_customer_in_erpnext(doc, method):
|
|||||||
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)
|
||||||
|
|||||||
@ -361,10 +361,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()
|
||||||
@ -386,10 +386,16 @@ const deal = createResource({
|
|||||||
let obj = {
|
let obj = {
|
||||||
doc: data,
|
doc: data,
|
||||||
$dialog,
|
$dialog,
|
||||||
|
$socket,
|
||||||
router,
|
router,
|
||||||
updateField,
|
updateField,
|
||||||
createToast,
|
createToast,
|
||||||
deleteDoc: deleteDeal,
|
deleteDoc: deleteDeal,
|
||||||
|
resource: {
|
||||||
|
deal,
|
||||||
|
deal_contacts,
|
||||||
|
fieldsLayout,
|
||||||
|
},
|
||||||
call,
|
call,
|
||||||
}
|
}
|
||||||
setupAssignees(data)
|
setupAssignees(data)
|
||||||
@ -399,10 +405,22 @@ const deal = createResource({
|
|||||||
})
|
})
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@ -335,7 +335,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()
|
||||||
@ -358,10 +358,15 @@ const lead = createResource({
|
|||||||
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user