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

fix: init pesa with correct currency

This commit is contained in:
18alantom 2021-12-31 13:02:29 +05:30
parent 5ad858ede7
commit 595341c2aa
2 changed files with 10 additions and 3 deletions

View File

@ -6,8 +6,7 @@ import regionalModelUpdates from '../models/regionalModelUpdates';
import postStart from '../server/postStart'; import postStart from '../server/postStart';
import { DB_CONN_FAILURE } from './messages'; import { DB_CONN_FAILURE } from './messages';
import migrate from './migrate'; import migrate from './migrate';
import { getSavePath } from './utils'; import { callInitializeMoneyMaker, getSavePath } from './utils';
import { callInitializeMoneyMaker } from './utils';
export async function createNewDatabase() { export async function createNewDatabase() {
const { canceled, filePath } = await getSavePath('books', 'db'); const { canceled, filePath } = await getSavePath('books', 'db');
@ -50,6 +49,7 @@ export async function connectToLocalDatabase(filePath) {
return { connectionSuccess: false, reason: DB_CONN_FAILURE.CANT_CONNECT }; return { connectionSuccess: false, reason: DB_CONN_FAILURE.CANT_CONNECT };
} }
// first init no currency, for migratory needs
await callInitializeMoneyMaker(); await callInitializeMoneyMaker();
try { try {
@ -90,6 +90,9 @@ export async function connectToLocalDatabase(filePath) {
// set last selected file // set last selected file
config.set('lastSelectedFilePath', filePath); config.set('lastSelectedFilePath', filePath);
// second init with currency, normal usage
await callInitializeMoneyMaker();
return { connectionSuccess: true, reason: '' }; return { connectionSuccess: true, reason: '' };
} }

View File

@ -362,7 +362,7 @@ export async function getIsSetupComplete() {
} }
export async function getCurrency() { export async function getCurrency() {
let currency = frappe?.AccoutingSettings?.currency ?? undefined; let currency = frappe?.AccountingSettings?.currency ?? undefined;
if (!currency) { if (!currency) {
try { try {
@ -385,6 +385,10 @@ export async function callInitializeMoneyMaker(currency) {
if (!currency && frappe.pesa) { if (!currency && frappe.pesa) {
return; return;
} }
if (currency && frappe.pesa().options.currency === currency) {
return;
}
await frappe.initializeMoneyMaker(currency); await frappe.initializeMoneyMaker(currency);
} }