mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
incr: rename Meta and Document
This commit is contained in:
parent
807a5d2da7
commit
26e030106f
24
frappe/backends/helpers.ts
Normal file
24
frappe/backends/helpers.ts
Normal file
@ -0,0 +1,24 @@
|
||||
export const sqliteTypeMap = {
|
||||
AutoComplete: 'text',
|
||||
Currency: 'text',
|
||||
Int: 'integer',
|
||||
Float: 'float',
|
||||
Percent: 'float',
|
||||
Check: 'integer',
|
||||
Code: 'text',
|
||||
Date: 'text',
|
||||
Datetime: 'text',
|
||||
Time: 'text',
|
||||
Text: 'text',
|
||||
Data: 'text',
|
||||
Link: 'text',
|
||||
DynamicLink: 'text',
|
||||
Password: 'text',
|
||||
Select: 'text',
|
||||
File: 'text',
|
||||
Attach: 'text',
|
||||
AttachImage: 'text',
|
||||
Color: 'text',
|
||||
};
|
||||
|
||||
export const validTypes = Object.keys(sqliteTypeMap);
|
@ -1,5 +1,6 @@
|
||||
import frappe from 'frappe';
|
||||
import Database from './database';
|
||||
import { sqliteTypeMap } from './helpers';
|
||||
|
||||
export default class SqliteDatabase extends Database {
|
||||
constructor({ dbPath }) {
|
||||
@ -67,36 +68,7 @@ export default class SqliteDatabase extends Database {
|
||||
}
|
||||
|
||||
initTypeMap() {
|
||||
// prettier-ignore
|
||||
this.typeMap = {
|
||||
'AutoComplete': 'text',
|
||||
'Currency': 'text',
|
||||
'Int': 'integer',
|
||||
'Float': 'float',
|
||||
'Percent': 'float',
|
||||
'Check': 'integer',
|
||||
'Small Text': 'text',
|
||||
'Long Text': 'text',
|
||||
'Code': 'text',
|
||||
'Text Editor': 'text',
|
||||
'Date': 'text',
|
||||
'Datetime': 'text',
|
||||
'Time': 'text',
|
||||
'Text': 'text',
|
||||
'Data': 'text',
|
||||
'Link': 'text',
|
||||
'DynamicLink': 'text',
|
||||
'Password': 'text',
|
||||
'Select': 'text',
|
||||
'Read Only': 'text',
|
||||
'File': 'text',
|
||||
'Attach': 'text',
|
||||
'AttachImage': 'text',
|
||||
'Signature': 'text',
|
||||
'Color': 'text',
|
||||
'Barcode': 'text',
|
||||
'Geolocation': 'text'
|
||||
};
|
||||
this.typeMap = sqliteTypeMap;
|
||||
}
|
||||
|
||||
getError(err) {
|
||||
|
@ -1,7 +0,0 @@
|
||||
export default async function initLibs(frappe) {
|
||||
const BaseMeta = await import('frappe/model/meta');
|
||||
const BaseDocument = await import('frappe/model/document');
|
||||
|
||||
frappe.BaseDocument = BaseDocument.default;
|
||||
frappe.BaseMeta = BaseMeta.default;
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import initLibs from 'frappe/common';
|
||||
import { getMoneyMaker } from 'pesa';
|
||||
import { markRaw } from 'vue';
|
||||
import * as errors from './common/errors';
|
||||
@ -23,7 +22,10 @@ class Frappe {
|
||||
|
||||
async initializeAndRegister(customModels = {}, force = false) {
|
||||
this.init(force);
|
||||
await initLibs(this);
|
||||
|
||||
this.Meta = (await import('frappe/model/meta')).default;
|
||||
this.Document = (await import('frappe/model/document')).default;
|
||||
|
||||
const coreModels = await import('frappe/models');
|
||||
this.registerModels(coreModels.default);
|
||||
this.registerModels(customModels);
|
||||
@ -233,7 +235,7 @@ class Frappe {
|
||||
throw new Error(`${doctype} is not a registered doctype`);
|
||||
}
|
||||
|
||||
let metaClass = model.metaClass || this.BaseMeta;
|
||||
let metaClass = model.metaClass || this.Meta;
|
||||
this.metaCache[doctype] = new metaClass(model);
|
||||
}
|
||||
|
||||
@ -257,7 +259,7 @@ class Frappe {
|
||||
|
||||
getDocumentClass(doctype) {
|
||||
const meta = this.getMeta(doctype);
|
||||
return meta.documentClass || this.BaseDocument;
|
||||
return meta.documentClass || this.Document;
|
||||
}
|
||||
|
||||
async getSingle(doctype) {
|
||||
@ -292,7 +294,7 @@ class Frappe {
|
||||
}
|
||||
|
||||
async newCustomDoc(fields) {
|
||||
let doc = new this.BaseDocument({ isCustom: 1, fields });
|
||||
let doc = new this.Document({ isCustom: 1, fields });
|
||||
doc._notInserted = true;
|
||||
doc.name = this.getRandomString();
|
||||
this.addToCache(doc);
|
||||
@ -300,7 +302,7 @@ class Frappe {
|
||||
}
|
||||
|
||||
createMeta(fields) {
|
||||
let meta = new this.BaseMeta({ isCustom: 1, fields });
|
||||
let meta = new this.Meta({ isCustom: 1, fields });
|
||||
return meta;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
import frappe from 'frappe';
|
||||
import { validTypes } from 'frappe/backends/helpers';
|
||||
import { ValueError } from 'frappe/common/errors';
|
||||
import { indicators as indicatorColor } from '../../src/colors';
|
||||
import { t } from '../utils/translation';
|
||||
import Document from './document';
|
||||
import model from './index';
|
||||
|
||||
export default class BaseMeta extends Document {
|
||||
export default class Meta extends Document {
|
||||
constructor(data) {
|
||||
if (data.basedOn) {
|
||||
let config = frappe.models[data.basedOn];
|
||||
@ -33,7 +36,7 @@ export default class BaseMeta extends Document {
|
||||
if (!this.fields.find((df) => df.fieldname === 'name') && !this.isSingle) {
|
||||
this.fields = [
|
||||
{
|
||||
label: frappe.t`ID`,
|
||||
label: t`ID`,
|
||||
fieldname: 'name',
|
||||
fieldtype: 'Data',
|
||||
required: 1,
|
||||
@ -149,12 +152,12 @@ export default class BaseMeta extends Document {
|
||||
// fields validation
|
||||
this.fields.forEach((df, i) => {
|
||||
if (!df.fieldname) {
|
||||
throw new frappe.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
`DocType ${this.name}: "fieldname" is required for field at index ${i}`
|
||||
);
|
||||
}
|
||||
if (!df.fieldtype) {
|
||||
throw new frappe.errors.ValidationError(
|
||||
throw new ValidationError(
|
||||
`DocType ${this.name}: "fieldtype" is required for field "${df.fieldname}"`
|
||||
);
|
||||
}
|
||||
@ -165,7 +168,7 @@ export default class BaseMeta extends Document {
|
||||
// standard fields
|
||||
for (let field of model.commonFields) {
|
||||
if (
|
||||
frappe.db.typeMap[field.fieldtype] &&
|
||||
validTypes.includes(field.fieldtype) &&
|
||||
!doctypeFields.includes(field.fieldname)
|
||||
) {
|
||||
_add(field);
|
||||
@ -176,7 +179,7 @@ export default class BaseMeta extends Document {
|
||||
_add({
|
||||
fieldtype: 'Check',
|
||||
fieldname: 'submitted',
|
||||
label: frappe.t`Submitted`,
|
||||
label: t`Submitted`,
|
||||
});
|
||||
}
|
||||
|
||||
@ -184,7 +187,7 @@ export default class BaseMeta extends Document {
|
||||
// child fields
|
||||
for (let field of model.childFields) {
|
||||
if (
|
||||
frappe.db.typeMap[field.fieldtype] &&
|
||||
validTypes.includes(field.fieldtype) &&
|
||||
!doctypeFields.includes(field.fieldname)
|
||||
) {
|
||||
_add(field);
|
||||
@ -194,7 +197,7 @@ export default class BaseMeta extends Document {
|
||||
// parent fields
|
||||
for (let field of model.parentFields) {
|
||||
if (
|
||||
frappe.db.typeMap[field.fieldtype] &&
|
||||
validTypes.includes(field.fieldtype) &&
|
||||
!doctypeFields.includes(field.fieldname)
|
||||
) {
|
||||
_add(field);
|
||||
@ -206,7 +209,7 @@ export default class BaseMeta extends Document {
|
||||
// tree fields
|
||||
for (let field of model.treeFields) {
|
||||
if (
|
||||
frappe.db.typeMap[field.fieldtype] &&
|
||||
validTypes.includes(field.fieldtype) &&
|
||||
!doctypeFields.includes(field.fieldname)
|
||||
) {
|
||||
_add(field);
|
||||
@ -216,7 +219,7 @@ export default class BaseMeta extends Document {
|
||||
|
||||
// doctype fields
|
||||
for (let field of this.fields) {
|
||||
let include = frappe.db.typeMap[field.fieldtype];
|
||||
const include = validTypes.includes(field.fieldtype);
|
||||
|
||||
if (include) {
|
||||
_add(field);
|
||||
@ -278,7 +281,7 @@ export default class BaseMeta extends Document {
|
||||
}
|
||||
|
||||
if (!validValues.includes(value)) {
|
||||
throw new frappe.errors.ValueError(
|
||||
throw new ValueError(
|
||||
// prettier-ignore
|
||||
`DocType ${this.name}: Invalid value "${value}" for "${field.label}". Must be one of ${options.join(', ')}`
|
||||
);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { getPaddedName } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
|
||||
export default class NumberSeries extends BaseDocument {
|
||||
export default class NumberSeries extends Document {
|
||||
validate() {
|
||||
if (!this.current) {
|
||||
this.current = this.start;
|
||||
|
@ -1 +0,0 @@
|
||||
module.exports = function () { return function () {}; };
|
@ -1,7 +1,7 @@
|
||||
import frappe from 'frappe';
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
|
||||
export default class Account extends BaseDocument {
|
||||
export default class Account extends Document {
|
||||
async validate() {
|
||||
if (!this.accountType && this.parentAccount) {
|
||||
this.accountType = await frappe.db.getValue(
|
||||
|
@ -1,6 +1,6 @@
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
|
||||
export default class Event extends BaseDocument {
|
||||
export default class Event extends Document {
|
||||
alertEvent() {
|
||||
alert(this.title);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import frappe from 'frappe';
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
import format from './GSTR3BFormat';
|
||||
|
||||
export default class GSTR3B extends BaseDocument {
|
||||
export default class GSTR3B extends Document {
|
||||
async getData() {
|
||||
const monthIndex = [
|
||||
'January',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
import LedgerPosting from '../../../accounting/ledgerPosting';
|
||||
|
||||
export default class JournalEntryServer extends BaseDocument {
|
||||
export default class JournalEntryServer extends Document {
|
||||
getPosting() {
|
||||
let entries = new LedgerPosting({ reference: this });
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import frappe from 'frappe';
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
|
||||
export default class PartyServer extends BaseDocument {
|
||||
export default class PartyServer extends Document {
|
||||
beforeInsert() {
|
||||
if (this.customer && this.supplier) {
|
||||
frappe.call({
|
||||
|
@ -1,8 +1,8 @@
|
||||
import frappe from 'frappe';
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
import LedgerPosting from '../../../accounting/ledgerPosting';
|
||||
|
||||
export default class PaymentServer extends BaseDocument {
|
||||
export default class PaymentServer extends Document {
|
||||
async change({ changed }) {
|
||||
switch (changed) {
|
||||
case 'for': {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import frappe from 'frappe';
|
||||
import BaseDocument from 'frappe/model/document';
|
||||
import Document from 'frappe/model/document';
|
||||
import { getExchangeRate } from '../../../accounting/exchangeRate';
|
||||
|
||||
export default class TransactionDocument extends BaseDocument {
|
||||
export default class TransactionDocument extends Document {
|
||||
async getExchangeRate() {
|
||||
if (!this.currency) return 1.0;
|
||||
|
||||
|
@ -108,7 +108,7 @@ export async function connectToLocalDatabase(filePath) {
|
||||
export async function purgeCache(purgeAll = false) {
|
||||
const filterFunction = purgeAll
|
||||
? () => true
|
||||
: (d) => frappe.docs[d][d] instanceof frappe.BaseMeta;
|
||||
: (d) => frappe.docs[d][d] instanceof frappe.Meta;
|
||||
|
||||
Object.keys(frappe.docs)
|
||||
.filter(filterFunction)
|
||||
|
@ -484,7 +484,7 @@ export function formatXLabels(label) {
|
||||
export function stringifyCircular(
|
||||
obj,
|
||||
ignoreCircular = false,
|
||||
convertBaseDocument = false
|
||||
convertDocument = false
|
||||
) {
|
||||
const cacheKey = [];
|
||||
const cacheValue = [];
|
||||
@ -504,7 +504,7 @@ export function stringifyCircular(
|
||||
cacheKey.push(key);
|
||||
cacheValue.push(value);
|
||||
|
||||
if (convertBaseDocument && value instanceof frappe.BaseDocument) {
|
||||
if (convertDocument && value instanceof frappe.Document) {
|
||||
return value.getValidDict();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user