mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
Merge pull request #237 from 18alantom/fix-db-load
fix: issues with db loading
This commit is contained in:
commit
49cf248247
16
src/App.vue
16
src/App.vue
@ -45,9 +45,10 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
async activeScreen(value) {
|
async activeScreen(value) {
|
||||||
if (!value) return;
|
if (!value) return;
|
||||||
const { width, height } = ipcRenderer.invoke(
|
const { width, height } = await ipcRenderer.invoke(
|
||||||
IPC_ACTIONS.GET_PRIMARY_DISPLAY_SIZE
|
IPC_ACTIONS.GET_PRIMARY_DISPLAY_SIZE
|
||||||
);
|
);
|
||||||
|
|
||||||
let size = {
|
let size = {
|
||||||
Desk: [width, height],
|
Desk: [width, height],
|
||||||
DatabaseSelector: [600, 600],
|
DatabaseSelector: [600, 600],
|
||||||
@ -69,12 +70,15 @@ export default {
|
|||||||
WindowsTitleBar,
|
WindowsTitleBar,
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
let lastSelectedFilePath = config.get('lastSelectedFilePath', null);
|
const lastSelectedFilePath = config.get('lastSelectedFilePath', null);
|
||||||
if (!lastSelectedFilePath) {
|
const connectionSuccess = await connectToLocalDatabase(
|
||||||
this.activeScreen = 'DatabaseSelector';
|
lastSelectedFilePath
|
||||||
} else {
|
);
|
||||||
await connectToLocalDatabase(lastSelectedFilePath);
|
|
||||||
|
if (connectionSuccess) {
|
||||||
this.showSetupWizardOrDesk();
|
this.showSetupWizardOrDesk();
|
||||||
|
} else {
|
||||||
|
this.activeScreen = 'DatabaseSelector';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -139,7 +139,7 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.files = config.get('files', []);
|
this.files = config.get('files', []).filter(({filepath}) => fs.existsSync(filepath));
|
||||||
this.showFiles = this.files.length > 0;
|
this.showFiles = this.files.length > 0;
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -159,9 +159,14 @@ export default {
|
|||||||
},
|
},
|
||||||
async connectToDatabase(filePath) {
|
async connectToDatabase(filePath) {
|
||||||
this.loadingDatabase = true;
|
this.loadingDatabase = true;
|
||||||
await connectToLocalDatabase(filePath);
|
const connectionSuccess = await connectToLocalDatabase(filePath);
|
||||||
this.loadingDatabase = false;
|
this.loadingDatabase = false;
|
||||||
|
|
||||||
|
if(connectionSuccess) {
|
||||||
this.$emit('database-connect');
|
this.$emit('database-connect');
|
||||||
|
} else {
|
||||||
|
alert(frappe._("Please select an existing database or create a new one."))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getFileLastModified(filePath) {
|
getFileLastModified(filePath) {
|
||||||
let stats = fs.statSync(filePath);
|
let stats = fs.statSync(filePath);
|
||||||
|
@ -8,17 +8,17 @@
|
|||||||
<FormControl
|
<FormControl
|
||||||
:df="meta.getField('companyLogo')"
|
:df="meta.getField('companyLogo')"
|
||||||
:value="doc.companyLogo"
|
:value="doc.companyLogo"
|
||||||
@change="value => setValue('companyLogo', value)"
|
@change="(value) => setValue('companyLogo', value)"
|
||||||
/>
|
/>
|
||||||
<div class="ml-2">
|
<div class="ml-2">
|
||||||
<FormControl
|
<FormControl
|
||||||
ref="companyField"
|
ref="companyField"
|
||||||
:df="meta.getField('companyName')"
|
:df="meta.getField('companyName')"
|
||||||
:value="doc.companyName"
|
:value="doc.companyName"
|
||||||
@change="value => setValue('companyName', value)"
|
@change="(value) => setValue('companyName', value)"
|
||||||
:input-class="
|
:input-class="
|
||||||
classes => [
|
(classes) => [
|
||||||
'bg-transparent font-semibold text-xl text-white placeholder-blue-200 focus:outline-none focus:bg-blue-600 px-3 rounded py-1'
|
'bg-transparent font-semibold text-xl text-white placeholder-blue-200 focus:outline-none focus:bg-blue-600 px-3 rounded py-1',
|
||||||
]
|
]
|
||||||
"
|
"
|
||||||
:autofocus="true"
|
:autofocus="true"
|
||||||
@ -28,10 +28,10 @@
|
|||||||
<FormControl
|
<FormControl
|
||||||
:df="meta.getField('email')"
|
:df="meta.getField('email')"
|
||||||
:value="doc.email"
|
:value="doc.email"
|
||||||
@change="value => setValue('email', value)"
|
@change="(value) => setValue('email', value)"
|
||||||
:input-class="
|
:input-class="
|
||||||
classes => [
|
(classes) => [
|
||||||
'text-base bg-transparent text-white placeholder-blue-200 focus:bg-blue-600 focus:outline-none rounded px-3 py-1'
|
'text-base bg-transparent text-white placeholder-blue-200 focus:bg-blue-600 focus:outline-none rounded px-3 py-1',
|
||||||
]
|
]
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
@ -69,7 +69,7 @@ import Popover from '@/components/Popover';
|
|||||||
import {
|
import {
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
handleErrorWithDialog,
|
handleErrorWithDialog,
|
||||||
showMessageDialog
|
showMessageDialog,
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -79,20 +79,20 @@ export default {
|
|||||||
doc: null,
|
doc: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
valuesFilled: false,
|
valuesFilled: false,
|
||||||
emailError: null
|
emailError: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
return {
|
return {
|
||||||
doctype: 'SetupWizard',
|
doctype: 'SetupWizard',
|
||||||
name: 'SetupWizard'
|
name: 'SetupWizard',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
TwoColumnForm,
|
TwoColumnForm,
|
||||||
FormControl,
|
FormControl,
|
||||||
Button,
|
Button,
|
||||||
Popover
|
Popover,
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
this.doc = await frappe.newDoc({ doctype: 'SetupWizard' });
|
this.doc = await frappe.newDoc({ doctype: 'SetupWizard' });
|
||||||
@ -103,7 +103,7 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
setValue(fieldname, value) {
|
setValue(fieldname, value) {
|
||||||
this.emailError = null;
|
this.emailError = null;
|
||||||
this.doc.set(fieldname, value).catch(e => {
|
this.doc.set(fieldname, value).catch((e) => {
|
||||||
// set error
|
// set error
|
||||||
if (fieldname === 'email') {
|
if (fieldname === 'email') {
|
||||||
this.emailError = getErrorMessage(e, this.doc);
|
this.emailError = getErrorMessage(e, this.doc);
|
||||||
@ -112,7 +112,7 @@ export default {
|
|||||||
},
|
},
|
||||||
allValuesFilled() {
|
allValuesFilled() {
|
||||||
let values = this.meta.quickEditFields.map(
|
let values = this.meta.quickEditFields.map(
|
||||||
fieldname => this.doc[fieldname]
|
(fieldname) => this.doc[fieldname]
|
||||||
);
|
);
|
||||||
return values.every(Boolean);
|
return values.every(Boolean);
|
||||||
},
|
},
|
||||||
@ -127,10 +127,19 @@ export default {
|
|||||||
this.$emit('setup-complete');
|
this.$emit('setup-complete');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
console.log(e, this.doc);
|
||||||
|
if (e.type === frappe.errors.DuplicateEntryError) {
|
||||||
|
// TODO: Add option to overwrite file from here.
|
||||||
|
const message = this._(
|
||||||
|
'Records already exist in the db. Please create a new database file and try again.'
|
||||||
|
);
|
||||||
|
showMessageDialog({ message });
|
||||||
|
} else {
|
||||||
handleErrorWithDialog(e, this.doc);
|
handleErrorWithDialog(e, this.doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
meta() {
|
meta() {
|
||||||
return frappe.getMeta('SetupWizard');
|
return frappe.getMeta('SetupWizard');
|
||||||
@ -140,7 +149,7 @@ export default {
|
|||||||
},
|
},
|
||||||
buttonText() {
|
buttonText() {
|
||||||
return this.loading ? this._('Setting Up...') : this._('Next');
|
return this.loading ? this._('Setting Up...') : this._('Next');
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import frappe from 'frappejs';
|
import frappe from 'frappejs';
|
||||||
import countryList from '~/fixtures/countryInfo.json';
|
import countryList from '~/fixtures/countryInfo.json';
|
||||||
|
import generateTaxes from '../../../models/doctype/Tax/RegionalChanges';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
|
|
||||||
export default async function setupCompany(setupWizardValues) {
|
export default async function setupCompany(setupWizardValues) {
|
||||||
@ -96,10 +97,9 @@ async function setupChartOfAccounts(bankName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setupRegionalChanges(country) {
|
async function setupRegionalChanges(country) {
|
||||||
const generateRegionalTaxes = await import('~/models/doctype/Tax/RegionalChanges');
|
await generateTaxes(country);
|
||||||
await generateRegionalTaxes(country);
|
|
||||||
if (country === 'India') {
|
if (country === 'India') {
|
||||||
frappe.models.Party = await import('~/models/doctype/Party/RegionalChanges');
|
frappe.models.Party = await import('../../../models/doctype/Party/RegionalChanges');
|
||||||
await frappe.db.migrate();
|
await frappe.db.migrate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
src/utils.js
28
src/utils.js
@ -36,7 +36,12 @@ export async function createNewDatabase() {
|
|||||||
return filePath;
|
return filePath;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ label: _('Cancel'), action() {} },
|
{
|
||||||
|
label: _('Cancel'),
|
||||||
|
action() {
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -63,11 +68,19 @@ export async function loadExistingDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function connectToLocalDatabase(filepath) {
|
export async function connectToLocalDatabase(filepath) {
|
||||||
|
if (!filepath) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
frappe.login('Administrator');
|
frappe.login('Administrator');
|
||||||
|
try {
|
||||||
frappe.db = new SQLite({
|
frappe.db = new SQLite({
|
||||||
dbPath: filepath,
|
dbPath: filepath,
|
||||||
});
|
});
|
||||||
await frappe.db.connect();
|
await frappe.db.connect();
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
await migrate();
|
await migrate();
|
||||||
await postStart();
|
await postStart();
|
||||||
|
|
||||||
@ -86,6 +99,7 @@ export async function connectToLocalDatabase(filepath) {
|
|||||||
|
|
||||||
// set last selected file
|
// set last selected file
|
||||||
config.set('lastSelectedFilePath', filepath);
|
config.set('lastSelectedFilePath', filepath);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function showMessageDialog({
|
export async function showMessageDialog({
|
||||||
@ -188,13 +202,15 @@ export function openQuickEdit({ doctype, name, hideFields, defaults = {} }) {
|
|||||||
|
|
||||||
export function getErrorMessage(e, doc) {
|
export function getErrorMessage(e, doc) {
|
||||||
let errorMessage = e.message || _('An error occurred');
|
let errorMessage = e.message || _('An error occurred');
|
||||||
if (e.type === frappe.errors.LinkValidationError) {
|
const { doctype, name } = doc;
|
||||||
|
const canElaborate = doctype && name;
|
||||||
|
if (e.type === frappe.errors.LinkValidationError && canElaborate) {
|
||||||
errorMessage = _('{0} {1} is linked with existing records.', [
|
errorMessage = _('{0} {1} is linked with existing records.', [
|
||||||
doc.doctype,
|
doctype,
|
||||||
doc.name,
|
name,
|
||||||
]);
|
]);
|
||||||
} else if (e.type === frappe.errors.DuplicateEntryError) {
|
} else if (e.type === frappe.errors.DuplicateEntryError && canElaborate) {
|
||||||
errorMessage = _('{0} {1} already exists.', [doc.doctype, doc.name]);
|
errorMessage = _('{0} {1} already exists.', [doctype, name]);
|
||||||
}
|
}
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user