mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
incr: add meta fields
This commit is contained in:
parent
ef6e8d44ab
commit
19278e92d6
@ -19,8 +19,8 @@
|
||||
{
|
||||
"fieldname": "party",
|
||||
"label": "Party",
|
||||
"fieldtype": "Link",
|
||||
"target": "Party"
|
||||
"fieldtype": "DynamicLink",
|
||||
"target": ["Customer", "Supplier"]
|
||||
},
|
||||
{
|
||||
"fieldname": "debit",
|
||||
@ -66,4 +66,4 @@
|
||||
"balance"
|
||||
],
|
||||
"keywordFields": ["account", "party", "referenceName"]
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@
|
||||
"fieldname": "items",
|
||||
"label": "Items",
|
||||
"fieldtype": "Table",
|
||||
"childtype": "SalesInvoiceItem",
|
||||
"target": "SalesInvoiceItem",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
|
@ -14,7 +14,7 @@
|
||||
"fieldname": "details",
|
||||
"label": "Details",
|
||||
"fieldtype": "Table",
|
||||
"childtype": "TaxDetail",
|
||||
"target": "TaxDetail",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
|
@ -1,14 +1,47 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { getListFromMap, getMapFromList } from './helpers';
|
||||
import regional from './regional';
|
||||
import { appSchemas, coreSchemas } from './schemas';
|
||||
import regionalSchemas from './regional';
|
||||
import { appSchemas, coreSchemas, metaSchemas } from './schemas';
|
||||
import { Schema, SchemaMap, SchemaStub, SchemaStubMap } from './types';
|
||||
|
||||
export function getSchemas(countryCode: string = '-'): SchemaMap {
|
||||
const builtCoreSchemas = getCoreSchemas();
|
||||
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 {
|
||||
@ -116,10 +149,12 @@ function getRegionalCombinedSchemas(countryCode: string): SchemaStubMap {
|
||||
}
|
||||
|
||||
function getRegionalSchema(countryCode: string): SchemaStubMap {
|
||||
const regionalSchemas = regional[countryCode] as SchemaStub[] | undefined;
|
||||
if (regionalSchemas === undefined) {
|
||||
const countrySchemas = regionalSchemas[countryCode] as
|
||||
| SchemaStub[]
|
||||
| undefined;
|
||||
if (countrySchemas === undefined) {
|
||||
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 SingleValue from './core/SingleValue.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';
|
||||
|
||||
export const coreSchemas: Schema[] = [
|
||||
@ -36,6 +41,13 @@ export const coreSchemas: 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[] = [
|
||||
SetupWizard as Schema,
|
||||
GetStarted as Schema,
|
||||
|
@ -54,7 +54,7 @@ export enum FieldTypeEnum {
|
||||
export type FieldType = keyof typeof FieldTypeEnum;
|
||||
export type RawValue = string | number | boolean;
|
||||
|
||||
// prettier-ignore
|
||||
// @formatter:off
|
||||
export interface BaseField {
|
||||
fieldname: string; // Column name in the db
|
||||
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
|
||||
groupBy?: string; // UI Facing used in dropdowns fields
|
||||
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 };
|
||||
@ -78,19 +79,19 @@ export interface OptionField extends BaseField {
|
||||
options: SelectOption[];
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
// @formatter:off
|
||||
export interface TargetField extends BaseField {
|
||||
fieldtype: FieldTypeEnum.Table | FieldTypeEnum.Link;
|
||||
target: string | string[]; // Name of the table or group of tables to fetch values
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
// @formatter:off
|
||||
export interface DynamicLinkField extends BaseField {
|
||||
fieldtype: FieldTypeEnum.DynamicLink;
|
||||
references: string; // Reference to an option field that links to schema
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
// @formatter:off
|
||||
export interface NumberField extends BaseField {
|
||||
fieldtype: FieldTypeEnum.Float | FieldTypeEnum.Int;
|
||||
minvalue?: number; // UI Facing used to restrict lower bound
|
||||
|
Loading…
Reference in New Issue
Block a user