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 @@