2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 19:09:01 +00:00

Initialize db in electron entry

This commit is contained in:
Faris Ansari 2018-10-21 18:19:33 +05:30
parent 5a7a8c8efe
commit dfbddd651a
4 changed files with 54 additions and 45 deletions

View File

@ -2,7 +2,7 @@ const path = require('path');
const server = require('frappejs/server');
const frappe = require('frappejs');
const naming = require('frappejs/model/naming');
const registerReportMethods = require('../reports');
const registerServerMethods = require('./registerServerMethods');
async function start() {
await server.start({
@ -36,16 +36,7 @@ async function postStart() {
await naming.createNumberSeries('PO-', 'PurchaseOrderSettings');
await naming.createNumberSeries('PREC-', 'PurchaseReceiptSettings');
registerReportMethods();
frappe.registerMethod({
method: 'import-coa',
async handler() {
const standardCOA = require('../fixtures/standardCOA');
const importCOA = require('../models/doctype/Account/importCOA');
await importCOA(standardCOA);
}
})
registerServerMethods();
}
start();

View File

@ -0,0 +1,15 @@
const frappe = require('frappejs');
const registerReportMethods = require('../reports');
module.exports = function registerServerMethods() {
registerReportMethods();
frappe.registerMethod({
method: 'import-coa',
async handler() {
const standardCOA = require('../fixtures/standardCOA');
const importCOA = require('../models/doctype/Account/importCOA');
await importCOA(standardCOA);
}
});
}

View File

@ -1,3 +1,4 @@
const path = require('path');
const { app, BrowserWindow } = require('electron');
const { getAppConfig } = require('frappejs/webpack/utils');
const setupMenu = require('./menu');
@ -5,7 +6,7 @@ const setupMenu = require('./menu');
const appConfig = getAppConfig();
if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\')
}
let mainWindow

View File

@ -6,46 +6,48 @@ import frappeVue from 'frappejs/ui/plugins/frappeVue';
// frappejs imports
import frappe from 'frappejs';
import frappeConf from '../frappe.conf';
import HTTPClient from 'frappejs/backends/http';
import SQLite from 'frappejs/backends/sqlite';
import common from 'frappejs/common';
import coreModels from 'frappejs/models';
import models from '../models';
import registerReportMethods from '../reports';
import registerServerMethods from '../server/registerServerMethods';
console.log('electron is here')
(async () => {
frappe.isServer = true;
frappe.init();
frappe.registerLibs(common);
frappe.registerModels(coreModels);
frappe.registerModels(models);
frappe.fetch = window.fetch.bind();
frappe.login('Administrator');
frappe.db = new SQLite({ dbPath: 'test.db' });
await frappe.db.connect();
await frappe.db.migrate();
frappe.init();
frappe.registerLibs(common);
frappe.registerModels(coreModels);
frappe.registerModels(models);
frappe.fetch = window.fetch.bind();
frappe.db = new SQLite({ dbPath: 'test.db' });
frappe.getSingle('SystemSettings');
registerServerMethods();
frappe.getSingle('SystemSettings');
registerReportMethods();
frappe.getSingle('AccountingSettings')
.then(accountingSettings => {
if (router.currentRoute.fullPath !== '/') return;
frappe.getSingle('AccountingSettings')
.then(accountingSettings => {
if (router.currentRoute.fullPath !== '/') return;
if (accountingSettings.companyName) {
router.push('/tree/Account');
} else {
router.push('/setup-wizard');
}
});
if (accountingSettings.companyName) {
router.push('/tree/Account');
} else {
router.push('/setup-wizard');
}
window.frappe = frappe;
Vue.config.productionTip = false;
Vue.use(frappeVue);
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
});
window.frappe = frappe;
Vue.config.productionTip = false;
Vue.use(frappeVue);
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
});
})()