Skip to content

Commit 4960ebb

Browse files
authored
Merge pull request #573 from raizasafeel/fix/mandatory-field-in-data-import
fix(dataimport): add mandatory child table fields in getMandatoryFields
2 parents 2b13d81 + 45dd0a0 commit 4960ebb

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

frappe/DataImport/UploadStep.vue

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<script setup lang="ts">
154154
import { computed, nextTick, ref, watch } from 'vue'
155155
import { useRouter } from 'vue-router'
156-
import type { DataImports, DataImport, DocField } from './types'
156+
import type { DataImports, DataImport, DocField, DocType } from './types'
157157
import { toast } from "../../src/components/Toast/index"
158158
import { fieldsToIgnore, getChildTableName, getBadgeColor } from './dataImport'
159159
import Badge from '../../src/components/Badge/Badge.vue'
@@ -327,20 +327,39 @@ const getExportFields = (type: 'mandatory' | 'all') => {
327327
}
328328
329329
const getMandatoryFields = () => {
330-
let parentDoctype = props.fields.data?.docs.find((doc: any) => doc.name == props.doctype)
331-
let exportableFields = parentDoctype.fields.filter((field: DocField) => {
330+
let exportableFields: Record<string, string[]> = {}
331+
let docs = props.fields.data?.docs || []
332+
let referenceDoctype = props.doctype || props.data?.reference_doctype as string
333+
let parentDoctype = docs.find((doc: DocType) => doc.name == referenceDoctype)
334+
335+
let parentFields = parentDoctype.fields.filter((field: DocField) => {
332336
return !fieldsToIgnore.includes(field.fieldtype) && field.reqd
333337
}).map((field: DocField) => field.fieldname)
334-
exportableFields.unshift('name')
335-
return {
336-
[props.doctype || props.data?.reference_doctype as string]: exportableFields
337-
}
338+
parentFields.unshift('name')
339+
exportableFields[referenceDoctype] = parentFields
340+
341+
let childDoctypes = parentDoctype.fields.filter((field: DocField) => {
342+
return (field.fieldtype === 'Table' || field.fieldtype === 'Table MultiSelect') && field.reqd
343+
})
344+
345+
childDoctypes.forEach((field: DocField) => {
346+
let childDoctype = docs.find((doc: DocType) => doc.name == field.options)
347+
if (childDoctype) {
348+
let childFields = childDoctype.fields.filter((f: DocField) => {
349+
return !fieldsToIgnore.includes(f.fieldtype) && f.reqd
350+
}).map((f: DocField) => f.fieldname)
351+
childFields.unshift('name')
352+
exportableFields[field.fieldname] = childFields
353+
}
354+
})
355+
356+
return exportableFields
338357
}
339358
340359
const getAllFields = () => {
341360
let doctypeMap: Record<string, string[]> = {}
342361
let docs = props.fields.data?.docs || []
343-
docs.forEach((doc: any) => {
362+
docs.forEach((doc: DocType) => {
344363
let exportableFields = doc.fields.filter((field: DocField) => {
345364
return !fieldsToIgnore.includes(field.fieldtype)
346365
}).map((field: DocField) => field.fieldname)

frappe/DataImport/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export interface DocField {
3535
fieldname: string
3636
reqd: 0 | 1
3737
fieldtype: string
38+
options?: string
39+
}
40+
41+
export interface DocType {
42+
name: string
43+
fields: DocField[]
3844
}
3945

4046
export interface File {

0 commit comments

Comments
 (0)