fix: handle new document for lead/deal/contact/organization
(cherry picked from commit c4feed116dcccdf23cc346557c36b3e719111e29) # Conflicts: # frontend/src/components/Modals/OrganizationModal.vue
This commit is contained in:
parent
82414cff7d
commit
5358b5fdba
@ -25,7 +25,7 @@
|
||||
<FieldLayout
|
||||
v-if="tabs.data?.length"
|
||||
:tabs="tabs.data"
|
||||
:data="_contact"
|
||||
:data="_contact.doc"
|
||||
doctype="Contact"
|
||||
/>
|
||||
</div>
|
||||
@ -49,9 +49,10 @@ import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
||||
import EditIcon from '@/components/Icons/EditIcon.vue'
|
||||
import { usersStore } from '@/stores/users'
|
||||
import { isMobileView } from '@/composables/settings'
|
||||
import { useDocument } from '@/data/document'
|
||||
import { capture } from '@/telemetry'
|
||||
import { call, createResource } from 'frappe-ui'
|
||||
import { ref, nextTick, watch } from 'vue'
|
||||
import { ref, nextTick, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const props = defineProps({
|
||||
@ -77,23 +78,27 @@ const show = defineModel()
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
let _contact = ref({})
|
||||
const { document: _contact } = useDocument('Contact')
|
||||
|
||||
if (Object.keys(_contact.doc).length != 0) {
|
||||
_contact.doc = {}
|
||||
}
|
||||
|
||||
async function createContact() {
|
||||
if (_contact.value.email_id) {
|
||||
_contact.value.email_ids = [{ email_id: _contact.value.email_id }]
|
||||
delete _contact.value.email_id
|
||||
if (_contact.doc.email_id) {
|
||||
_contact.doc.email_ids = [{ email_id: _contact.doc.email_id }]
|
||||
delete _contact.doc.email_id
|
||||
}
|
||||
|
||||
if (_contact.value.mobile_no) {
|
||||
_contact.value.phone_nos = [{ phone: _contact.value.mobile_no }]
|
||||
delete _contact.value.mobile_no
|
||||
if (_contact.doc.mobile_no) {
|
||||
_contact.doc.phone_nos = [{ phone: _contact.doc.mobile_no }]
|
||||
delete _contact.doc.mobile_no
|
||||
}
|
||||
|
||||
const doc = await call('frappe.client.insert', {
|
||||
doc: {
|
||||
doctype: 'Contact',
|
||||
..._contact.value,
|
||||
..._contact.doc,
|
||||
},
|
||||
})
|
||||
if (doc.name) {
|
||||
@ -130,7 +135,7 @@ const tabs = createResource({
|
||||
field.read_only = false
|
||||
} else if (field.fieldname == 'address') {
|
||||
field.create = (value, close) => {
|
||||
_contact.value.address = value
|
||||
_contact.doc.address = value
|
||||
emit('openAddressModal')
|
||||
show.value = false
|
||||
close()
|
||||
@ -140,7 +145,7 @@ const tabs = createResource({
|
||||
show.value = false
|
||||
}
|
||||
} else if (field.fieldtype === 'Table') {
|
||||
_contact.value[field.fieldname] = []
|
||||
_contact.doc[field.fieldname] = []
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -149,16 +154,9 @@ const tabs = createResource({
|
||||
},
|
||||
})
|
||||
|
||||
watch(
|
||||
() => show.value,
|
||||
(value) => {
|
||||
if (!value) return
|
||||
nextTick(() => {
|
||||
_contact.value = { ...props.contact.data }
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
Object.assign(_contact.doc, props.contact.data || props.contact || {})
|
||||
})
|
||||
const showQuickEntryModal = defineModel('showQuickEntryModal')
|
||||
|
||||
function openQuickEntryModal() {
|
||||
|
||||
@ -50,7 +50,7 @@
|
||||
ref="fieldLayoutRef"
|
||||
v-if="tabs.data?.length"
|
||||
:tabs="tabs.data"
|
||||
:data="deal"
|
||||
:data="deal.doc"
|
||||
doctype="CRM Deal"
|
||||
/>
|
||||
<ErrorMessage class="mt-4" v-if="error" :message="__(error)" />
|
||||
@ -76,9 +76,10 @@ import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
||||
import { usersStore } from '@/stores/users'
|
||||
import { statusesStore } from '@/stores/statuses'
|
||||
import { isMobileView } from '@/composables/settings'
|
||||
import { useDocument } from '@/data/document'
|
||||
import { capture } from '@/telemetry'
|
||||
import { Switch, createResource } from 'frappe-ui'
|
||||
import { computed, ref, reactive, onMounted, nextTick, watch } from 'vue'
|
||||
import { computed, ref, onMounted, nextTick, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const props = defineProps({
|
||||
@ -92,24 +93,11 @@ const show = defineModel()
|
||||
const router = useRouter()
|
||||
const error = ref(null)
|
||||
|
||||
const deal = reactive({
|
||||
organization: '',
|
||||
organization_name: '',
|
||||
website: '',
|
||||
no_of_employees: '',
|
||||
territory: '',
|
||||
annual_revenue: '',
|
||||
industry: '',
|
||||
contact: '',
|
||||
salutation: '',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
email: '',
|
||||
mobile_no: '',
|
||||
gender: '',
|
||||
status: '',
|
||||
deal_owner: '',
|
||||
})
|
||||
const { document: deal } = useDocument('CRM Deal')
|
||||
|
||||
if (Object.keys(deal.doc).length != 0) {
|
||||
deal.doc = {}
|
||||
}
|
||||
|
||||
const hasOrganizationSections = ref(true)
|
||||
const hasContactSections = ref(true)
|
||||
@ -165,11 +153,11 @@ const tabs = createResource({
|
||||
if (field.fieldname == 'status') {
|
||||
field.fieldtype = 'Select'
|
||||
field.options = dealStatuses.value
|
||||
field.prefix = getDealStatus(deal.status).color
|
||||
field.prefix = getDealStatus(deal.doc.status).color
|
||||
}
|
||||
|
||||
if (field.fieldtype === 'Table') {
|
||||
deal[field.fieldname] = []
|
||||
deal.doc[field.fieldname] = []
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -180,46 +168,49 @@ const tabs = createResource({
|
||||
|
||||
const dealStatuses = computed(() => {
|
||||
let statuses = statusOptions('deal')
|
||||
if (!deal.status) {
|
||||
deal.status = statuses[0].value
|
||||
if (!deal.doc.status) {
|
||||
deal.doc.status = statuses[0].value
|
||||
}
|
||||
return statuses
|
||||
})
|
||||
|
||||
function createDeal() {
|
||||
if (deal.website && !deal.website.startsWith('http')) {
|
||||
deal.website = 'https://' + deal.website
|
||||
if (deal.doc.website && !deal.doc.website.startsWith('http')) {
|
||||
deal.doc.website = 'https://' + deal.doc.website
|
||||
}
|
||||
if (chooseExistingContact.value) {
|
||||
deal['first_name'] = null
|
||||
deal['last_name'] = null
|
||||
deal['email'] = null
|
||||
deal['mobile_no'] = null
|
||||
} else deal['contact'] = null
|
||||
deal.doc['first_name'] = null
|
||||
deal.doc['last_name'] = null
|
||||
deal.doc['email'] = null
|
||||
deal.doc['mobile_no'] = null
|
||||
} else deal.doc['contact'] = null
|
||||
|
||||
createResource({
|
||||
url: 'crm.fcrm.doctype.crm_deal.crm_deal.create_deal',
|
||||
params: { args: deal },
|
||||
params: { args: deal.doc },
|
||||
auto: true,
|
||||
validate() {
|
||||
error.value = null
|
||||
if (deal.annual_revenue) {
|
||||
if (typeof deal.annual_revenue === 'string') {
|
||||
deal.annual_revenue = deal.annual_revenue.replace(/,/g, '')
|
||||
} else if (isNaN(deal.annual_revenue)) {
|
||||
if (deal.doc.annual_revenue) {
|
||||
if (typeof deal.doc.annual_revenue === 'string') {
|
||||
deal.doc.annual_revenue = deal.doc.annual_revenue.replace(/,/g, '')
|
||||
} else if (isNaN(deal.doc.annual_revenue)) {
|
||||
error.value = __('Annual Revenue should be a number')
|
||||
return error.value
|
||||
}
|
||||
}
|
||||
if (deal.mobile_no && isNaN(deal.mobile_no.replace(/[-+() ]/g, ''))) {
|
||||
if (
|
||||
deal.doc.mobile_no &&
|
||||
isNaN(deal.doc.mobile_no.replace(/[-+() ]/g, ''))
|
||||
) {
|
||||
error.value = __('Mobile No should be a number')
|
||||
return error.value
|
||||
}
|
||||
if (deal.email && !deal.email.includes('@')) {
|
||||
if (deal.doc.email && !deal.doc.email.includes('@')) {
|
||||
error.value = __('Invalid Email')
|
||||
return error.value
|
||||
}
|
||||
if (!deal.status) {
|
||||
if (!deal.doc.status) {
|
||||
error.value = __('Status is required')
|
||||
return error.value
|
||||
}
|
||||
@ -252,12 +243,12 @@ function openQuickEntryModal() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
Object.assign(deal, props.defaults)
|
||||
if (!deal.deal_owner) {
|
||||
deal.deal_owner = getUser().name
|
||||
Object.assign(deal.doc, props.defaults)
|
||||
if (!deal.doc.deal_owner) {
|
||||
deal.doc.deal_owner = getUser().name
|
||||
}
|
||||
if (!deal.status && dealStatuses.value[0].value) {
|
||||
deal.status = dealStatuses.value[0].value
|
||||
if (!deal.doc.status && dealStatuses.value[0].value) {
|
||||
deal.doc.status = dealStatuses.value[0].value
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<FieldLayout v-if="tabs.data" :tabs="tabs.data" :data="lead" />
|
||||
<FieldLayout v-if="tabs.data" :tabs="tabs.data" :data="lead.doc" />
|
||||
<ErrorMessage class="mt-4" v-if="error" :message="__(error)" />
|
||||
</div>
|
||||
</div>
|
||||
@ -51,7 +51,8 @@ import { isMobileView } from '@/composables/settings'
|
||||
import { capture } from '@/telemetry'
|
||||
import { createResource } from 'frappe-ui'
|
||||
import { useOnboarding } from 'frappe-ui/frappe'
|
||||
import { computed, onMounted, ref, reactive, nextTick } from 'vue'
|
||||
import { useDocument } from '@/data/document'
|
||||
import { computed, onMounted, ref, nextTick } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const props = defineProps({
|
||||
@ -68,6 +69,20 @@ const router = useRouter()
|
||||
const error = ref(null)
|
||||
const isLeadCreating = ref(false)
|
||||
|
||||
const { document: lead } = useDocument('CRM Lead')
|
||||
|
||||
if (Object.keys(lead.doc).length != 0) {
|
||||
lead.doc = {}
|
||||
}
|
||||
|
||||
const leadStatuses = computed(() => {
|
||||
let statuses = statusOptions('lead')
|
||||
if (!lead.doc.status) {
|
||||
lead.doc.status = statuses?.[0]?.value
|
||||
}
|
||||
return statuses
|
||||
})
|
||||
|
||||
const tabs = createResource({
|
||||
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||
cache: ['QuickEntry', 'CRM Lead'],
|
||||
@ -81,11 +96,11 @@ const tabs = createResource({
|
||||
if (field.fieldname == 'status') {
|
||||
field.fieldtype = 'Select'
|
||||
field.options = leadStatuses.value
|
||||
field.prefix = getLeadStatus(lead.status).color
|
||||
field.prefix = getLeadStatus(lead.doc.status).color
|
||||
}
|
||||
|
||||
if (field.fieldtype === 'Table') {
|
||||
lead[field.fieldname] = []
|
||||
lead.doc[field.fieldname] = []
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -94,23 +109,6 @@ const tabs = createResource({
|
||||
},
|
||||
})
|
||||
|
||||
const lead = reactive({
|
||||
salutation: '',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
email: '',
|
||||
mobile_no: '',
|
||||
gender: '',
|
||||
organization: '',
|
||||
website: '',
|
||||
no_of_employees: '',
|
||||
territory: '',
|
||||
annual_revenue: '',
|
||||
industry: '',
|
||||
status: '',
|
||||
lead_owner: '',
|
||||
})
|
||||
|
||||
const createLead = createResource({
|
||||
url: 'frappe.client.insert',
|
||||
makeParams(values) {
|
||||
@ -123,43 +121,38 @@ const createLead = createResource({
|
||||
},
|
||||
})
|
||||
|
||||
const leadStatuses = computed(() => {
|
||||
let statuses = statusOptions('lead')
|
||||
if (!lead.status) {
|
||||
lead.status = statuses?.[0]?.value
|
||||
}
|
||||
return statuses
|
||||
})
|
||||
|
||||
function createNewLead() {
|
||||
if (lead.website && !lead.website.startsWith('http')) {
|
||||
lead.website = 'https://' + lead.website
|
||||
if (lead.doc.website && !lead.doc.website.startsWith('http')) {
|
||||
lead.doc.website = 'https://' + lead.doc.website
|
||||
}
|
||||
|
||||
createLead.submit(lead, {
|
||||
createLead.submit(lead.doc, {
|
||||
validate() {
|
||||
error.value = null
|
||||
if (!lead.first_name) {
|
||||
if (!lead.doc.first_name) {
|
||||
error.value = __('First Name is mandatory')
|
||||
return error.value
|
||||
}
|
||||
if (lead.annual_revenue) {
|
||||
if (typeof lead.annual_revenue === 'string') {
|
||||
lead.annual_revenue = lead.annual_revenue.replace(/,/g, '')
|
||||
} else if (isNaN(lead.annual_revenue)) {
|
||||
if (lead.doc.annual_revenue) {
|
||||
if (typeof lead.doc.annual_revenue === 'string') {
|
||||
lead.doc.annual_revenue = lead.doc.annual_revenue.replace(/,/g, '')
|
||||
} else if (isNaN(lead.doc.annual_revenue)) {
|
||||
error.value = __('Annual Revenue should be a number')
|
||||
return error.value
|
||||
}
|
||||
}
|
||||
if (lead.mobile_no && isNaN(lead.mobile_no.replace(/[-+() ]/g, ''))) {
|
||||
if (
|
||||
lead.doc.mobile_no &&
|
||||
isNaN(lead.doc.mobile_no.replace(/[-+() ]/g, ''))
|
||||
) {
|
||||
error.value = __('Mobile No should be a number')
|
||||
return error.value
|
||||
}
|
||||
if (lead.email && !lead.email.includes('@')) {
|
||||
if (lead.doc.email && !lead.doc.email.includes('@')) {
|
||||
error.value = __('Invalid Email')
|
||||
return error.value
|
||||
}
|
||||
if (!lead.status) {
|
||||
if (!lead.doc.status) {
|
||||
error.value = __('Status is required')
|
||||
return error.value
|
||||
}
|
||||
@ -195,12 +188,12 @@ function openQuickEntryModal() {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
Object.assign(lead, props.defaults)
|
||||
if (!lead.lead_owner) {
|
||||
lead.lead_owner = getUser().name
|
||||
Object.assign(lead.doc, props.defaults)
|
||||
if (!lead.doc?.lead_owner) {
|
||||
lead.doc.lead_owner = getUser().name
|
||||
}
|
||||
if (!lead.status && leadStatuses.value[0]?.value) {
|
||||
lead.status = leadStatuses.value[0].value
|
||||
if (!lead.doc?.status && leadStatuses.value[0]?.value) {
|
||||
lead.doc.status = leadStatuses.value[0].value
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -15,7 +15,11 @@
|
||||
class="w-7"
|
||||
@click="openQuickEntryModal"
|
||||
>
|
||||
<<<<<<< HEAD
|
||||
<EditIcon class="h-4 w-4" />
|
||||
=======
|
||||
<EditIcon class="w-4 h-4" />
|
||||
>>>>>>> c4feed1 (fix: handle new document for lead/deal/contact/organization)
|
||||
</Button>
|
||||
<Button variant="ghost" class="w-7" @click="show = false">
|
||||
<FeatherIcon name="x" class="h-4 w-4" />
|
||||
@ -25,9 +29,16 @@
|
||||
<FieldLayout
|
||||
v-if="tabs.data?.length"
|
||||
:tabs="tabs.data"
|
||||
<<<<<<< HEAD
|
||||
:data="_organization"
|
||||
doctype="CRM Organization"
|
||||
/>
|
||||
=======
|
||||
:data="_organization.doc"
|
||||
doctype="CRM Organization"
|
||||
/>
|
||||
<ErrorMessage class="mt-8" v-if="error" :message="__(error)" />
|
||||
>>>>>>> c4feed1 (fix: handle new document for lead/deal/contact/organization)
|
||||
</div>
|
||||
<div class="px-4 pb-7 pt-4 sm:px-6">
|
||||
<div class="space-y-2">
|
||||
@ -49,9 +60,10 @@ import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
||||
import EditIcon from '@/components/Icons/EditIcon.vue'
|
||||
import { usersStore } from '@/stores/users'
|
||||
import { isMobileView } from '@/composables/settings'
|
||||
import { useDocument } from '@/data/document'
|
||||
import { capture } from '@/telemetry'
|
||||
import { call, FeatherIcon, createResource } from 'frappe-ui'
|
||||
import { ref, nextTick, watch } from 'vue'
|
||||
import { ref, nextTick, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const props = defineProps({
|
||||
@ -75,23 +87,35 @@ const organization = defineModel('organization')
|
||||
const loading = ref(false)
|
||||
const title = ref(null)
|
||||
|
||||
let _organization = ref({
|
||||
organization_name: '',
|
||||
website: '',
|
||||
annual_revenue: '',
|
||||
no_of_employees: '1-10',
|
||||
industry: '',
|
||||
})
|
||||
const { document: _organization } = useDocument('CRM Organization')
|
||||
|
||||
if (Object.keys(_organization.doc).length != 0) {
|
||||
_organization.doc = { no_of_employees: '1-10' }
|
||||
}
|
||||
|
||||
let doc = ref({})
|
||||
|
||||
async function createOrganization() {
|
||||
const doc = await call('frappe.client.insert', {
|
||||
doc: {
|
||||
doctype: 'CRM Organization',
|
||||
..._organization.value,
|
||||
const doc = await call(
|
||||
'frappe.client.insert',
|
||||
{
|
||||
doc: {
|
||||
doctype: 'CRM Organization',
|
||||
..._organization.doc,
|
||||
},
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
})
|
||||
=======
|
||||
{
|
||||
onError: (err) => {
|
||||
if (err.error.exc_type == 'ValidationError') {
|
||||
error.value = err.error?.messages?.[0]
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
>>>>>>> c4feed1 (fix: handle new document for lead/deal/contact/organization)
|
||||
loading.value = false
|
||||
if (doc.name) {
|
||||
capture('organization_created')
|
||||
@ -124,7 +148,7 @@ const tabs = createResource({
|
||||
column.fields.forEach((field) => {
|
||||
if (field.fieldname == 'address') {
|
||||
field.create = (value, close) => {
|
||||
_organization.value.address = value
|
||||
_organization.doc.address = value
|
||||
emit('openAddressModal')
|
||||
show.value = false
|
||||
close()
|
||||
@ -134,7 +158,7 @@ const tabs = createResource({
|
||||
show.value = false
|
||||
}
|
||||
} else if (field.fieldtype === 'Table') {
|
||||
_organization.value[field.fieldname] = []
|
||||
_organization.doc[field.fieldname] = []
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -143,19 +167,12 @@ const tabs = createResource({
|
||||
},
|
||||
})
|
||||
|
||||
watch(
|
||||
() => show.value,
|
||||
(value) => {
|
||||
if (!value) return
|
||||
nextTick(() => {
|
||||
// TODO: Issue with FormControl
|
||||
// title.value.el.focus()
|
||||
doc.value = organization.value?.doc || organization.value || {}
|
||||
_organization.value = { ...doc.value }
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
Object.assign(
|
||||
_organization.doc,
|
||||
organization.value?.doc || organization.value || {},
|
||||
)
|
||||
})
|
||||
const showQuickEntryModal = defineModel('showQuickEntryModal')
|
||||
|
||||
function openQuickEntryModal() {
|
||||
|
||||
@ -280,6 +280,7 @@
|
||||
}"
|
||||
/>
|
||||
<ContactModal
|
||||
v-if="showContactModal"
|
||||
v-model="showContactModal"
|
||||
:contact="_contact"
|
||||
:options="{
|
||||
|
||||
@ -222,6 +222,7 @@
|
||||
}"
|
||||
/>
|
||||
<ContactModal
|
||||
v-if="showContactModal"
|
||||
v-model="showContactModal"
|
||||
:contact="_contact"
|
||||
:options="{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user