mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
Refactor electron client code
This commit is contained in:
parent
a8028b8708
commit
82e0129011
@ -6,9 +6,6 @@ module.exports = {
|
||||
// require modules
|
||||
frappe.registerModels(require('../models'), 'client');
|
||||
|
||||
frappe.registerView('List', 'ToDo', require('frappejs/models/doctype/ToDo/ToDoList.js'));
|
||||
frappe.registerView('Form', 'FilterSelector', require('frappejs/models/doctype/FilterSelector/FilterSelectorForm.js'));
|
||||
|
||||
frappe.registerView('List', 'Customer', require('../models/doctype/Party/CustomerList.js'));
|
||||
|
||||
frappe.router.add('report/general-ledger', async (params) => {
|
||||
@ -26,6 +23,7 @@ module.exports = {
|
||||
frappe.desk.menu.addItem('Address', "#list/Address");
|
||||
frappe.desk.menu.addItem('Contact', "#list/Contact");
|
||||
frappe.desk.menu.addItem('Settings', () => frappe.desk.showFormModal('SystemSettings'));
|
||||
frappe.desk.menu.addItem('General Ledger', '#report/general-ledger');
|
||||
|
||||
frappe.router.default = '#tree/Account';
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
const frappe = require('frappejs');
|
||||
const path = require('path');
|
||||
const electron = require('frappejs/client/electron');
|
||||
const { writeFile } = require('frappejs/server/utils');
|
||||
const appClient = require('../client');
|
||||
const SetupWizard = require('../setup');
|
||||
const { getPDFForElectron } = require('frappejs/server/pdf');
|
||||
const { getSettings, saveSettings } = require('./settings');
|
||||
const { postStart } = require('../server');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
@ -13,79 +14,70 @@ require.extensions['.html'] = function (module, filename) {
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const configFilePath = path.join(require('os').homedir(), '.config', 'frappe-accounting', 'settings.json');
|
||||
let electronSettings = getSettings();
|
||||
let firstRun = false, setupWizardValues = null;
|
||||
|
||||
let settings, dbPath;
|
||||
try {
|
||||
settings = require(configFilePath);
|
||||
} catch(e) {
|
||||
settings = {}
|
||||
if (!electronSettings.dbPath) {
|
||||
const values = await runSetupWizard();
|
||||
const dbPath = path.join(values.file[0].path, frappe.slug(values.companyName) + '.db');
|
||||
const config = {
|
||||
directory: path.dirname(dbPath),
|
||||
dbPath: dbPath
|
||||
};
|
||||
await saveSettings(config);
|
||||
|
||||
firstRun = true;
|
||||
electronSettings = config;
|
||||
setupWizardValues = values;
|
||||
}
|
||||
|
||||
frappe.electronConfig = settings;
|
||||
await electron.start({
|
||||
dbPath: electronSettings.dbPath,
|
||||
models: require('../models')
|
||||
});
|
||||
|
||||
// await postStart();
|
||||
|
||||
if (firstRun) {
|
||||
await saveSetupWizardValues(values);
|
||||
await bootstrapChartOfAccounts();
|
||||
}
|
||||
|
||||
frappe.getPDF = getPDFForElectron;
|
||||
frappe.electronSettings = electronSettings;
|
||||
|
||||
if (settings.dbPath) {
|
||||
dbPath = settings.dbPath;
|
||||
electron.start({
|
||||
dbPath,
|
||||
models: require('../models')
|
||||
}).then(() => {
|
||||
|
||||
frappe.syncDoc(require('../fixtures/invoicePrint'));
|
||||
appClient.start();
|
||||
});
|
||||
} else {
|
||||
const setup = new SetupWizard();
|
||||
window.setup = setup;
|
||||
const values = await setup.start();
|
||||
const {
|
||||
companyName,
|
||||
file,
|
||||
country,
|
||||
name,
|
||||
email,
|
||||
abbreviation,
|
||||
bankName
|
||||
} = values;
|
||||
|
||||
dbPath = path.join(file[0].path, companyName + '.db');
|
||||
|
||||
electron.start({
|
||||
dbPath,
|
||||
models: require('../models')
|
||||
}).then(async () => {
|
||||
const config = {
|
||||
directory: path.dirname(dbPath),
|
||||
dbPath: dbPath
|
||||
};
|
||||
|
||||
await writeFile(configFilePath, JSON.stringify(config));
|
||||
|
||||
frappe.electronConfig = config;
|
||||
|
||||
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.update();
|
||||
|
||||
// bootstrap Chart of Accounts
|
||||
const importCOA = require('../models/doctype/account/importCOA');
|
||||
const chart = require('../fixtures/standardCOA');
|
||||
await importCOA(chart);
|
||||
|
||||
|
||||
frappe.syncDoc(require('../fixtures/invoicePrint'));
|
||||
appClient.start();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
appClient.start();
|
||||
})();
|
||||
|
||||
async function runSetupWizard() {
|
||||
const setup = new SetupWizard();
|
||||
const values = await setup.start();
|
||||
return values;
|
||||
}
|
||||
|
||||
async function saveSetupWizardValues(values) {
|
||||
const {
|
||||
companyName,
|
||||
country,
|
||||
name,
|
||||
email,
|
||||
abbreviation,
|
||||
bankName
|
||||
} = 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.update();
|
||||
}
|
||||
|
||||
async function bootstrapChartOfAccounts() {
|
||||
const importCOA = require('../models/doctype/account/importCOA');
|
||||
const chart = require('../fixtures/standardCOA');
|
||||
await importCOA(chart);
|
||||
}
|
||||
|
25
electron/settings.js
Normal file
25
electron/settings.js
Normal file
@ -0,0 +1,25 @@
|
||||
const os = require('os');
|
||||
const { writeFile } = require('frappejs/server/utils');
|
||||
|
||||
const homedir = os.homedir();
|
||||
const configFilePath = path.join(homedir, '.config', 'frappe-accounting', 'settings.json');
|
||||
|
||||
function getSettings() {
|
||||
let settings;
|
||||
try {
|
||||
settings = require(configFilePath);
|
||||
} catch (e) {
|
||||
settings = {}
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
async function saveSettings(settings) {
|
||||
await writeFile(configFilePath, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSettings,
|
||||
saveSettings
|
||||
}
|
@ -7,11 +7,15 @@ module.exports = {
|
||||
async start() {
|
||||
await server.start({
|
||||
backend: 'sqlite',
|
||||
connectionParams: {dbPath: 'test.db'},
|
||||
connectionParams: { dbPath: 'test.db' },
|
||||
staticPath: './www',
|
||||
models: require('../models')
|
||||
})
|
||||
|
||||
await this.postStart();
|
||||
},
|
||||
|
||||
async postStart() {
|
||||
// set server-side modules
|
||||
frappe.models.Invoice.documentClass = require('../models/doctype/Invoice/InvoiceServer.js');
|
||||
frappe.models.Payment.documentClass = require('../models/doctype/Payment/PaymentServer.js');
|
||||
|
Loading…
Reference in New Issue
Block a user