|
153 | 153 | <script setup lang="ts"> |
154 | 154 | import { computed, nextTick, ref, watch } from 'vue' |
155 | 155 | import { useRouter } from 'vue-router' |
156 | | -import type { DataImports, DataImport, DocField } from './types' |
| 156 | +import type { DataImports, DataImport, DocField, DocType } from './types' |
157 | 157 | import { toast } from "../../src/components/Toast/index" |
158 | 158 | import { fieldsToIgnore, getChildTableName, getBadgeColor } from './dataImport' |
159 | 159 | import Badge from '../../src/components/Badge/Badge.vue' |
@@ -327,20 +327,39 @@ const getExportFields = (type: 'mandatory' | 'all') => { |
327 | 327 | } |
328 | 328 |
|
329 | 329 | 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) => { |
332 | 336 | return !fieldsToIgnore.includes(field.fieldtype) && field.reqd |
333 | 337 | }).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 |
338 | 357 | } |
339 | 358 |
|
340 | 359 | const getAllFields = () => { |
341 | 360 | let doctypeMap: Record<string, string[]> = {} |
342 | 361 | let docs = props.fields.data?.docs || [] |
343 | | - docs.forEach((doc: any) => { |
| 362 | + docs.forEach((doc: DocType) => { |
344 | 363 | let exportableFields = doc.fields.filter((field: DocField) => { |
345 | 364 | return !fieldsToIgnore.includes(field.fieldtype) |
346 | 365 | }).map((field: DocField) => field.fieldname) |
|
0 commit comments