From 595341c2aa3800435e81c2bc97c87cc99513dd1e Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Fri, 31 Dec 2021 13:02:29 +0530 Subject: [PATCH] fix: init pesa with correct currency --- src/initialization.js | 7 +++++-- src/utils.js | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/initialization.js b/src/initialization.js index e61be3c2..b6987710 100644 --- a/src/initialization.js +++ b/src/initialization.js @@ -6,8 +6,7 @@ import regionalModelUpdates from '../models/regionalModelUpdates'; import postStart from '../server/postStart'; import { DB_CONN_FAILURE } from './messages'; import migrate from './migrate'; -import { getSavePath } from './utils'; -import { callInitializeMoneyMaker } from './utils'; +import { callInitializeMoneyMaker, getSavePath } from './utils'; export async function createNewDatabase() { 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 }; } + // first init no currency, for migratory needs await callInitializeMoneyMaker(); try { @@ -90,6 +90,9 @@ export async function connectToLocalDatabase(filePath) { // set last selected file config.set('lastSelectedFilePath', filePath); + + // second init with currency, normal usage + await callInitializeMoneyMaker(); return { connectionSuccess: true, reason: '' }; } diff --git a/src/utils.js b/src/utils.js index 725f51a6..2aed68c6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -362,7 +362,7 @@ export async function getIsSetupComplete() { } export async function getCurrency() { - let currency = frappe?.AccoutingSettings?.currency ?? undefined; + let currency = frappe?.AccountingSettings?.currency ?? undefined; if (!currency) { try { @@ -385,6 +385,10 @@ export async function callInitializeMoneyMaker(currency) { if (!currency && frappe.pesa) { return; } + + if (currency && frappe.pesa().options.currency === currency) { + return; + } await frappe.initializeMoneyMaker(currency); }