mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
refactor: shift pesa init with currency to books
This commit is contained in:
parent
2dd4906788
commit
4650b1eeda
@ -7,6 +7,7 @@ import postStart from '../server/postStart';
|
||||
import { DB_CONN_FAILURE } from './messages';
|
||||
import migrate from './migrate';
|
||||
import { getSavePath } from './utils';
|
||||
import { callInitializeMoneyMaker } from './utils';
|
||||
|
||||
export async function createNewDatabase() {
|
||||
const { canceled, filePath } = await getSavePath('books', 'db');
|
||||
@ -49,6 +50,8 @@ export async function connectToLocalDatabase(filePath) {
|
||||
return { connectionSuccess: false, reason: DB_CONN_FAILURE.CANT_CONNECT };
|
||||
}
|
||||
|
||||
await callInitializeMoneyMaker();
|
||||
|
||||
try {
|
||||
await runRegionalModelUpdates();
|
||||
} catch (error) {
|
||||
|
@ -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');
|
||||
|
36
src/utils.js
36
src/utils.js
@ -351,3 +351,39 @@ export function titleCase(phrase) {
|
||||
})
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user