2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00
books/fyo/model/types.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
3.1 KiB
TypeScript
Raw Normal View History

import { DocValue, DocValueMap } from 'fyo/core/types';
import SystemSettings from 'fyo/models/SystemSettings';
import { FieldType, SelectOption } from 'schemas/types';
import { QueryFilter } from 'utils/db/types';
import { Router } from 'vue-router';
import { Doc } from './doc';
/**
* 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).
*/
export type FormulaReturn = DocValue | DocValueMap[] | undefined | Doc[];
export type Formula = () => Promise<FormulaReturn> | FormulaReturn;
export type FormulaConfig = { dependsOn?: string[]; formula: Formula };
export type Default = () => DocValue;
2022-04-22 11:02:03 +00:00
export type Validation = (value: DocValue) => Promise<void> | void;
export type Required = () => boolean;
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;
export type FormulaMap = Record<string, FormulaConfig | undefined>;
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>;
export type ChangeArg = { doc: Doc; changed: string };
/**
* Should add this for hidden too
*/
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 {
SystemSettings?: SystemSettings;
[key: string]: Doc | undefined;
2022-04-18 08:01:41 +00:00
}
// Static Config properties
export type FilterFunction = (doc: Doc) => QueryFilter | Promise<QueryFilter>;
export type FiltersMap = Record<string, FilterFunction>;
export type EmptyMessageFunction = (doc: Doc) => string;
export type EmptyMessageMap = Record<string, EmptyMessageFunction>;
export type ListFunction = (doc?: Doc) => string[] | SelectOption[];
2022-04-22 12:01:04 +00:00
export type ListsMap = Record<string, ListFunction | undefined>;
export interface Action {
label: string;
2022-04-20 06:38:47 +00:00
action: (doc: Doc, router: Router) => Promise<void> | void;
condition?: (doc: Doc) => boolean;
component?: {
template?: string;
};
}
export interface ColumnConfig {
label: string;
fieldtype: FieldType;
fieldname?: string;
size?: string;
render?: (doc: Doc) => { template: string };
getValue?: (doc: Doc) => string;
}
export type ListViewColumn = string | ColumnConfig;
export interface ListViewSettings {
formRoute?: (name: string) => string;
columns?: ListViewColumn[];
}
export interface TreeViewSettings {
parentField: string;
getRootLabel: () => Promise<string>;
}