2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 12:10:06 +00:00
books/electron/client.js

90 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-04-16 09:32:56 +00:00
const frappe = require('frappejs');
const path = require('path');
2018-03-29 18:52:46 +00:00
const electron = require('frappejs/client/electron');
const appClient = require('../client');
const SetupWizard = require('../setup');
2018-04-16 09:32:56 +00:00
const { getPDFForElectron } = require('frappejs/server/pdf');
2018-04-16 13:03:54 +00:00
const { getSettings, saveSettings } = require('./settings');
const { postStart } = require('../server');
2018-04-18 06:47:00 +00:00
const { slug } = require('frappejs/utils');
2018-03-26 14:07:27 +00:00
2018-04-08 18:33:32 +00:00
const fs = require('fs');
require.extensions['.html'] = function (module, filename) {
2018-07-14 14:26:18 +00:00
module.exports = fs.readFileSync(filename, 'utf8');
2018-04-08 18:33:32 +00:00
};
(async () => {
2018-07-14 14:26:18 +00:00
let electronSettings = getSettings();
let firstRun = false;
let setupWizardValues = null;
if (!electronSettings.dbPath) {
const values = await runSetupWizard();
const dbPath = path.join(values.file[0].path, slug(values.companyName) + '.db');
const config = {
directory: path.dirname(dbPath),
dbPath: dbPath
};
await saveSettings(config);
firstRun = true;
electronSettings = config;
setupWizardValues = values;
}
await electron.start({
dbPath: electronSettings.dbPath,
models: require('../models')
});
await postStart();
if (firstRun) {
await saveSetupWizardValues(setupWizardValues);
await bootstrapChartOfAccounts();
}
frappe.getPDF = getPDFForElectron;
frappe.electronSettings = electronSettings;
appClient.start();
})();
2018-03-26 14:07:27 +00:00
2018-04-16 13:03:54 +00:00
async function runSetupWizard() {
2018-07-14 14:26:18 +00:00
const setup = new SetupWizard();
const values = await setup.start();
return values;
2018-04-16 13:03:54 +00:00
}
async function saveSetupWizardValues(values) {
2018-07-14 14:26:18 +00:00
const {
companyName,
country,
name,
email,
abbreviation,
bankName,
fiscalYearStart,
fiscalYearEnd
} = values;
const doc = await frappe.getDoc('AccountingSettings');
await doc.set('companyName', companyName);
await doc.set('country', country);
await doc.set('fullname', name);
await doc.set('email', email);
await doc.set('bankName', bankName);
await doc.set('fiscalYearStart', fiscalYearStart);
await doc.set('fiscalYearEnd', fiscalYearEnd);
await doc.update();
2018-04-16 13:03:54 +00:00
}
async function bootstrapChartOfAccounts() {
2018-07-14 14:26:18 +00:00
const importCOA = require('../models/doctype/account/importCOA');
const chart = require('../fixtures/standardCOA');
await importCOA(chart);
2018-04-16 13:03:54 +00:00
}