2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/server/postStart.js

58 lines
2.3 KiB
JavaScript
Raw Normal View History

import frappe from 'frappe';
import naming from 'frappe/model/naming';
import GSTR3BServer from '../models/doctype/GSTR3B/GSTR3BServer.js';
import JournalEntryServer from '../models/doctype/JournalEntry/JournalEntryServer.js';
import PartyServer from '../models/doctype/Party/PartyServer.js';
import PaymentServer from '../models/doctype/Payment/PaymentServer.js';
import PurchaseInvoiceServer from '../models/doctype/PurchaseInvoice/PurchaseInvoiceServer.js';
import SalesInvoiceServer from '../models/doctype/SalesInvoice/SalesInvoiceServer.js';
import registerServerMethods from './registerServerMethods';
2018-10-22 18:02:47 +00:00
export default async function postStart() {
2018-10-22 18:02:47 +00:00
// set server-side modules
frappe.models.SalesInvoice.documentClass = SalesInvoiceServer;
frappe.models.Payment.documentClass = PaymentServer;
frappe.models.Party.documentClass = PartyServer;
frappe.models.PurchaseInvoice.documentClass = PurchaseInvoiceServer;
frappe.models.JournalEntry.documentClass = JournalEntryServer;
frappe.models.GSTR3B.documentClass = GSTR3BServer;
2018-10-22 18:02:47 +00:00
frappe.metaCache = {};
// init naming series if missing
await naming.createNumberSeries('SINV-', 'SalesInvoiceSettings');
await naming.createNumberSeries('PINV-', 'PurchaseInvoiceSettings');
2018-10-22 18:02:47 +00:00
await naming.createNumberSeries('PAY-', 'PaymentSettings');
await naming.createNumberSeries('JV-', 'JournalEntrySettings');
await naming.createNumberSeries('QTN-', 'QuotationSettings');
await naming.createNumberSeries('SO-', 'SalesOrderSettings');
await naming.createNumberSeries('OF-', 'FulfillmentSettings');
await naming.createNumberSeries('PO-', 'PurchaseOrderSettings');
await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings');
// fetch singles
// so that they are available synchronously
await frappe.getSingle('SystemSettings');
await frappe.getSingle('AccountingSettings');
await frappe.getSingle('GetStarted');
// cache currency symbols for frappe.format
await setCurrencySymbols();
2018-10-22 18:02:47 +00:00
registerServerMethods();
}
export async function setCurrencySymbols() {
frappe.currencySymbols = await frappe.db
.getAll({
doctype: 'Currency',
fields: ['name', 'symbol'],
})
.then((data) => {
return data.reduce((obj, currency) => {
obj[currency.name] = currency.symbol;
return obj;
}, {});
});
}