mirror of
https://github.com/frappe/books.git
synced 2025-02-02 12:08:27 +00:00
incr: add meta fields
This commit is contained in:
parent
ef6e8d44ab
commit
19278e92d6
@ -19,8 +19,8 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "party",
|
"fieldname": "party",
|
||||||
"label": "Party",
|
"label": "Party",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "DynamicLink",
|
||||||
"target": "Party"
|
"target": ["Customer", "Supplier"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "debit",
|
"fieldname": "debit",
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
"fieldname": "items",
|
"fieldname": "items",
|
||||||
"label": "Items",
|
"label": "Items",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"childtype": "SalesInvoiceItem",
|
"target": "SalesInvoiceItem",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"fieldname": "details",
|
"fieldname": "details",
|
||||||
"label": "Details",
|
"label": "Details",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"childtype": "TaxDetail",
|
"target": "TaxDetail",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -1,14 +1,47 @@
|
|||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep } from 'lodash';
|
||||||
import { getListFromMap, getMapFromList } from './helpers';
|
import { getListFromMap, getMapFromList } from './helpers';
|
||||||
import regional from './regional';
|
import regionalSchemas from './regional';
|
||||||
import { appSchemas, coreSchemas } from './schemas';
|
import { appSchemas, coreSchemas, metaSchemas } from './schemas';
|
||||||
import { Schema, SchemaMap, SchemaStub, SchemaStubMap } from './types';
|
import { Schema, SchemaMap, SchemaStub, SchemaStubMap } from './types';
|
||||||
|
|
||||||
export function getSchemas(countryCode: string = '-'): SchemaMap {
|
export function getSchemas(countryCode: string = '-'): SchemaMap {
|
||||||
const builtCoreSchemas = getCoreSchemas();
|
const builtCoreSchemas = getCoreSchemas();
|
||||||
const builtAppSchemas = getAppSchemas(countryCode);
|
const builtAppSchemas = getAppSchemas(countryCode);
|
||||||
|
|
||||||
return Object.assign({}, builtAppSchemas, builtCoreSchemas);
|
let schemaMap = Object.assign({}, builtAppSchemas, builtCoreSchemas);
|
||||||
|
schemaMap = addMetaFields(schemaMap);
|
||||||
|
return schemaMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMetaFields(schemaMap: SchemaMap): SchemaMap {
|
||||||
|
const metaSchemaMap = getMapFromList(metaSchemas);
|
||||||
|
|
||||||
|
const base = metaSchemaMap.base;
|
||||||
|
const tree = getCombined(metaSchemaMap.tree, base);
|
||||||
|
const child = metaSchemaMap.child;
|
||||||
|
const submittable = getCombined(metaSchemaMap.submittable, base);
|
||||||
|
const submittableTree = getCombined(tree, metaSchemaMap.submittable);
|
||||||
|
|
||||||
|
for (const name in schemaMap) {
|
||||||
|
const schema = schemaMap[name];
|
||||||
|
if (schema.isSingle) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.isTree && schema.isSubmittable) {
|
||||||
|
schema.fields = [...schema.fields, ...submittableTree.fields];
|
||||||
|
} else if (schema.isTree) {
|
||||||
|
schema.fields = [...schema.fields, ...tree.fields];
|
||||||
|
} else if (schema.isSubmittable) {
|
||||||
|
schema.fields = [...schema.fields, ...submittable.fields];
|
||||||
|
} else if (schema.isChild) {
|
||||||
|
schema.fields = [...schema.fields, ...child.fields];
|
||||||
|
} else {
|
||||||
|
schema.fields = [...schema.fields, ...base.fields];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return schemaMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCoreSchemas(): SchemaMap {
|
function getCoreSchemas(): SchemaMap {
|
||||||
@ -116,10 +149,12 @@ function getRegionalCombinedSchemas(countryCode: string): SchemaStubMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getRegionalSchema(countryCode: string): SchemaStubMap {
|
function getRegionalSchema(countryCode: string): SchemaStubMap {
|
||||||
const regionalSchemas = regional[countryCode] as SchemaStub[] | undefined;
|
const countrySchemas = regionalSchemas[countryCode] as
|
||||||
if (regionalSchemas === undefined) {
|
| SchemaStub[]
|
||||||
|
| undefined;
|
||||||
|
if (countrySchemas === undefined) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return getMapFromList(regionalSchemas);
|
return getMapFromList(countrySchemas);
|
||||||
}
|
}
|
||||||
|
33
schemas/meta/base.json
Normal file
33
schemas/meta/base.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "base",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "createdBy",
|
||||||
|
"label": "Created By",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "modifiedBy",
|
||||||
|
"label": "Modified By",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "created",
|
||||||
|
"label": "Created",
|
||||||
|
"fieldtype": "Datetime",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "modified",
|
||||||
|
"label": "Modified",
|
||||||
|
"fieldtype": "Datetime",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
29
schemas/meta/child.json
Normal file
29
schemas/meta/child.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "child",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "idx",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "parent",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "parentName",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "parentFieldname",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
19
schemas/meta/submittable.json
Normal file
19
schemas/meta/submittable.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "submittable",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "submitted",
|
||||||
|
"label": "Submitted",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "cancelled",
|
||||||
|
"label": "Cancelled",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
19
schemas/meta/tree.json
Normal file
19
schemas/meta/tree.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "tree",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldname": "lft",
|
||||||
|
"label": "Left Index",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "rgt",
|
||||||
|
"label": "Right Index",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"required": true,
|
||||||
|
"meta": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -28,6 +28,11 @@ import TaxSummary from './app/TaxSummary.json';
|
|||||||
import PatchRun from './core/PatchRun.json';
|
import PatchRun from './core/PatchRun.json';
|
||||||
import SingleValue from './core/SingleValue.json';
|
import SingleValue from './core/SingleValue.json';
|
||||||
import SystemSettings from './core/SystemSettings.json';
|
import SystemSettings from './core/SystemSettings.json';
|
||||||
|
import base from './meta/base.json';
|
||||||
|
import submittable from './meta/submittable.json';
|
||||||
|
//asdf
|
||||||
|
import child from './meta/child.json';
|
||||||
|
import tree from './meta/tree.json';
|
||||||
import { Schema, SchemaStub } from './types';
|
import { Schema, SchemaStub } from './types';
|
||||||
|
|
||||||
export const coreSchemas: Schema[] = [
|
export const coreSchemas: Schema[] = [
|
||||||
@ -36,6 +41,13 @@ export const coreSchemas: Schema[] = [
|
|||||||
SystemSettings as Schema,
|
SystemSettings as Schema,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const metaSchemas: SchemaStub[] = [
|
||||||
|
base as SchemaStub,
|
||||||
|
child as SchemaStub,
|
||||||
|
submittable as SchemaStub,
|
||||||
|
tree as SchemaStub,
|
||||||
|
];
|
||||||
|
|
||||||
export const appSchemas: Schema[] | SchemaStub[] = [
|
export const appSchemas: Schema[] | SchemaStub[] = [
|
||||||
SetupWizard as Schema,
|
SetupWizard as Schema,
|
||||||
GetStarted as Schema,
|
GetStarted as Schema,
|
||||||
|
@ -54,7 +54,7 @@ export enum FieldTypeEnum {
|
|||||||
export type FieldType = keyof typeof FieldTypeEnum;
|
export type FieldType = keyof typeof FieldTypeEnum;
|
||||||
export type RawValue = string | number | boolean;
|
export type RawValue = string | number | boolean;
|
||||||
|
|
||||||
// prettier-ignore
|
// @formatter:off
|
||||||
export interface BaseField {
|
export interface BaseField {
|
||||||
fieldname: string; // Column name in the db
|
fieldname: string; // Column name in the db
|
||||||
fieldtype: FieldType; // UI Descriptive field types that map to column types
|
fieldtype: FieldType; // UI Descriptive field types that map to column types
|
||||||
@ -67,6 +67,7 @@ export interface BaseField {
|
|||||||
placeholder?: string; // UI Facing config, form field placeholder
|
placeholder?: string; // UI Facing config, form field placeholder
|
||||||
groupBy?: string; // UI Facing used in dropdowns fields
|
groupBy?: string; // UI Facing used in dropdowns fields
|
||||||
computed?: boolean; // Indicates whether a value is computed, implies readonly
|
computed?: boolean; // Indicates whether a value is computed, implies readonly
|
||||||
|
meta?: boolean; // Field is a meta field, i.e. only for the db, not UI
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SelectOption = { value: string; label: string };
|
export type SelectOption = { value: string; label: string };
|
||||||
@ -78,19 +79,19 @@ export interface OptionField extends BaseField {
|
|||||||
options: SelectOption[];
|
options: SelectOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// @formatter:off
|
||||||
export interface TargetField extends BaseField {
|
export interface TargetField extends BaseField {
|
||||||
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
|
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
|
||||||
target: string | string[]; // Name of the table or group of tables to fetch values
|
target: string | string[]; // Name of the table or group of tables to fetch values
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// @formatter:off
|
||||||
export interface DynamicLinkField extends BaseField {
|
export interface DynamicLinkField extends BaseField {
|
||||||
fieldtype: FieldTypeEnum.DynamicLink;
|
fieldtype: FieldTypeEnum.DynamicLink;
|
||||||
references: string; // Reference to an option field that links to schema
|
references: string; // Reference to an option field that links to schema
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// @formatter:off
|
||||||
export interface NumberField extends BaseField {
|
export interface NumberField extends BaseField {
|
||||||
fieldtype: FieldTypeEnum.Float | FieldTypeEnum.Int;
|
fieldtype: FieldTypeEnum.Float | FieldTypeEnum.Int;
|
||||||
minvalue?: number; // UI Facing used to restrict lower bound
|
minvalue?: number; // UI Facing used to restrict lower bound
|
||||||
|
Loading…
x
Reference in New Issue
Block a user