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

feat: add CoA selection to Setup Wizard

This commit is contained in:
18alantom 2022-02-21 11:48:32 +05:30 committed by Alan
parent ace1d4204d
commit 73253212c5
5 changed files with 60 additions and 2 deletions

View File

@ -92,6 +92,7 @@ module.exports = {
this.methods = {};
this.errorLog = [];
// temp params while calling routes
this.temp = {};
this.params = {};
},

View File

@ -1,6 +1,7 @@
import { t } from 'frappe';
import { DateTime } from 'luxon';
import countryList from '~/fixtures/countryInfo.json';
import { getCOAList } from '../../../src/utils';
export default {
name: 'SetupWizard',
@ -116,12 +117,37 @@ export default {
fieldtype: 'Check',
readonly: 1,
},
{
fieldname: 'chartOfAccounts',
label: t`Chart of Accounts`,
fieldtype: 'AutoComplete',
placeholder: t`Select CoA`,
formulaDependsOn: ['country'],
formula: async (doc) => {
if (!doc.country) return;
const { code } = countryList[doc.country];
const coaList = await getCOAList();
const coa = coaList.find(({ countryCode }) => countryCode === code);
if (coa === undefined) {
return coaList[0].name;
}
return coa.name;
},
getList: async () =>
(await getCOAList()).map(({ name, countryCode }) => ({
label: name,
value: countryCode,
})),
},
],
quickEditFields: [
'fullname',
'bankName',
'country',
'currency',
'chartOfAccounts',
'fiscalYearStart',
'fiscalYearEnd',
],

View File

@ -233,6 +233,28 @@ ipcMain.handle(IPC_ACTIONS.GET_LANGUAGE_MAP, async (event, code) => {
return obj;
});
ipcMain.handle(IPC_ACTIONS.GET_COA_LIST, async () => {
const p = path.resolve('./fixtures/verified');
const files = await fs.readdir(p);
const coas = [];
for (let file of files) {
if (!file.endsWith('.json')) {
continue;
}
const fh = await fs.open(path.join(p, file));
const json = await fh.readFile({ encoding: 'utf-8' });
const { name, countryCode } = JSON.parse(json);
if (name === undefined) {
continue;
}
coas.push({ name, countryCode });
}
return coas;
});
/* ------------------------------
* Register autoUpdater events lis
* ------------------------------*/

View File

@ -25,6 +25,7 @@ export const IPC_ACTIONS = {
SEND_ERROR: 'send-error',
GET_LANGUAGE_MAP: 'get-language-map',
CHECK_FOR_UPDATES: 'check-for-updates',
GET_COA_LIST: 'get-coa-list',
};
// ipcMain.send(...)

View File

@ -6,7 +6,6 @@ import frappe, { t } from 'frappe';
import { isPesa } from 'frappe/utils';
import { DEFAULT_LANGUAGE } from 'frappe/utils/consts';
import { setLanguageMapOnTranslationString } from 'frappe/utils/translation';
import lodash from 'lodash';
import { createApp, h } from 'vue';
import config from './config';
import { handleErrorWithDialog } from './errorHandling';
@ -367,7 +366,7 @@ export function titleCase(phrase) {
if (['and', 'an', 'a', 'from', 'by', 'on'].includes(wordLower)) {
return wordLower;
}
return lodash.capitalize(wordLower);
return wordLower[0].toUpperCase() + wordLower.slice(1);
})
.join(' ');
}
@ -513,3 +512,12 @@ function getLanguageCode(initLanguage, oldLanguage) {
}
return [languageCodeMap[language], language, usingDefault];
}
export async function getCOAList() {
if (!frappe.temp.coaList) {
const coaList = await ipcRenderer.invoke(IPC_ACTIONS.GET_COA_LIST);
coaList.unshift({ name: t`Standard Chart of Accounts`, countryCode: '' });
frappe.temp.coaList = coaList;
}
return frappe.temp.coaList;
}