From b24577f9fc21fdeaa881693ba56f2fe7509d3028 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 2 Feb 2023 13:42:09 +0530 Subject: [PATCH] feat: start rewriting data import as the import wizard --- fyo/core/converter.ts | 1 - fyo/utils/index.ts | 34 +- src/components/Controls/Text.vue | 3 +- src/importer.ts | 215 +++++++++++ src/pages/ImportWizard.vue | 629 +++++++++++++++++++++++++++++++ src/router.ts | 6 + src/utils/sidebarConfig.ts | 5 + tests/testImporter.spec.ts | 14 + 8 files changed, 904 insertions(+), 3 deletions(-) create mode 100644 src/importer.ts create mode 100644 src/pages/ImportWizard.vue create mode 100644 tests/testImporter.spec.ts diff --git a/fyo/core/converter.ts b/fyo/core/converter.ts index 7a3c2d55..c9220163 100644 --- a/fyo/core/converter.ts +++ b/fyo/core/converter.ts @@ -3,7 +3,6 @@ import { Doc } from 'fyo/model/doc'; import { isPesa } from 'fyo/utils'; import { ValueError } from 'fyo/utils/errors'; import { DateTime } from 'luxon'; -import { Money } from 'pesa'; import { Field, FieldTypeEnum, RawValue, TargetField } from 'schemas/types'; import { getIsNullOrUndef, safeParseFloat, safeParseInt } from 'utils'; import { DatabaseHandler } from './dbHandler'; diff --git a/fyo/utils/index.ts b/fyo/utils/index.ts index c35bbff9..e7bad878 100644 --- a/fyo/utils/index.ts +++ b/fyo/utils/index.ts @@ -1,8 +1,9 @@ import { Fyo } from 'fyo'; +import { DocValue } from 'fyo/core/types'; import { Doc } from 'fyo/model/doc'; import { Action } from 'fyo/model/types'; import { Money } from 'pesa'; -import { Field, OptionField, SelectOption } from 'schemas/types'; +import { Field, FieldType, OptionField, SelectOption } from 'schemas/types'; import { getIsNullOrUndef, safeParseInt } from 'utils'; export function slug(str: string) { @@ -109,3 +110,34 @@ function getRawOptionList(field: Field, doc: Doc | undefined | null) { return getList(doc!); } + +export function getEmptyValuesByFieldTypes( + fieldtype: FieldType, + fyo: Fyo +): DocValue { + switch (fieldtype) { + case 'Date': + case 'Datetime': + return new Date(); + case 'Float': + case 'Int': + return 0; + case 'Currency': + return fyo.pesa(0); + case 'Check': + return false; + case 'DynamicLink': + case 'Link': + case 'Select': + case 'AutoComplete': + case 'Text': + case 'Data': + case 'Color': + return null; + case 'Table': + case 'Attachment': + case 'AttachImage': + default: + return null; + } +} diff --git a/src/components/Controls/Text.vue b/src/components/Controls/Text.vue index dbdcc6e7..1d6fda3b 100644 --- a/src/components/Controls/Text.vue +++ b/src/components/Controls/Text.vue @@ -6,7 +6,7 @@