2023-03-07 07:09:49 +00:00
|
|
|
import { Fyo } from 'fyo';
|
2022-04-19 05:59:36 +00:00
|
|
|
import { DocValue, DocValueMap } from 'fyo/core/types';
|
2023-07-24 09:23:57 +00:00
|
|
|
import type { SystemSettings } from 'fyo/models/SystemSettings';
|
2022-06-14 09:10:46 +00:00
|
|
|
import { FieldType, Schema, SelectOption } from 'schemas/types';
|
2022-04-11 09:41:49 +00:00
|
|
|
import { QueryFilter } from 'utils/db/types';
|
2023-01-09 07:03:26 +00:00
|
|
|
import { RouteLocationRaw, Router } from 'vue-router';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from './doc';
|
2023-06-06 07:44:26 +00:00
|
|
|
import type { AccountingSettings } from 'models/baseModels/AccountingSettings/AccountingSettings';
|
|
|
|
import type { Defaults } from 'models/baseModels/Defaults/Defaults';
|
|
|
|
import type { PrintSettings } from 'models/baseModels/PrintSettings/PrintSettings';
|
|
|
|
import type { InventorySettings } from 'models/inventory/InventorySettings';
|
2023-06-30 06:27:43 +00:00
|
|
|
import { Misc } from 'models/baseModels/Misc';
|
2022-04-01 09:35:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The functions below are used for dynamic evaluation
|
|
|
|
* and setting of field types.
|
|
|
|
*
|
|
|
|
* Since they are set directly on the doc, they can
|
|
|
|
* access the doc by using `this`.
|
|
|
|
*
|
|
|
|
* - `Formula`: Async function used for obtaining a computed value such as amount (rate * qty).
|
|
|
|
* - `Default`: Regular function used to dynamically set the default value, example new Date().
|
|
|
|
* - `Validation`: Async function that throw an error if the value is invalid.
|
|
|
|
* - `Required`: Regular function used to decide if a value is mandatory (there are !notnul in the db).
|
|
|
|
*/
|
2022-04-14 09:22:45 +00:00
|
|
|
export type FormulaReturn = DocValue | DocValueMap[] | undefined | Doc[];
|
2022-07-12 10:23:41 +00:00
|
|
|
export type Formula = (fieldname?: string) => Promise<FormulaReturn> | FormulaReturn;
|
2022-04-29 13:00:24 +00:00
|
|
|
export type FormulaConfig = { dependsOn?: string[]; formula: Formula };
|
2022-10-12 09:29:43 +00:00
|
|
|
export type Default = (doc: Doc) => DocValue;
|
2022-04-22 11:02:03 +00:00
|
|
|
export type Validation = (value: DocValue) => Promise<void> | void;
|
2022-04-01 09:35:51 +00:00
|
|
|
export type Required = () => boolean;
|
2022-04-14 05:24:11 +00:00
|
|
|
export type Hidden = () => boolean;
|
2022-04-22 11:02:03 +00:00
|
|
|
export type ReadOnly = () => boolean;
|
2022-04-18 08:01:41 +00:00
|
|
|
export type GetCurrency = () => string;
|
2022-04-01 09:35:51 +00:00
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
export type FormulaMap = Record<string, FormulaConfig | undefined>;
|
2022-04-01 09:35:51 +00:00
|
|
|
export type DefaultMap = Record<string, Default | undefined>;
|
|
|
|
export type ValidationMap = Record<string, Validation | undefined>;
|
|
|
|
export type RequiredMap = Record<string, Required | undefined>;
|
2022-04-22 12:01:04 +00:00
|
|
|
export type CurrenciesMap = Record<string, GetCurrency | undefined>;
|
|
|
|
export type HiddenMap = Record<string, Hidden | undefined>;
|
|
|
|
export type ReadOnlyMap = Record<string, ReadOnly | undefined>;
|
2022-04-01 09:35:51 +00:00
|
|
|
|
2022-05-03 13:13:47 +00:00
|
|
|
export type ChangeArg = { doc: Doc; changed: string };
|
|
|
|
|
2022-04-01 09:35:51 +00:00
|
|
|
/**
|
|
|
|
* Should add this for hidden too
|
|
|
|
*/
|
2022-04-07 06:20:14 +00:00
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
export type ModelMap = Record<string, typeof Doc | undefined>;
|
|
|
|
export type DocMap = Record<string, Doc | undefined>;
|
|
|
|
|
2022-04-18 08:01:41 +00:00
|
|
|
export interface SinglesMap {
|
2022-04-18 11:29:20 +00:00
|
|
|
SystemSettings?: SystemSettings;
|
2023-06-06 07:44:26 +00:00
|
|
|
AccountingSettings?: AccountingSettings;
|
|
|
|
InventorySettings?: InventorySettings;
|
|
|
|
PrintSettings?: PrintSettings;
|
|
|
|
Defaults?: Defaults;
|
2023-06-30 06:27:43 +00:00
|
|
|
Misc?: Misc;
|
2022-04-18 11:29:20 +00:00
|
|
|
[key: string]: Doc | undefined;
|
2022-04-18 08:01:41 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
// Static Config properties
|
|
|
|
|
2022-04-26 10:12:33 +00:00
|
|
|
export type FilterFunction = (doc: Doc) => QueryFilter | Promise<QueryFilter>;
|
2022-04-11 09:41:49 +00:00
|
|
|
export type FiltersMap = Record<string, FilterFunction>;
|
|
|
|
|
2022-04-26 10:12:33 +00:00
|
|
|
export type EmptyMessageFunction = (doc: Doc) => string;
|
2022-04-11 12:44:36 +00:00
|
|
|
export type EmptyMessageMap = Record<string, EmptyMessageFunction>;
|
|
|
|
|
2022-04-27 08:37:06 +00:00
|
|
|
export type ListFunction = (doc?: Doc) => string[] | SelectOption[];
|
2022-04-22 12:01:04 +00:00
|
|
|
export type ListsMap = Record<string, ListFunction | undefined>;
|
2022-04-11 09:41:49 +00:00
|
|
|
|
2022-04-11 12:44:36 +00:00
|
|
|
export interface Action {
|
|
|
|
label: string;
|
2023-04-03 08:21:46 +00:00
|
|
|
action: (doc: Doc, router: Router) => Promise<void> | void | unknown;
|
2022-04-20 06:38:47 +00:00
|
|
|
condition?: (doc: Doc) => boolean;
|
2022-11-30 06:59:52 +00:00
|
|
|
group?: string;
|
|
|
|
type?: 'primary' | 'secondary';
|
2022-04-20 06:38:47 +00:00
|
|
|
component?: {
|
2023-03-31 08:30:37 +00:00
|
|
|
template: string;
|
2022-04-20 06:38:47 +00:00
|
|
|
};
|
2022-04-11 12:44:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 09:10:46 +00:00
|
|
|
export interface RenderData {
|
|
|
|
schema: Schema,
|
|
|
|
[key: string]: DocValue | Schema
|
|
|
|
}
|
|
|
|
|
2023-03-07 07:09:49 +00:00
|
|
|
export type ColumnConfig = {
|
2022-04-11 09:41:49 +00:00
|
|
|
label: string;
|
|
|
|
fieldtype: FieldType;
|
2023-03-07 07:09:49 +00:00
|
|
|
fieldname: string;
|
2022-06-14 09:10:46 +00:00
|
|
|
render?: (doc: RenderData) => { template: string };
|
2023-03-07 07:09:49 +00:00
|
|
|
display?: (value: unknown, fyo: Fyo) => string;
|
2022-04-11 09:41:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type ListViewColumn = string | ColumnConfig;
|
|
|
|
export interface ListViewSettings {
|
2023-03-03 12:20:16 +00:00
|
|
|
formRoute?: (name: string) => RouteLocationRaw;
|
2022-04-11 09:41:49 +00:00
|
|
|
columns?: ListViewColumn[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TreeViewSettings {
|
|
|
|
parentField: string;
|
|
|
|
getRootLabel: () => Promise<string>;
|
|
|
|
}
|
2022-06-14 09:10:46 +00:00
|
|
|
|
|
|
|
export type DocStatus =
|
|
|
|
| ''
|
|
|
|
| 'Draft'
|
|
|
|
| 'Saved'
|
|
|
|
| 'NotSaved'
|
|
|
|
| 'Submitted'
|
|
|
|
| 'Cancelled';
|