1
0
forked from test/crm

feat: added callback to update link field value after creating new

(cherry picked from commit 91ba11b5653a08a431e233c8d55297a5cec70277)
This commit is contained in:
Shariq Ansari 2025-05-14 14:04:25 +05:30 committed by Mergify
parent 48dd017dd2
commit 887db5398e
5 changed files with 25 additions and 8 deletions

View File

@ -126,7 +126,9 @@
"
:filters="field.filters"
@change="(v) => fieldChange(v, field, row)"
:onCreate="field.create"
:onCreate="
(value, close) => field.create(v, field, row, close)
"
/>
<Link
v-else-if="field.fieldtype === 'User'"
@ -407,7 +409,12 @@ const allFields = computed(() => {
function getFieldObj(field) {
if (field.fieldtype === 'Link' && field.options !== 'User') {
if (!field.create) {
field.create = (obj, close) => createDocument(field.options, obj, close)
field.create = (value, field, row, close) => {
const callback = (d) => {
if (d) fieldChange(d.name, field, row)
}
createDocument(field.options, value, close, callback)
}
}
}

View File

@ -275,7 +275,12 @@ const field = computed(() => {
if (field.fieldtype === 'Link' && field.options !== 'User') {
if (!field.create) {
field.create = (obj, close) => createDocument(field.options, obj, close)
field.create = (value, close) => {
const callback = (d) => {
if (d) fieldChange(d.name, field)
}
createDocument(field.options, value, close, callback)
}
}
}

View File

@ -62,7 +62,7 @@ const props = defineProps({
},
})
const emit = defineEmits(['showQuickEntryModal'])
const emit = defineEmits(['showQuickEntryModal', 'callback'])
const { isManager } = usersStore()
@ -100,11 +100,11 @@ const tabs = createResource({
auto: true,
})
async function create(close) {
async function create() {
loading.value = true
error.value = null
await call(
let doc = await call(
'frappe.client.insert',
{
doc: {
@ -124,6 +124,7 @@ async function create(close) {
loading.value = false
show.value = false
emit('callback', doc)
}
watch(

View File

@ -5,6 +5,7 @@
:doctype="createDocumentDoctype"
:data="createDocumentData"
@showQuickEntryModal="(dt) => openQuickEntryModal(dt)"
@callback="(data) => createDocumentCallback(data)"
/>
<QuickEntryModal
v-if="showQuickEntryModal"
@ -19,6 +20,7 @@ import {
showCreateDocumentModal,
createDocumentDoctype,
createDocumentData,
createDocumentCallback,
} from '@/composables/document'
import { ref } from 'vue'

View File

@ -3,12 +3,14 @@ import { ref } from 'vue'
export const showCreateDocumentModal = ref(false)
export const createDocumentDoctype = ref('')
export const createDocumentData = ref({})
export const createDocumentCallback = ref(null)
export function createDocument(doctype, obj, close) {
export function createDocument(doctype, obj, close, callback) {
if (doctype) {
close()
close?.()
createDocumentDoctype.value = doctype
createDocumentData.value = obj || {}
createDocumentCallback.value = callback || null
showCreateDocumentModal.value = true
}
}