diff --git a/src/initialization.js b/src/initialization.js index 96845fc90..c5aed050a 100644 --- a/src/initialization.js +++ b/src/initialization.js @@ -8,6 +8,7 @@ import regionalModelUpdates from '../models/regionalModelUpdates'; import postStart from '../server/postStart'; import { IPC_ACTIONS } from './messages'; import migrate from './migrate'; +import { callInitializeMoneyMaker } from './utils'; export async function createNewDatabase() { const options = { @@ -66,6 +67,8 @@ export async function connectToLocalDatabase(filePath) { return false; } + await callInitializeMoneyMaker(); + try { await runRegionalModelUpdates(); } catch (error) { diff --git a/src/pages/SetupWizard/setupCompany.js b/src/pages/SetupWizard/setupCompany.js index fee6deed4..1f670220d 100644 --- a/src/pages/SetupWizard/setupCompany.js +++ b/src/pages/SetupWizard/setupCompany.js @@ -3,6 +3,7 @@ import frappe from 'frappejs'; import countryList from '~/fixtures/countryInfo.json'; import generateTaxes from '../../../models/doctype/Tax/RegionalEntries'; import regionalModelUpdates from '../../../models/regionalModelUpdates'; +import { callInitializeMoneyMaker } from '../../utils'; export default async function setupCompany(setupWizardValues) { const { @@ -17,6 +18,9 @@ export default async function setupCompany(setupWizardValues) { } = setupWizardValues; const accountingSettings = frappe.AccountingSettings; + const currency = countryList[country]['currency']; + await callInitializeMoneyMaker(currency); + await accountingSettings.update({ companyName, country, @@ -25,7 +29,7 @@ export default async function setupCompany(setupWizardValues) { bankName, fiscalYearStart, fiscalYearEnd, - currency: countryList[country]['currency'], + currency, }); const printSettings = await frappe.getSingle('PrintSettings'); diff --git a/src/utils.js b/src/utils.js index 6f08f09ed..fbbdba46b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -292,3 +292,39 @@ export function fuzzyMatch(keyword, candidate) { export function openSettings(tab) { routeTo({ path: '/settings', query: { tab } }); } + +export async function getIsSetupComplete() { + try { + const { setupComplete } = await frappe.getSingle('AccountingSettings'); + return !!setupComplete; + } catch { + return false; + } +} + +export async function getCurrency() { + let currency = frappe?.AccoutingSettings?.currency ?? undefined; + + if (!currency) { + try { + currency = ( + await frappe.db.getSingleValues({ + fieldname: 'currency', + parent: 'AccountingSettings', + }) + )[0].value; + } catch (err) { + currency = undefined; + } + } + + return currency; +} + +export async function callInitializeMoneyMaker(currency) { + currency ??= await getCurrency(); + if (!currency && frappe.pesa) { + return; + } + await frappe.initializeMoneyMaker(currency); +}