Skip to content

Commit

Permalink
fix: COA issue; TIL webpack bundles jsons -_-
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Feb 25, 2022
1 parent eade577 commit c49c742
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion accounting/importCOA.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function identifyIsGroup(child) {
}

export async function getCountryCOA(chartOfAccounts) {
const coaList = await getCOAList();
const coaList = getCOAList();
const coa = coaList.find(({ name }) => name === chartOfAccounts);
const conCode = coa.countryCode;
if (!conCode) {
Expand Down
4 changes: 2 additions & 2 deletions models/doctype/SetupWizard/SetupWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ export default {
if (!doc.country) return;

const { code } = countryList[doc.country];
const coaList = await getCOAList();
const coaList = getCOAList();
const coa = coaList.find(({ countryCode }) => countryCode === code);

if (coa === undefined) {
return coaList[0].name;
}
return coa.name;
},
getList: async () => (await getCOAList()).map(({ name }) => name),
getList: () => getCOAList().map(({ name }) => name),
},
],
quickEditFields: [
Expand Down
22 changes: 0 additions & 22 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,28 +233,6 @@ 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;
});

ipcMain.handle(IPC_ACTIONS.GET_FILE, async (event, options) => {
const response = {
name: '',
Expand Down
1 change: 0 additions & 1 deletion src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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',
GET_FILE: 'get-file',
};

Expand Down
21 changes: 18 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,25 @@ function getLanguageCode(initLanguage, oldLanguage) {
return [languageCodeMap[language], language, usingDefault];
}

export async function getCOAList() {
export 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: '' });
const coaList = [
{ name: t`Standard Chart of Accounts`, countryCode: '' },

{ countryCode: 'ae', name: 'U.A.E - Chart of Accounts' },
{
countryCode: 'ca',
name: 'Canada - Plan comptable pour les provinces francophones',
},
{ countryCode: 'gt', name: 'Guatemala - Cuentas' },
{ countryCode: 'hu', name: 'Hungary - Chart of Accounts' },
{ countryCode: 'id', name: 'Indonesia - Chart of Accounts' },
{ countryCode: 'in', name: 'India - Chart of Accounts' },
{ countryCode: 'mx', name: 'Mexico - Plan de Cuentas' },
{ countryCode: 'ni', name: 'Nicaragua - Catalogo de Cuentas' },
{ countryCode: 'nl', name: 'Netherlands - Grootboekschema' },
{ countryCode: 'sg', name: 'Singapore - Chart of Accounts' },
];
frappe.temp.coaList = coaList;
}
return frappe.temp.coaList;
Expand Down

0 comments on commit c49c742

Please sign in to comment.