2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

fix: Cache singles and currencySymbols in postStart

This commit is contained in:
Faris Ansari 2019-12-03 13:42:31 +05:30
parent 049432dbf1
commit c282844685
3 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,7 @@ module.exports = {
doctype: 'DocType',
isSingle: 0,
keywordFields: ['name', 'symbol'],
quickEditFields: ['name', 'symbol'],
fields: [
{
fieldname: 'name',

View File

@ -26,5 +26,28 @@ module.exports = async function postStart() {
await naming.createNumberSeries('PO-', 'PurchaseOrderSettings');
await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings');
// fetch singles
// these will be available as
// frappe.SystemSettings and frappe.AccountingSettings
await frappe.getSingle('SystemSettings');
await frappe.getSingle('AccountingSettings');
// cache currency symbols for frappe.format
frappe.currencySymbols = await getCurrencySymbols();
registerServerMethods();
};
function getCurrencySymbols() {
return frappe.db
.getAll({
doctype: 'Currency',
fields: ['name', 'symbol']
})
.then(data => {
return data.reduce((obj, currency) => {
obj[currency.name] = currency.symbol;
return obj;
}, {});
});
}

View File

@ -203,9 +203,8 @@ import router from './router';
dbPath: filepath
});
await frappe.db.connect();
await frappe.db.migrate();
frappe.getSingle('SystemSettings');
await postStart();
await frappe.db.migrate();
} catch (e) {
console.log(e);
}