mirror of
https://github.com/frappe/books.git
synced 2025-01-25 16:18:33 +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 { DB_CONN_FAILURE } from './messages';
|
||||||
import migrate from './migrate';
|
import migrate from './migrate';
|
||||||
import { getSavePath } from './utils';
|
import { 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');
|
||||||
@ -49,6 +50,8 @@ export async function connectToLocalDatabase(filePath) {
|
|||||||
return { connectionSuccess: false, reason: DB_CONN_FAILURE.CANT_CONNECT };
|
return { connectionSuccess: false, reason: DB_CONN_FAILURE.CANT_CONNECT };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await callInitializeMoneyMaker();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await runRegionalModelUpdates();
|
await runRegionalModelUpdates();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -3,6 +3,7 @@ import frappe from 'frappejs';
|
|||||||
import countryList from '~/fixtures/countryInfo.json';
|
import countryList from '~/fixtures/countryInfo.json';
|
||||||
import generateTaxes from '../../../models/doctype/Tax/RegionalEntries';
|
import generateTaxes from '../../../models/doctype/Tax/RegionalEntries';
|
||||||
import regionalModelUpdates from '../../../models/regionalModelUpdates';
|
import regionalModelUpdates from '../../../models/regionalModelUpdates';
|
||||||
|
import { callInitializeMoneyMaker } from '../../utils';
|
||||||
|
|
||||||
export default async function setupCompany(setupWizardValues) {
|
export default async function setupCompany(setupWizardValues) {
|
||||||
const {
|
const {
|
||||||
@ -17,6 +18,9 @@ export default async function setupCompany(setupWizardValues) {
|
|||||||
} = setupWizardValues;
|
} = setupWizardValues;
|
||||||
|
|
||||||
const accountingSettings = frappe.AccountingSettings;
|
const accountingSettings = frappe.AccountingSettings;
|
||||||
|
const currency = countryList[country]['currency'];
|
||||||
|
await callInitializeMoneyMaker(currency);
|
||||||
|
|
||||||
await accountingSettings.update({
|
await accountingSettings.update({
|
||||||
companyName,
|
companyName,
|
||||||
country,
|
country,
|
||||||
@ -25,7 +29,7 @@ export default async function setupCompany(setupWizardValues) {
|
|||||||
bankName,
|
bankName,
|
||||||
fiscalYearStart,
|
fiscalYearStart,
|
||||||
fiscalYearEnd,
|
fiscalYearEnd,
|
||||||
currency: countryList[country]['currency'],
|
currency,
|
||||||
});
|
});
|
||||||
|
|
||||||
const printSettings = await frappe.getSingle('PrintSettings');
|
const printSettings = await frappe.getSingle('PrintSettings');
|
||||||
|
36
src/utils.js
36
src/utils.js
@ -351,3 +351,39 @@ export function titleCase(phrase) {
|
|||||||
})
|
})
|
||||||
.join(' ');
|
.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…
x
Reference in New Issue
Block a user