mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
refactor: properly type naming
- remove redundant files - change getDoc and getNewDoc
This commit is contained in:
parent
9e71466b82
commit
0201844fd0
@ -25,8 +25,7 @@ async function importAccounts(children, parentAccount, rootType, rootAccount) {
|
||||
const { accountType, accountNumber } = child;
|
||||
const accountName = getAccountName(rootName, accountNumber);
|
||||
const isGroup = identifyIsGroup(child);
|
||||
const doc = frappe.getNewDoc({
|
||||
doctype: 'Account',
|
||||
const doc = frappe.doc.getNewDoc('Account', {
|
||||
name: accountName,
|
||||
parentAccount,
|
||||
isGroup,
|
||||
|
@ -27,7 +27,7 @@ export default class LedgerPosting {
|
||||
|
||||
async setAccountBalanceChange(accountName, type, amount) {
|
||||
const debitAccounts = ['Asset', 'Expense'];
|
||||
const { rootType } = await frappe.getDoc('Account', accountName);
|
||||
const { rootType } = await frappe.doc.getDoc('Account', accountName);
|
||||
if (debitAccounts.indexOf(rootType) === -1) {
|
||||
const change = type == 'credit' ? amount : amount.neg();
|
||||
this.accountEntries.push({
|
||||
@ -82,7 +82,10 @@ export default class LedgerPosting {
|
||||
});
|
||||
|
||||
for (let entry of data) {
|
||||
let entryDoc = await frappe.getDoc('AccountingLedgerEntry', entry.name);
|
||||
let entryDoc = await frappe.doc.getDoc(
|
||||
'AccountingLedgerEntry',
|
||||
entry.name
|
||||
);
|
||||
entryDoc.reverted = 1;
|
||||
await entryDoc.update();
|
||||
}
|
||||
@ -145,14 +148,12 @@ export default class LedgerPosting {
|
||||
|
||||
async insertEntries() {
|
||||
for (let entry of this.entries) {
|
||||
let entryDoc = frappe.getNewDoc({
|
||||
doctype: 'AccountingLedgerEntry',
|
||||
});
|
||||
let entryDoc = frappe.doc.getNewDoc('AccountingLedgerEntry');
|
||||
Object.assign(entryDoc, entry);
|
||||
await entryDoc.insert();
|
||||
}
|
||||
for (let entry of this.accountEntries) {
|
||||
let entryDoc = await frappe.getDoc('Account', entry.name);
|
||||
let entryDoc = await frappe.doc.getDoc('Account', entry.name);
|
||||
entryDoc.balance = entryDoc.balance.add(entry.balanceChange);
|
||||
await entryDoc.update();
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ export class DatabaseHandler extends DatabaseBase {
|
||||
|
||||
async getAll(
|
||||
schemaName: string,
|
||||
options: GetAllOptions
|
||||
options: GetAllOptions = {}
|
||||
): Promise<DocValueMap[]> {
|
||||
const rawValueMap = (await this.#demux.call(
|
||||
'getAll',
|
||||
|
@ -1,17 +1,24 @@
|
||||
import frappe from 'frappe';
|
||||
import NumberSeries from 'frappe/models/NumberSeries';
|
||||
import { getRandomString } from 'frappe/utils';
|
||||
import { BaseError } from 'frappe/utils/errors';
|
||||
import { Field, Schema } from 'schemas/types';
|
||||
import Doc from './doc';
|
||||
|
||||
export async function isNameAutoSet(schemaName: string) {
|
||||
const doc = frappe.doc.getEmptyDoc(schemaName);
|
||||
if (doc.meta.naming === 'autoincrement') {
|
||||
export function getNumberSeries(schema: Schema): Field | undefined {
|
||||
const numberSeries = schema.fields.find(
|
||||
(f) => f.fieldname === 'numberSeries'
|
||||
);
|
||||
return numberSeries;
|
||||
}
|
||||
|
||||
export function isNameAutoSet(schemaName: string): boolean {
|
||||
const schema = frappe.schemaMap[schemaName]!;
|
||||
if (schema.naming === 'autoincrement') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!doc.meta.settings) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { numberSeries } = await doc.getSettings();
|
||||
const numberSeries = getNumberSeries(schema);
|
||||
if (numberSeries) {
|
||||
return true;
|
||||
}
|
||||
@ -19,30 +26,18 @@ export async function isNameAutoSet(schemaName: string) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function setName(doc) {
|
||||
if (frappe.isServer) {
|
||||
// if is server, always name again if autoincrement or other
|
||||
if (doc.meta.naming === 'autoincrement') {
|
||||
doc.name = await getNextId(doc.doctype);
|
||||
return;
|
||||
}
|
||||
export async function setName(doc: Doc) {
|
||||
// if is server, always name again if autoincrement or other
|
||||
if (doc.schema.naming === 'autoincrement') {
|
||||
doc.name = await getNextId(doc.schemaName);
|
||||
return;
|
||||
}
|
||||
|
||||
// Current, per doc number series
|
||||
if (doc.numberSeries) {
|
||||
doc.name = await getSeriesNext(doc.numberSeries, doc.doctype);
|
||||
return;
|
||||
}
|
||||
|
||||
// Legacy, using doc settings for number series
|
||||
if (doc.meta.settings) {
|
||||
const numberSeries = (await doc.getSettings()).numberSeries;
|
||||
if (!numberSeries) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc.name = await getSeriesNext(numberSeries, doc.doctype);
|
||||
return;
|
||||
}
|
||||
// Current, per doc number series
|
||||
const numberSeries = doc.numberSeries as string | undefined;
|
||||
if (numberSeries !== undefined) {
|
||||
doc.name = await getSeriesNext(numberSeries, doc.schemaName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (doc.name) {
|
||||
@ -50,8 +45,8 @@ export async function setName(doc) {
|
||||
}
|
||||
|
||||
// name === doctype for Single
|
||||
if (doc.meta.isSingle) {
|
||||
doc.name = doc.meta.name;
|
||||
if (doc.schema.isSingle) {
|
||||
doc.name = doc.schema.name;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -62,54 +57,57 @@ export async function setName(doc) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getNextId(doctype) {
|
||||
export async function getNextId(schemaName: string) {
|
||||
// get the last inserted row
|
||||
let lastInserted = await getLastInserted(doctype);
|
||||
const lastInserted = await getLastInserted(schemaName);
|
||||
let name = 1;
|
||||
if (lastInserted) {
|
||||
let lastNumber = parseInt(lastInserted.name);
|
||||
let lastNumber = parseInt(lastInserted.name as string);
|
||||
if (isNaN(lastNumber)) lastNumber = 0;
|
||||
name = lastNumber + 1;
|
||||
}
|
||||
return (name + '').padStart(9, '0');
|
||||
}
|
||||
|
||||
export async function getLastInserted(doctype) {
|
||||
const lastInserted = await frappe.db.getAll({
|
||||
doctype: doctype,
|
||||
export async function getLastInserted(schemaName: string) {
|
||||
const lastInserted = await frappe.db.getAll(schemaName, {
|
||||
fields: ['name'],
|
||||
limit: 1,
|
||||
order_by: 'creation',
|
||||
orderBy: 'creation',
|
||||
order: 'desc',
|
||||
});
|
||||
return lastInserted && lastInserted.length ? lastInserted[0] : null;
|
||||
}
|
||||
|
||||
export async function getSeriesNext(prefix, doctype) {
|
||||
let series;
|
||||
export async function getSeriesNext(prefix: string, schemaName: string) {
|
||||
let series: NumberSeries;
|
||||
|
||||
try {
|
||||
series = await frappe.getDoc('NumberSeries', prefix);
|
||||
series = (await frappe.doc.getDoc('NumberSeries', prefix)) as NumberSeries;
|
||||
} catch (e) {
|
||||
if (!e.statusCode || e.statusCode !== 404) {
|
||||
const { statusCode } = e as BaseError;
|
||||
if (!statusCode || statusCode !== 404) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
await createNumberSeries(prefix, doctype);
|
||||
series = await frappe.getDoc('NumberSeries', prefix);
|
||||
await createNumberSeries(prefix, schemaName);
|
||||
series = (await frappe.doc.getDoc('NumberSeries', prefix)) as NumberSeries;
|
||||
}
|
||||
|
||||
return await series.next(doctype);
|
||||
return await series.next(schemaName);
|
||||
}
|
||||
|
||||
export async function createNumberSeries(prefix, referenceType, start = 1001) {
|
||||
export async function createNumberSeries(
|
||||
prefix: string,
|
||||
referenceType: string,
|
||||
start = 1001
|
||||
) {
|
||||
const exists = await frappe.db.exists('NumberSeries', prefix);
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
const series = frappe.getNewDoc({
|
||||
doctype: 'NumberSeries',
|
||||
const series = frappe.doc.getNewDoc('NumberSeries', {
|
||||
name: prefix,
|
||||
start,
|
||||
referenceType,
|
||||
|
@ -28,7 +28,7 @@ export default class PaymentServer extends Document {
|
||||
}
|
||||
|
||||
const doctype = referenceType;
|
||||
const doc = await frappe.getDoc(doctype, referenceName);
|
||||
const doc = await frappe.doc.getDoc(doctype, referenceName);
|
||||
|
||||
let party;
|
||||
let paymentType;
|
||||
@ -147,7 +147,7 @@ export default class PaymentServer extends Document {
|
||||
if (!['SalesInvoice', 'PurchaseInvoice'].includes(row.referenceType)) {
|
||||
continue;
|
||||
}
|
||||
let referenceDoc = await frappe.getDoc(
|
||||
let referenceDoc = await frappe.doc.getDoc(
|
||||
row.referenceType,
|
||||
row.referenceName
|
||||
);
|
||||
@ -175,7 +175,7 @@ export default class PaymentServer extends Document {
|
||||
let newOutstanding = outstandingAmount.sub(this.amount);
|
||||
await referenceDoc.set('outstandingAmount', newOutstanding);
|
||||
await referenceDoc.update();
|
||||
let party = await frappe.getDoc('Party', this.party);
|
||||
let party = await frappe.doc.getDoc('Party', this.party);
|
||||
await party.updateOutstandingAmount();
|
||||
}
|
||||
}
|
||||
@ -198,7 +198,7 @@ export default class PaymentServer extends Document {
|
||||
|
||||
async updateReferenceOutstandingAmount() {
|
||||
await this.for.forEach(async ({ amount, referenceType, referenceName }) => {
|
||||
const refDoc = await frappe.getDoc(referenceType, referenceName);
|
||||
const refDoc = await frappe.doc.getDoc(referenceType, referenceName);
|
||||
refDoc.setMultiple({
|
||||
outstandingAmount: refDoc.outstandingAmount.add(amount),
|
||||
});
|
||||
|
@ -84,15 +84,15 @@ export default {
|
||||
await this.getFont();
|
||||
},
|
||||
async getTemplate() {
|
||||
let invoiceSettings = await frappe.getDoc('SalesInvoiceSettings');
|
||||
let invoiceSettings = await frappe.doc.getDoc('SalesInvoiceSettings');
|
||||
this.template = invoiceTemplates[invoiceSettings.template];
|
||||
},
|
||||
async getColor() {
|
||||
let invoiceSettings = await frappe.getDoc('SalesInvoiceSettings');
|
||||
let invoiceSettings = await frappe.doc.getDoc('SalesInvoiceSettings');
|
||||
this.themeColor = invoiceSettings.themeColor;
|
||||
},
|
||||
async getFont() {
|
||||
let invoiceSettings = await frappe.getDoc('SalesInvoiceSettings');
|
||||
let invoiceSettings = await frappe.doc.getDoc('SalesInvoiceSettings');
|
||||
this.font = invoiceSettings.font;
|
||||
},
|
||||
async toggleCustomizer() {
|
||||
|
@ -49,7 +49,8 @@ export default class TransactionDocument extends Document {
|
||||
|
||||
async getTax(tax) {
|
||||
if (!this._taxes) this._taxes = {};
|
||||
if (!this._taxes[tax]) this._taxes[tax] = await frappe.getDoc('Tax', tax);
|
||||
if (!this._taxes[tax])
|
||||
this._taxes[tax] = await frappe.doc.getDoc('Tax', tax);
|
||||
return this._taxes[tax];
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,10 @@ export default {
|
||||
outstandingAmount: this.baseGrandTotal,
|
||||
});
|
||||
|
||||
let party = await frappe.getDoc('Party', this.customer || this.supplier);
|
||||
let party = await frappe.doc.getDoc(
|
||||
'Party',
|
||||
this.customer || this.supplier
|
||||
);
|
||||
await party.updateOutstandingAmount();
|
||||
},
|
||||
|
||||
@ -43,7 +46,7 @@ export default {
|
||||
let paymentRefList = await this.getPayments();
|
||||
for (let paymentFor of paymentRefList) {
|
||||
const paymentReference = paymentFor.parent;
|
||||
const payment = await frappe.getDoc('Payment', paymentReference);
|
||||
const payment = await frappe.doc.getDoc('Payment', paymentReference);
|
||||
const paymentEntries = await payment.getPosting();
|
||||
await paymentEntries.postReverse();
|
||||
// To set the payment status as unsubmitted.
|
||||
|
@ -1,28 +0,0 @@
|
||||
import frappe from 'frappe';
|
||||
|
||||
export default async function execute() {
|
||||
// Since sqlite has no ALTER TABLE to change column meta
|
||||
// the table has to be _Prestiged_.
|
||||
const tableInfo = await frappe.db.sql('pragma table_info("Payment")');
|
||||
const referenceId = tableInfo.find(({ name }) => name === 'referenceId');
|
||||
if (!referenceId || !referenceId.notnull) {
|
||||
return;
|
||||
}
|
||||
|
||||
await frappe.db.createTable('Payment', '__Payment');
|
||||
await frappe.db.sql('insert into __Payment select * from Payment');
|
||||
|
||||
const mainCount = await frappe.db.knex
|
||||
.table('Payment')
|
||||
.count('name as count');
|
||||
const replCount = await frappe.db.knex
|
||||
.table('__Payment')
|
||||
.count('name as count');
|
||||
|
||||
if (mainCount[0].count === replCount[0].count) {
|
||||
await frappe.db.knex.schema.dropTable('Payment');
|
||||
await frappe.db.knex.schema.renameTable('__Payment', 'Payment');
|
||||
} else {
|
||||
await frappe.db.knex.schema.dropTable('__Payment');
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
import frappe from 'frappe';
|
||||
|
||||
function getTablesToConvert() {
|
||||
// Do not change loops to map, doesn't work for some reason.
|
||||
const toConvert = [];
|
||||
for (let key in frappe.models) {
|
||||
const model = frappe.models[key];
|
||||
|
||||
const fieldsToConvert = [];
|
||||
for (let i in model.fields) {
|
||||
const field = model.fields[i];
|
||||
|
||||
if (field.fieldtype === 'Currency') {
|
||||
fieldsToConvert.push(field.fieldname);
|
||||
}
|
||||
}
|
||||
|
||||
if (fieldsToConvert.length > 0 && !model.isSingle && !model.basedOn) {
|
||||
toConvert.push({ name: key, fields: fieldsToConvert });
|
||||
}
|
||||
}
|
||||
|
||||
return toConvert;
|
||||
}
|
||||
|
||||
export default async function execute() {
|
||||
const toConvert = getTablesToConvert();
|
||||
for (let { name, fields } of toConvert) {
|
||||
const rows = await frappe.db.knex(name);
|
||||
const convertedRows = rows.map((row) => {
|
||||
for (let field of fields) {
|
||||
row[field] = frappe.pesa(row[field] ?? 0).store;
|
||||
}
|
||||
|
||||
if ('numberFormat' in row) {
|
||||
delete row.numberFormat;
|
||||
}
|
||||
|
||||
return row;
|
||||
});
|
||||
await frappe.db.prestigeTheTable(name, convertedRows);
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
import { getPaddedName } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import { journalEntryTypeMap } from '../../models/doctype/JournalEntry/JournalEntry';
|
||||
|
||||
export async function getCorrectedJournalEntries() {
|
||||
const jes = await frappe.db.knex('JournalEntry');
|
||||
const names = new Set();
|
||||
const duplicates = [];
|
||||
|
||||
for (const je of jes) {
|
||||
if (je.name in journalEntryTypeMap) {
|
||||
const entryType = je.name;
|
||||
je.name = je.entryType;
|
||||
je.entryType = entryType;
|
||||
}
|
||||
|
||||
if (names.has(je.name)) {
|
||||
duplicates.push(je);
|
||||
} else {
|
||||
names.add(je.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (duplicates.length === 0) {
|
||||
return { jes, currentMap: {}, nsMap: {} };
|
||||
}
|
||||
|
||||
const nameMap = getNameMap(names);
|
||||
const nsMap = await getNumberSeriesMap(nameMap);
|
||||
const currentMap = {};
|
||||
|
||||
const editedMap = {};
|
||||
|
||||
for (const je of duplicates) {
|
||||
const { prefix } = getNumPrefix(je.name);
|
||||
if (prefix.length === 0) {
|
||||
je.name = `${je.name}-${Math.random().toString(36).slice(2, 7)}`;
|
||||
continue;
|
||||
}
|
||||
|
||||
const newNum = nameMap[prefix].at(-1) + 1;
|
||||
nameMap[prefix].push(newNum);
|
||||
currentMap[prefix] = newNum;
|
||||
|
||||
const newName = getPaddedName(prefix, newNum, nsMap[prefix].padZeros);
|
||||
editedMap[je.name] = newName;
|
||||
je.name = newName;
|
||||
}
|
||||
|
||||
return { jes, currentMap, nsMap };
|
||||
}
|
||||
|
||||
async function updateCurrent(currentMap, nsMap) {
|
||||
for (const name in currentMap) {
|
||||
nsMap[name].update({ current: currentMap[name] });
|
||||
}
|
||||
}
|
||||
|
||||
async function getNumberSeriesMap(nameMap) {
|
||||
const nsMap = {};
|
||||
for (const name in nameMap) {
|
||||
nsMap[name] = await frappe.getDoc('NumberSeries', name);
|
||||
}
|
||||
return nsMap;
|
||||
}
|
||||
|
||||
function getNumPrefix(name) {
|
||||
const mo = name.match(/(\D+)(\d+)$/);
|
||||
const np = { num: '', prefix: '' };
|
||||
if (!mo) {
|
||||
return np;
|
||||
}
|
||||
|
||||
np.prefix = mo[1] ?? '';
|
||||
np.num = mo[2] ?? '';
|
||||
return np;
|
||||
}
|
||||
|
||||
function getNameMap(names) {
|
||||
const nameMap = {};
|
||||
for (const name of names) {
|
||||
const { num, prefix } = getNumPrefix(name);
|
||||
if (prefix.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nameMap[prefix] ??= [];
|
||||
nameMap[prefix].push(parseInt(num));
|
||||
}
|
||||
|
||||
for (const name in nameMap) {
|
||||
nameMap[name].sort();
|
||||
}
|
||||
|
||||
return nameMap;
|
||||
}
|
||||
|
||||
export default async function execute() {
|
||||
const { jes, currentMap, nsMap } = await getCorrectedJournalEntries();
|
||||
await frappe.db.prestigeTheTable('JournalEntry', jes);
|
||||
if (Object.keys(currentMap).length) {
|
||||
updateCurrent(currentMap, nsMap);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
import { invertMap } from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import { DEFAULT_NUMBER_SERIES } from 'frappe/utils/consts';
|
||||
|
||||
async function setReferencesOnNumberSeries() {
|
||||
const map = invertMap(DEFAULT_NUMBER_SERIES);
|
||||
const rows = await frappe.db.knex('NumberSeries');
|
||||
for (const row of rows) {
|
||||
if (row.referenceType === map[row.name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
row.referenceType = map[row.name];
|
||||
}
|
||||
await frappe.db.prestigeTheTable('NumberSeries', rows);
|
||||
}
|
||||
|
||||
export default async function execute() {
|
||||
await setReferencesOnNumberSeries();
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
[
|
||||
{
|
||||
"version": "0.0.3",
|
||||
"fileName": "makePaymentRefIdNullable",
|
||||
"beforeMigrate": true
|
||||
},
|
||||
{
|
||||
"version": "0.0.4",
|
||||
"fileName": "convertCurrencyToStrings",
|
||||
"beforeMigrate": true
|
||||
},
|
||||
{
|
||||
"version": "0.3.2",
|
||||
"fileName": "moveNumberSeriesFromSettings",
|
||||
"beforeMigrate": false
|
||||
},
|
||||
{
|
||||
"version": "0.3.2",
|
||||
"fileName": "fixJournalEntryIds",
|
||||
"beforeMigrate": true
|
||||
}
|
||||
]
|
@ -39,18 +39,21 @@ class BaseGSTR {
|
||||
}
|
||||
|
||||
async getRow(ledgerEntry) {
|
||||
ledgerEntry = await frappe.getDoc(ledgerEntry.doctype, ledgerEntry.name);
|
||||
ledgerEntry = await frappe.doc.getDoc(
|
||||
ledgerEntry.doctype,
|
||||
ledgerEntry.name
|
||||
);
|
||||
|
||||
const row = {};
|
||||
const { gstin } = frappe.AccountingSettings;
|
||||
|
||||
let party = await frappe.getDoc(
|
||||
let party = await frappe.doc.getDoc(
|
||||
'Party',
|
||||
ledgerEntry.customer || ledgerEntry.supplier
|
||||
);
|
||||
|
||||
if (party.address) {
|
||||
let addressDetails = await frappe.getDoc('Address', party.address);
|
||||
let addressDetails = await frappe.doc.getDoc('Address', party.address);
|
||||
row.place = addressDetails.pos || '';
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
"label": "Ledger Entry",
|
||||
"isSingle": false,
|
||||
"isChild": false,
|
||||
"naming": "autoincrement",
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "date",
|
||||
|
@ -108,6 +108,7 @@ export type Field =
|
||||
| NumberField;
|
||||
|
||||
export type TreeSettings = { parentField: string };
|
||||
export type Naming = 'autoincrement' | 'random' | 'numberSeries'
|
||||
|
||||
export interface Schema {
|
||||
name: string; // Table name
|
||||
@ -123,6 +124,7 @@ export interface Schema {
|
||||
keywordFields?: string[]; // Used to get fields that are to be used for search.
|
||||
quickEditFields?: string[]; // Used to get fields for the quickEditForm
|
||||
treeSettings?: TreeSettings; // Used to determine root nodes
|
||||
naming?: Naming; // Used for assigning name, default is 'random' else 'numberSeries' if present
|
||||
}
|
||||
|
||||
export interface SchemaStub extends Partial<Schema> {
|
||||
|
@ -50,7 +50,7 @@ export default {
|
||||
};
|
||||
},
|
||||
async created() {
|
||||
this.doc = await frappe.getDoc('SalesInvoiceSettings');
|
||||
this.doc = await frappe.doc.getDoc('SalesInvoiceSettings');
|
||||
this.color.hex = this.doc.themeColor;
|
||||
const meta = frappe.getMeta('SalesInvoiceSettings');
|
||||
this.fields = meta.fields.filter(
|
||||
|
@ -66,7 +66,7 @@ export default {
|
||||
this.selectedEntries.push(this.entries[i]);
|
||||
}
|
||||
for (let entry of this.selectedEntries) {
|
||||
const payment = await frappe.getDoc('Payment', entry['Payment Entry']);
|
||||
const payment = await frappe.doc.getDoc('Payment', entry['Payment Entry']);
|
||||
const clearanceDate =
|
||||
luxon.DateTime.fromFormat(
|
||||
entry['Clearance Date'],
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { Doc, Field, FieldType, Map } from '@/types/model';
|
||||
import frappe from 'frappe';
|
||||
import { DocValueMap } from 'frappe/core/types';
|
||||
import Doc from 'frappe/model/doc';
|
||||
import { isNameAutoSet } from 'frappe/model/naming';
|
||||
import { FieldType, FieldTypeEnum } from 'schemas/types';
|
||||
import { parseCSV } from './csvParser';
|
||||
import telemetry from './telemetry/telemetry';
|
||||
import { Noun, Verb } from './telemetry/types';
|
||||
@ -25,9 +27,8 @@ type Exclusion = {
|
||||
[key: string]: string[];
|
||||
};
|
||||
|
||||
type ObjectMap = {
|
||||
[key: string]: Map;
|
||||
};
|
||||
type Map = Record<string, unknown>;
|
||||
type ObjectMap = Record<string, Map>;
|
||||
|
||||
type LabelTemplateFieldMap = {
|
||||
[key: string]: TemplateField;
|
||||
@ -51,16 +52,16 @@ interface TemplateField {
|
||||
|
||||
function formatValue(value: string, fieldtype: FieldType): unknown {
|
||||
switch (fieldtype) {
|
||||
case FieldType.Date:
|
||||
case FieldTypeEnum.Date:
|
||||
if (value === '') {
|
||||
return '';
|
||||
}
|
||||
return new Date(value);
|
||||
case FieldType.Currency:
|
||||
case FieldTypeEnum.Currency:
|
||||
// @ts-ignore
|
||||
return frappe.pesa(value || 0);
|
||||
case FieldType.Int:
|
||||
case FieldType.Float: {
|
||||
case FieldTypeEnum.Int:
|
||||
case FieldTypeEnum.Float: {
|
||||
const n = parseFloat(value);
|
||||
if (!Number.isNaN(n)) {
|
||||
return n;
|
||||
@ -115,7 +116,7 @@ function getFilteredDocFields(
|
||||
return;
|
||||
}
|
||||
|
||||
if (fieldtype === FieldType.Table && childtype) {
|
||||
if (fieldtype === FieldTypeEnum.Table && childtype) {
|
||||
tableTypes.push([childtype, fieldname]);
|
||||
return;
|
||||
}
|
||||
@ -363,7 +364,7 @@ export class Importer {
|
||||
|
||||
async importData(setLoadingStatus: LoadingStatusCallback): Promise<Status> {
|
||||
const status: Status = { success: false, names: [], message: '' };
|
||||
const shouldDeleteName = await isNameAutoSet(this.doctype);
|
||||
const shouldDeleteName = isNameAutoSet(this.doctype);
|
||||
const docObjs = this.getDocs();
|
||||
|
||||
let entriesMade = 0;
|
||||
@ -382,7 +383,7 @@ export class Importer {
|
||||
delete docObj[key];
|
||||
}
|
||||
|
||||
const doc: Doc = frappe.getEmptyDoc(this.doctype, false);
|
||||
const doc: Doc = frappe.doc.getEmptyDoc(this.doctype, false);
|
||||
try {
|
||||
await this.makeEntry(doc, docObj);
|
||||
entriesMade += 1;
|
||||
@ -398,7 +399,7 @@ export class Importer {
|
||||
return this.handleError(doc, err as Error, status);
|
||||
}
|
||||
|
||||
status.names.push(doc.name);
|
||||
status.names.push(doc.name!);
|
||||
}
|
||||
|
||||
setLoadingStatus(false, entriesMade, docObjs.length);
|
||||
@ -417,7 +418,7 @@ export class Importer {
|
||||
}
|
||||
|
||||
async makeEntry(doc: Doc, docObj: Map) {
|
||||
await doc.set(docObj);
|
||||
await doc.setMultiple(docObj as DocValueMap);
|
||||
await doc.insert();
|
||||
if (this.shouldSubmit) {
|
||||
await doc.submit();
|
||||
|
@ -205,11 +205,11 @@ import DropdownWithActions from '@/components/DropdownWithActions';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import StatusBadge from '@/components/StatusBadge';
|
||||
import {
|
||||
getActionsForDocument,
|
||||
getInvoiceStatus,
|
||||
openSettings,
|
||||
routeTo,
|
||||
showMessageDialog,
|
||||
getActionsForDocument,
|
||||
getInvoiceStatus,
|
||||
openSettings,
|
||||
routeTo,
|
||||
showMessageDialog
|
||||
} from '@/utils';
|
||||
import frappe from 'frappe';
|
||||
import { handleErrorWithDialog } from '../errorHandling';
|
||||
@ -263,7 +263,7 @@ export default {
|
||||
},
|
||||
async mounted() {
|
||||
try {
|
||||
this.doc = await frappe.getDoc(this.doctype, this.name);
|
||||
this.doc = await frappe.doc.getDoc(this.doctype, this.name);
|
||||
window.d = this.doc;
|
||||
} catch (error) {
|
||||
if (error instanceof frappe.errors.NotFoundError) {
|
||||
|
@ -192,7 +192,7 @@ export default {
|
||||
},
|
||||
async mounted() {
|
||||
try {
|
||||
this.doc = await frappe.getDoc(this.doctype, this.name);
|
||||
this.doc = await frappe.doc.getDoc(this.doctype, this.name);
|
||||
window.je = this.doc;
|
||||
} catch (error) {
|
||||
if (error instanceof frappe.errors.NotFoundError) {
|
||||
|
@ -56,12 +56,12 @@ import Button from '@/components/Button';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import SearchBar from '@/components/SearchBar';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
import telemetry from '@/telemetry/telemetry';
|
||||
import { Verb } from '@/telemetry/types';
|
||||
import { makePDF } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
|
||||
export default {
|
||||
name: 'PrintView',
|
||||
@ -81,7 +81,7 @@ export default {
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
this.doc = await frappe.getDoc(this.doctype, this.name);
|
||||
this.doc = await frappe.doc.getDoc(this.doctype, this.name);
|
||||
this.printSettings = await frappe.getSingle('PrintSettings');
|
||||
},
|
||||
computed: {
|
||||
|
@ -186,7 +186,7 @@ export default {
|
||||
},
|
||||
async fetchDoc() {
|
||||
try {
|
||||
this.doc = await frappe.getDoc(this.doctype, this.name);
|
||||
this.doc = await frappe.doc.getDoc(this.doctype, this.name);
|
||||
|
||||
this.doc.once('afterRename', () => {
|
||||
openQuickEdit({
|
||||
|
@ -12,8 +12,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import frappe from 'frappe';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import frappe from 'frappe';
|
||||
|
||||
export default {
|
||||
name: 'TabGeneral',
|
||||
@ -27,7 +27,7 @@ export default {
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
this.doc = await frappe.getDoc('AccountingSettings', 'AccountingSettings', {
|
||||
this.doc = await frappe.doc.getDoc('AccountingSettings', 'AccountingSettings', {
|
||||
skipDocumentCache: true,
|
||||
});
|
||||
},
|
||||
|
@ -1,20 +1,14 @@
|
||||
import FormControl from '@/components/Controls/FormControl';
|
||||
import LanguageSelector from '@/components/Controls/LanguageSelector.vue';
|
||||
import Popover from '@/components/Popover';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import config from '@/config';
|
||||
import { connectToLocalDatabase, purgeCache } from '@/initialization';
|
||||
import { IPC_MESSAGES } from '@/messages';
|
||||
import { setLanguageMap, showMessageDialog } from '@/utils';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe from 'frappe';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
getErrorMessage, handleErrorWithDialog, showErrorDialog
|
||||
} from '../../errorHandling';
|
||||
import setupCompany from './setupCompany';
|
||||
import Slide from './Slide.vue';
|
||||
import FormControl from '@/components/Controls/FormControl'; import
|
||||
LanguageSelector from '@/components/Controls/LanguageSelector.vue'; import
|
||||
Popover from '@/components/Popover'; import TwoColumnForm from
|
||||
'@/components/TwoColumnForm'; import config from '@/config'; import {
|
||||
connectToLocalDatabase, purgeCache } from '@/initialization'; import {
|
||||
IPC_MESSAGES } from '@/messages'; import { setLanguageMap, showMessageDialog }
|
||||
from '@/utils'; import { ipcRenderer } from 'electron'; import frappe from
|
||||
'frappe'; import fs from 'fs'; import path from 'path'; import {
|
||||
getErrorMessage, handleErrorWithDialog, showErrorDialog } from
|
||||
'../../errorHandling'; import setupCompany from './setupCompany'; import Slide
|
||||
from './Slide.vue';
|
||||
<template>
|
||||
<div>
|
||||
<Slide
|
||||
@ -119,7 +113,9 @@ import frappe from 'frappe';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
getErrorMessage, handleErrorWithDialog, showErrorDialog
|
||||
getErrorMessage,
|
||||
handleErrorWithDialog,
|
||||
showErrorDialog,
|
||||
} from '../../errorHandling';
|
||||
import setupCompany from './setupCompany';
|
||||
import Slide from './Slide.vue';
|
||||
@ -154,7 +150,7 @@ export default {
|
||||
this.index = 1;
|
||||
}
|
||||
|
||||
this.doc = await frappe.getNewDoc({ doctype: 'SetupWizard' });
|
||||
this.doc = await frappe.doc.getNewDoc('SetupWizard');
|
||||
this.doc.on('change', () => {
|
||||
this.valuesFilled = this.allValuesFilled();
|
||||
});
|
||||
|
@ -163,7 +163,7 @@ async function checkAndCreateDoc(docObject) {
|
||||
return;
|
||||
}
|
||||
|
||||
const doc = await frappe.getNewDoc(docObject);
|
||||
const doc = await frappe.doc.getNewDoc(docObject.doctype, docObject);
|
||||
return doc.insert();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import config, { ConfigFile, ConfigKeys, TelemetrySetting } from '@/config';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe, { t } from 'frappe';
|
||||
import { IPC_ACTIONS } from 'utils/messages';
|
||||
import { DoctypeName } from '../../models/types';
|
||||
import { Count, UniqueId } from './types';
|
||||
|
||||
@ -34,6 +34,7 @@ export async function getCounts(): Promise<Count> {
|
||||
DoctypeName.PurchaseInvoiceItem,
|
||||
DoctypeName.JournalEntry,
|
||||
DoctypeName.JournalEntryAccount,
|
||||
DoctypeName.Party,
|
||||
DoctypeName.Account,
|
||||
DoctypeName.Tax,
|
||||
];
|
||||
@ -46,27 +47,10 @@ export async function getCounts(): Promise<Count> {
|
||||
|
||||
type CountResponse = { 'count(*)': number }[];
|
||||
for (const name of interestingDocs) {
|
||||
// @ts-ignore
|
||||
const queryResponse: CountResponse = await frappe.db.knex(name).count();
|
||||
const count: number = queryResponse[0]['count(*)'];
|
||||
const count: number = (await frappe.db.getAll(name)).length;
|
||||
countMap[name] = count;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const supplierCount: CountResponse = await frappe.db
|
||||
.knex('Party')
|
||||
.count()
|
||||
.where({ supplier: 1 });
|
||||
|
||||
// @ts-ignore
|
||||
const customerCount: CountResponse = await frappe.db
|
||||
.knex('Party')
|
||||
.count()
|
||||
.where({ customer: 1 });
|
||||
|
||||
countMap[DoctypeName.Customer] = customerCount[0]['count(*)'];
|
||||
countMap[DoctypeName.Supplier] = supplierCount[0]['count(*)'];
|
||||
|
||||
return countMap;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ export async function cancelDocWithPrompt(doc) {
|
||||
{
|
||||
label: t`Yes`,
|
||||
async action() {
|
||||
const entryDoc = await frappe.getDoc(doc.doctype, doc.name);
|
||||
const entryDoc = await frappe.doc.getDoc(doc.doctype, doc.name);
|
||||
entryDoc.cancelled = 1;
|
||||
await entryDoc.update();
|
||||
entryDoc
|
||||
|
@ -6,7 +6,7 @@ describe('Frappe', function () {
|
||||
const frappe = new Frappe(DatabaseManager);
|
||||
|
||||
specify('Init', async function () {
|
||||
await frappe.init();
|
||||
await frappe.db.connectToDatabase(':memory:');
|
||||
// await frappe.init();
|
||||
// await frappe.db.connectToDatabase(':memory:');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user