mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
fix: Move importCOA file to accounting
This commit is contained in:
parent
c846118055
commit
1e44cc9fae
@ -1,8 +1,6 @@
|
||||
const frappe = require('frappejs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const countries = require('../../../fixtures/countryInfo.json');
|
||||
const standardCOA = require('../../../fixtures/verified/standardCOA.json');
|
||||
const countries = require('../fixtures/countryInfo.json');
|
||||
const standardCOA = require('../fixtures/verified/standardCOA.json');
|
||||
const accountFields = [
|
||||
'accountType',
|
||||
'rootType',
|
||||
@ -59,9 +57,7 @@ async function getCountryCOA() {
|
||||
const conCode = countries[doc.country].code;
|
||||
|
||||
try {
|
||||
const countryCoa = require('../../../fixtures/verified/' +
|
||||
conCode +
|
||||
'.json');
|
||||
const countryCoa = require('../fixtures/verified/' + conCode + '.json');
|
||||
return countryCoa.tree;
|
||||
} catch (e) {
|
||||
return standardCOA;
|
@ -1,74 +0,0 @@
|
||||
const frappe = require('frappejs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const countries = require('../../../fixtures/countryInfo.json');
|
||||
const standardCOA = require('../../../fixtures/verified/standardCOA.json');
|
||||
const accountFields = [
|
||||
'accountType',
|
||||
'rootType',
|
||||
'isGroup',
|
||||
'account_type',
|
||||
'root_type',
|
||||
'is_group'
|
||||
];
|
||||
|
||||
async function importAccounts(children, parent, rootType, rootAccount) {
|
||||
for (let accountName in children) {
|
||||
const child = children[accountName];
|
||||
|
||||
if (rootAccount) {
|
||||
rootType = child.rootType || child.root_type;
|
||||
}
|
||||
|
||||
if (!accountFields.includes(accountName)) {
|
||||
let isGroup = identifyIsGroup(child);
|
||||
const doc = frappe.newDoc({
|
||||
doctype: 'Account',
|
||||
name: accountName,
|
||||
parentAccount: parent,
|
||||
isGroup,
|
||||
rootType,
|
||||
balance: 0,
|
||||
accountType: child.accountType || child.account_type
|
||||
});
|
||||
|
||||
await doc.insert();
|
||||
|
||||
await importAccounts(child, accountName, rootType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function identifyIsGroup(child) {
|
||||
if (child.isGroup || child.is_group) {
|
||||
return child.isGroup || child.is_group;
|
||||
}
|
||||
|
||||
const keys = Object.keys(child);
|
||||
const children = keys.filter(key => !accountFields.includes(key));
|
||||
|
||||
if (children.length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
async function getCountryCOA() {
|
||||
const doc = await frappe.getDoc('AccountingSettings');
|
||||
const conCode = countries[doc.country].code;
|
||||
|
||||
try {
|
||||
const countryCoa = require('../../../fixtures/verified/' +
|
||||
conCode +
|
||||
'.json');
|
||||
return countryCoa.tree;
|
||||
} catch (e) {
|
||||
return standardCOA;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = async function importCharts() {
|
||||
const chart = await getCountryCOA();
|
||||
await importAccounts(chart, '', '', true);
|
||||
};
|
@ -7,7 +7,7 @@ module.exports = function registerServerMethods() {
|
||||
frappe.registerMethod({
|
||||
method: 'import-coa',
|
||||
async handler() {
|
||||
const importCOA = require('../models/doctype/Account/importCOA');
|
||||
const importCOA = require('../accounting/importCOA');
|
||||
await importCOA();
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user