diff --git a/accounting/importCOA.js b/accounting/importCOA.js deleted file mode 100644 index c4315e42..00000000 --- a/accounting/importCOA.js +++ /dev/null @@ -1,78 +0,0 @@ -import frappe from 'fyo'; -import standardCOA from '../fixtures/verified/standardCOA.json'; -import { getCOAList } from '../src/utils'; -const accountFields = ['accountType', 'accountNumber', 'rootType', 'isGroup']; - -function getAccountName(accountName, accountNumber) { - if (accountNumber) { - return `${accountName} - ${accountNumber}`; - } - return accountName; -} - -async function importAccounts(children, parentAccount, rootType, rootAccount) { - for (let rootName in children) { - if (accountFields.includes(rootName)) { - continue; - } - - const child = children[rootName]; - - if (rootAccount) { - rootType = child.rootType; - } - - const { accountType, accountNumber } = child; - const accountName = getAccountName(rootName, accountNumber); - const isGroup = identifyIsGroup(child); - const doc = frappe.doc.getNewDoc('Account', { - name: accountName, - parentAccount, - isGroup, - rootType, - balance: 0, - accountType, - }); - - await doc.insert(); - await importAccounts(child, accountName, rootType); - } -} - -function identifyIsGroup(child) { - if (child.isGroup) { - return child.isGroup; - } - - const keys = Object.keys(child); - const children = keys.filter((key) => !accountFields.includes(key)); - - if (children.length) { - return 1; - } - - return 0; -} - -export async function getCountryCOA(chartOfAccounts) { - const coaList = getCOAList(); - const coa = coaList.find(({ name }) => name === chartOfAccounts); - const conCode = coa.countryCode; - if (!conCode) { - return standardCOA; - } - - try { - const countryCoa = ( - await import('../fixtures/verified/' + conCode + '.json') - ).default; - return countryCoa.tree; - } catch (e) { - return standardCOA; - } -} - -export default async function importCharts(chartOfAccounts) { - const chart = await getCountryCOA(chartOfAccounts); - await importAccounts(chart, '', '', true); -} diff --git a/fixtures/standardCOA.js b/fixtures/standardCOA.js deleted file mode 100644 index 2a1c481b..00000000 --- a/fixtures/standardCOA.js +++ /dev/null @@ -1,172 +0,0 @@ -import { t } from 'fyo'; - -export default { - [t`Application of Funds (Assets)`]: { - [t`Current Assets`]: { - [t`Accounts Receivable`]: { - [t`Debtors`]: { - accountType: 'Receivable', - }, - }, - [t`Bank Accounts`]: { - accountType: 'Bank', - isGroup: 1, - }, - [t`Cash In Hand`]: { - [t`Cash`]: { - accountType: 'Cash', - }, - accountType: 'Cash', - }, - [t`Loans and Advances (Assets)`]: { - isGroup: 1, - }, - [t`Securities and Deposits`]: { - [t`Earnest Money`]: {}, - }, - [t`Stock Assets`]: { - [t`Stock In Hand`]: { - accountType: 'Stock', - }, - accountType: 'Stock', - }, - [t`Tax Assets`]: { - isGroup: 1, - }, - }, - [t`Fixed Assets`]: { - [t`Capital Equipments`]: { - accountType: 'Fixed Asset', - }, - [t`Electronic Equipments`]: { - accountType: 'Fixed Asset', - }, - [t`Furnitures and Fixtures`]: { - accountType: 'Fixed Asset', - }, - [t`Office Equipments`]: { - accountType: 'Fixed Asset', - }, - [t`Plants and Machineries`]: { - accountType: 'Fixed Asset', - }, - [t`Buildings`]: { - accountType: 'Fixed Asset', - }, - [t`Softwares`]: { - accountType: 'Fixed Asset', - }, - [t`Accumulated Depreciation`]: { - accountType: 'Accumulated Depreciation', - }, - }, - [t`Investments`]: { - isGroup: 1, - }, - [t`Temporary Accounts`]: { - [t`Temporary Opening`]: { - accountType: 'Temporary', - }, - }, - rootType: 'Asset', - }, - [t`Expenses`]: { - [t`Direct Expenses`]: { - [t`Stock Expenses`]: { - [t`Cost of Goods Sold`]: { - accountType: 'Cost of Goods Sold', - }, - [t`Expenses Included In Valuation`]: { - accountType: 'Expenses Included In Valuation', - }, - [t`Stock Adjustment`]: { - accountType: 'Stock Adjustment', - }, - }, - }, - [t`Indirect Expenses`]: { - [t`Administrative Expenses`]: {}, - [t`Commission on Sales`]: {}, - [t`Depreciation`]: { - accountType: 'Depreciation', - }, - [t`Entertainment Expenses`]: {}, - [t`Freight and Forwarding Charges`]: { - accountType: 'Chargeable', - }, - [t`Legal Expenses`]: {}, - [t`Marketing Expenses`]: { - accountType: 'Chargeable', - }, - [t`Miscellaneous Expenses`]: { - accountType: 'Chargeable', - }, - [t`Office Maintenance Expenses`]: {}, - [t`Office Rent`]: {}, - [t`Postal Expenses`]: {}, - [t`Print and Stationery`]: {}, - [t`Round Off`]: { - accountType: 'Round Off', - }, - [t`Salary`]: {}, - [t`Sales Expenses`]: {}, - [t`Telephone Expenses`]: {}, - [t`Travel Expenses`]: {}, - [t`Utility Expenses`]: {}, - [t`Write Off`]: {}, - [t`Exchange Gain/Loss`]: {}, - [t`Gain/Loss on Asset Disposal`]: {}, - }, - rootType: 'Expense', - }, - [t`Income`]: { - [t`Direct Income`]: { - [t`Sales`]: {}, - [t`Service`]: {}, - }, - [t`Indirect Income`]: { - isGroup: 1, - }, - rootType: 'Income', - }, - [t`Source of Funds (Liabilities)`]: { - [t`Current Liabilities`]: { - [t`Accounts Payable`]: { - [t`Creditors`]: { - accountType: 'Payable', - }, - [t`Payroll Payable`]: {}, - }, - [t`Stock Liabilities`]: { - [t`Stock Received But Not Billed`]: { - accountType: 'Stock Received But Not Billed', - }, - }, - [t`Duties and Taxes`]: { - accountType: 'Tax', - isGroup: 1, - }, - [t`Loans (Liabilities)`]: { - [t`Secured Loans`]: {}, - [t`Unsecured Loans`]: {}, - [t`Bank Overdraft Account`]: {}, - }, - }, - rootType: 'Liability', - }, - [t`Equity`]: { - [t`Capital Stock`]: { - accountType: 'Equity', - }, - [t`Dividends Paid`]: { - accountType: 'Equity', - }, - [t`Opening Balance Equity`]: { - accountType: 'Equity', - }, - [t`Retained Earnings`]: { - accountType: 'Equity', - }, - rootType: 'Equity', - }, -}; diff --git a/fixtures/verified/ae.json b/fixtures/verified/ae.json index 9141556c..1935a3de 100644 --- a/fixtures/verified/ae.json +++ b/fixtures/verified/ae.json @@ -386,7 +386,7 @@ }, "Duties and Taxes": { "accountType": "Tax", - "isGroup": 1 + "isGroup": true }, "Reservations & Credit Notes": { "Credit Notes": { diff --git a/fixtures/verified/ca.json b/fixtures/verified/ca.json index bf36c047..b270293d 100644 --- a/fixtures/verified/ca.json +++ b/fixtures/verified/ca.json @@ -11,7 +11,7 @@ }, "Banque": { "accountType": "Bank", - "isGroup": 1 + "isGroup": true }, "Comptes \u00e0 recevoir": { "Comptes clients": { @@ -20,7 +20,7 @@ "Provision pour cr\u00e9ances douteuses": {} }, "Encaisse": { - "isGroup": 1 + "isGroup": true }, "Frais pay\u00e9s d\u2019avance": { "Assurances pay\u00e9s d'avance": {}, @@ -29,7 +29,7 @@ }, "Petite caisse": { "accountType": "Cash", - "isGroup": 1 + "isGroup": true }, "Stocks": { "Mati\u00e8res premi\u00e8res": {}, @@ -175,7 +175,7 @@ "Loyer - b\u00e2timent": {}, "Loyer - entrep\u00f4t": {}, "Op\u00e9rations indirectes de la main-d\u2019\u0153uvre directe": { - "isGroup": 1 + "isGroup": true }, "R\u00e9parations et entretien - b\u00e2timent": {}, "R\u00e9parations et entretien - machinerie et \u00e9quipement": {}, diff --git a/fixtures/verified/gt.json b/fixtures/verified/gt.json index 69a6a788..a07b65fd 100644 --- a/fixtures/verified/gt.json +++ b/fixtures/verified/gt.json @@ -9,12 +9,12 @@ "Animales": { "accountNumber": "1.5.2.1", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Plantas": { "accountNumber": "1.5.2.2", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.5.2", "accountType": "Stock" @@ -22,7 +22,7 @@ "Activos Biol\u00f3gicos al Costo": { "accountNumber": "1.5.1", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.5", "accountType": "Stock" @@ -32,7 +32,7 @@ "Cr\u00e9dito Fiscal (IVA Por Cobrar)": { "accountNumber": "1.1.2.1", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.1.2", "accountType": "Chargeable" @@ -47,22 +47,22 @@ "Activos Adicionales y Otros": { "accountNumber": "1.6.6", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Cobrables Relacionados con Impuestos": { "accountNumber": "1.6.2", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Contratos de Construccion": { "accountNumber": "1.6.4", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Costos de Montaje": { "accountNumber": "1.6.5", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Pagos Anticipados y Otros Activos Circulantes": { "Seguro Pagado Anticipadamente": { @@ -75,7 +75,7 @@ "Proveedores de Servicio": { "accountNumber": "1.6.3", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.6", "accountType": "Chargeable" @@ -84,32 +84,32 @@ "Activos Financieros Clasificados por Designaci\u00f3n": { "accountNumber": "1.4.6", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Activos Financieros Derivados": { "accountNumber": "1.4.3", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Inversion o Participaci\u00f3n Accionaria en Empresas Afiliadas": { "accountNumber": "1.4.1", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Inversiones Burs\u00e1tiles e Instrumentos Financieros": { "accountNumber": "1.4.2", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Otros Activos Financieros": { "accountNumber": "1.4.4", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Provisi\u00f3n por Riesgo de Cr\u00e9dito (agregado) (Contra-activo)": { "accountNumber": "1.4.5", "accountType": "Round Off", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.4", "accountType": "Chargeable" @@ -117,13 +117,13 @@ "Activos Intangibles": { "accountNumber": "1.3", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Caja y Equivalentes": { "Caja": { "accountNumber": "1.9.1", "accountType": "Cash", - "isGroup": 1 + "isGroup": true }, "Equivalentes de Efectivo (Bancos)": { "Bancos Internacionales": { @@ -146,7 +146,7 @@ "Banco Industrial": { "accountNumber": "1.9.2.1.1", "accountType": "Bank", - "isGroup": 1 + "isGroup": true }, "Banco Internacional": { "accountNumber": "1.9.2.1.6", @@ -189,12 +189,12 @@ "Inversiones a Corto Plazo": { "accountNumber": "1.9.3", "accountType": "Bank", - "isGroup": 1 + "isGroup": true }, "Otros Equivalentes de Caja y Bancos": { "accountNumber": "1.9.4", "accountType": "Cash", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.9", "accountType": "Bank" @@ -203,12 +203,12 @@ "Activos bajo Contrato": { "accountNumber": "1.8.2", "accountType": "Receivable", - "isGroup": 1 + "isGroup": true }, "Ajustes": { "accountNumber": "1.8.4", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "Otras Cuentas por Cobrar": { "Cuentas Por Cobrar Compa\u00f1\u00edas Afiliadas": { @@ -241,7 +241,7 @@ "Ventas al Cr\u00e9dito": { "accountNumber": "1.8.1", "accountType": "Receivable", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.8", "accountType": "Receivable" @@ -253,38 +253,38 @@ "Art\u00edculos de Inventario Adicionales": { "accountNumber": "1.7.8", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Combustibles": { "accountNumber": "1.7.5", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Inventarios Pignorados Como Garant\u00eda de Pasivo": { "accountNumber": "1.7.10", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Inventarios a Valor Razonable Menos Costos de Venta": { "accountNumber": "1.7.11", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Materia Prima": { "accountNumber": "1.7.1", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Mercader\u00eda (Mercanc\u00edas)": { "accountNumber": "1.7.2", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Otros Inventarios": { "Merma o Ajuste de Inventario": { "accountNumber": "1.7.9.1", "accountType": "Stock Adjustment", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.7.9", "accountType": "Stock" @@ -292,13 +292,13 @@ "Producto Terminado": { "accountNumber": "1.7.7", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Repuestos": { "Respuestos en Transito": { "accountNumber": "1.7.4.0", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.7.4", "accountType": "Stock" @@ -306,12 +306,12 @@ "Suministros de Producci\u00f3n y Consumibles": { "accountNumber": "1.7.3", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Trabajo en Progeso": { "accountNumber": "1.7.6", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.7", "accountType": "Stock" @@ -324,7 +324,7 @@ "Inversion Inmobiliaria Construida": { "accountNumber": "1.2.2", "accountType": "Chargeable", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1.2", "accountType": "Chargeable" diff --git a/fixtures/verified/hu.json b/fixtures/verified/hu.json index 5434e520..3166eda6 100644 --- a/fixtures/verified/hu.json +++ b/fixtures/verified/hu.json @@ -29,16 +29,16 @@ }, "123. \u00c9p\u00fcletek, \u00e9p\u00fcletr\u00e9szek, tulajdoni h\u00e1nyadok ": { "accountType": "Fixed Asset", - "isGroup": 1 + "isGroup": true }, "124. Egy\u00e9b ingatlanok": { - "isGroup": 1 + "isGroup": true }, "125. \u00dczemk\u00f6r\u00f6n k\u00edv\u00fcli ingatlanok, \u00e9p\u00fcletek ": { - "isGroup": 1 + "isGroup": true }, "126. Ingatlanokhoz kapcsol\u00f3d\u00f3 vagyoni \u00e9rt\u00e9k\u0171 jogok": { - "isGroup": 1 + "isGroup": true }, "127. Ingatlanok \u00e9rt\u00e9khelyesb\u00edt\u00e9se": {}, "129. Kis \u00e9rt\u00e9k\u0171 ingatlanok": {} @@ -148,7 +148,7 @@ "239. Befejezetlen termel\u00e9s \u00e9s f\u00e9lk\u00e9sz term\u00e9kek \u00e9rt\u00e9kveszt\u00e9se \u00e9s annak vissza\u00edr\u00e1sa": {} }, "24. N\u00d6VEND\u00c9K-, H\u00cdZ\u00d3- \u00c9S EGY\u00c9B \u00c1LLATOK": { - "isGroup": 1 + "isGroup": true }, "25. K\u00c9SZTERM\u00c9KEK": { "251-257. K\u00e9szterm\u00e9kek": {}, @@ -158,23 +158,23 @@ "26-28. \u00c1RUK ": { "261. Kereskedelmi \u00e1ruk": { "accountType": "Stock", - "isGroup": 0 + "isGroup": false }, "262. Idegen helyen t\u00e1rolt, bizom\u00e1nyba \u00e1tadott \u00e1ruk": { "accountType": "Stock", - "isGroup": 0 + "isGroup": false }, "263. T\u00e1rgyi eszk\u00f6z\u00f6k k\u00f6z\u00fcl \u00e1tsorolt \u00e1ruk": { "accountType": "Stock", - "isGroup": 0 + "isGroup": false }, "264. Bels\u0151 (egys\u00e9gek, tev\u00e9kenys\u00e9gek k\u00f6z\u00f6tti) \u00e1tad\u00e1s-\u00e1tv\u00e9tel \u00fctk\u00f6z\u0151sz\u00e1mla": { "accountType": "Stock", - "isGroup": 0 + "isGroup": false }, "269. Kereskedelmi \u00e1ruk \u00e9rt\u00e9kveszt\u00e9se \u00e9s annak vissza\u00edr\u00e1sa": { "accountType": "Stock", - "isGroup": 0 + "isGroup": false }, "accountType": "Stock" }, @@ -183,7 +183,7 @@ "279. K\u00f6zvet\u00edtett szolg\u00e1ltat\u00e1sok \u00e9rt\u00e9kveszt\u00e9se \u00e9s annak vissza\u00edr\u00e1sa": {} }, "28. BET\u00c9TD\u00cdJAS G\u00d6NGY\u00d6LEGEK": { - "isGroup": 1 + "isGroup": true }, "rootType": "Asset" }, @@ -205,13 +205,13 @@ "319. K\u00fclf\u00f6ldi k\u00f6vetel\u00e9sek \u00e9rt\u00e9kveszt\u00e9se \u00e9s annak vissza\u00edr\u00e1sa": {} }, "32. K\u00d6VETEL\u00c9SEK KAPCSOLT V\u00c1LLALKOZ\u00c1SSAL SZEMBEN": { - "isGroup": 1 + "isGroup": true }, "33. K\u00d6VETEL\u00c9SEK EGY\u00c9B R\u00c9SZESED\u00c9SI VISZONYBAN L\u00c9V\u00d5 V\u00c1LLALKOZ\u00c1SSAL SZEMBEN ": { - "isGroup": 1 + "isGroup": true }, "34. V\u00c1LT\u00d3K\u00d6VETEL\u00c9SEK": { - "isGroup": 1 + "isGroup": true }, "35. ADOTT EL\u00d5LEGEK": { "351. Immateri\u00e1lis javakra adott el\u0151legek": {}, @@ -227,17 +227,17 @@ "3613. Egy\u00e9b elsz\u00e1mol\u00e1sok a munkav\u00e1llal\u00f3kkal": {} }, "362. K\u00f6lts\u00e9gvet\u00e9ssel szembeni k\u00f6vetel\u00e9sek": { - "isGroup": 1 + "isGroup": true }, "363. R\u00f6vid lej\u00e1ratra k\u00f6lcs\u00f6nadott p\u00e9nzeszk\u00f6z\u00f6k": { - "isGroup": 1 + "isGroup": true }, "364. R\u00e9szesed\u00e9sekkel, \u00e9rt\u00e9kpap\u00edrokkal kapcsolatos k\u00f6vetel\u00e9sek": { "3641. R\u00f6vid lej\u00e1rat\u00fa k\u00f6lcs\u00f6n\u00f6k": {}, "3642. Tart\u00f3san adott k\u00f6lcs\u00f6n\u00f6kb\u0151l \u00e1tsorolt k\u00f6vetel\u00e9sek": {} }, "365. V\u00e1s\u00e1rolt \u00e9s kapott k\u00f6vetel\u00e9sek ": { - "isGroup": 1 + "isGroup": true }, "366. R\u00e9szesed\u00e9sekkel, \u00e9rt\u00e9kpap\u00edrokkal kapcsolatos k\u00f6vetel\u00e9sek": {}, "367. Hat\u00e1rid\u0151s, opci\u00f3s \u00e9s swap \u00fcgyletekkel kapcsolatos k\u00f6vetel\u00e9sek": {}, @@ -285,7 +285,7 @@ "383. Csekkek": {}, "384. Elsz\u00e1mol\u00e1si bet\u00e9tsz\u00e1mla ": { "accountType": "Bank", - "isGroup": 1 + "isGroup": true }, "385. Elk\u00fcl\u00f6n\u00edtett bet\u00e9tsz\u00e1ml\u00e1k ": { "3851. Kamatoz\u00f3 bet\u00e9tsz\u00e1ml\u00e1k": {}, @@ -373,7 +373,7 @@ "4452. Egy\u00e9b hossz\u00fa lej\u00e1rat\u00fa hitelek deviz\u00e1ban": {} }, "446. Tart\u00f3s k\u00f6telezetts\u00e9gek kapcsolt v\u00e1llalkoz\u00e1ssal szemben ": { - "isGroup": 1 + "isGroup": true }, "447. Tart\u00f3s k\u00f6telezetts\u00e9gek egy\u00e9b r\u00e9szesed\u00e9si viszonyban l\u00e9v\u0151 v\u00e1llalkoz\u00e1ssal szemben": {}, "448. P\u00e9nz\u00fcgyi l\u00edzing miatti k\u00f6telezetts\u00e9gek ": {}, @@ -449,7 +449,7 @@ "463-9. C\u00e9gaut\u00f3ad\u00f3 ": {} }, "464. G\u00e9pj\u00e1rm\u0171 ad\u00f3 (c\u00e9gaut\u00f3ad\u00f3) elsz\u00e1mol\u00e1sa": { - "isGroup": 1 + "isGroup": true }, "465. V\u00e1m- \u00e9s p\u00e9nz\u00fcgy\u0151rs\u00e9g elsz\u00e1mol\u00e1si sz\u00e1mla ": { "4651. V\u00e1mk\u00f6lts\u00e9gek \u00e9s egy\u00e9b v\u00e1mterhek elsz\u00e1mol\u00e1si sz\u00e1mla": {}, @@ -619,7 +619,7 @@ "589. Aktiv\u00e1lt saj\u00e1t teljes\u00edtm\u00e9nyek \u00e1tvezet\u00e9si sz\u00e1mla": {} }, "59. K\u00d6LTS\u00c9GNEM \u00c1TVEZET\u00c9SI SZ\u00c1MLA": { - "isGroup": 1 + "isGroup": true }, "rootType": "Expense" }, @@ -647,7 +647,7 @@ "rootType": "Expense" }, "7. SZ\u00c1MLAOSZT\u00c1LY TEV\u00c9KENYS\u00c9GEKK\u00d6LTS\u00c9GEI": { - "isGroup": 1, + "isGroup": true, "rootType": "Expense" }, "8. SZ\u00c1MLAOSZT\u00c1LY \u00c9RT\u00c9KES\u00cdT\u00c9S ELSZ\u00c1MOLT \u00d6NK\u00d6LTS\u00c9GE \u00c9S R\u00c1FORD\u00cdT\u00c1SOK": { @@ -812,7 +812,7 @@ "9684. R\u00e9szesed\u00e9sek \u00e9rt\u00e9kveszt\u00e9s\u00e9nek vissza\u00edr\u00e1sa": {} }, "969. K\u00fcl\u00f6nf\u00e9le egy\u00e9b bev\u00e9telek": { - "isGroup": 1 + "isGroup": true } }, "97. P\u00c9NZ\u00dcGYI M\u0170VELETEK BEV\u00c9TELEI": { diff --git a/fixtures/verified/id.json b/fixtures/verified/id.json index 4ad611a9..543bc6d9 100644 --- a/fixtures/verified/id.json +++ b/fixtures/verified/id.json @@ -14,11 +14,11 @@ "Bank ": { "Bank Other Currency": { "accountNumber": "1122.000", - "isGroup": 1 + "isGroup": true }, "Bank Rupiah": { "accountNumber": "1121.000", - "isGroup": 1 + "isGroup": true }, "accountNumber": "1120.000", "accountType": "Bank" @@ -70,7 +70,7 @@ "Persediaan Barang": { "accountNumber": "1141.000", "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "Uang Muka Pembelian": { "Uang Muka Pembelian": { @@ -122,7 +122,7 @@ "Investasi": { "Deposito": { "accountNumber": "1231.003", - "isGroup": 1 + "isGroup": true }, "Investai Saham": { "Investasi Saham": { diff --git a/fixtures/verified/in.json b/fixtures/verified/in.json index 203684d2..f2afda4d 100644 --- a/fixtures/verified/in.json +++ b/fixtures/verified/in.json @@ -6,13 +6,13 @@ "Current Assets": { "Accounts Receivable": { "Debtors": { - "isGroup": 0, + "isGroup": false, "accountType": "Receivable" } }, "Bank Accounts": { "accountType": "Bank", - "isGroup": 1 + "isGroup": true }, "Cash In Hand": { "Cash": { @@ -21,7 +21,7 @@ "accountType": "Cash" }, "Loans and Advances (Assets)": { - "isGroup": 1 + "isGroup": true }, "Securities and Deposits": { "Earnest Money": {} @@ -33,7 +33,7 @@ "accountType": "Stock" }, "Tax Assets": { - "isGroup": 1 + "isGroup": true } }, "Fixed Assets": { @@ -60,7 +60,7 @@ } }, "Investments": { - "isGroup": 1 + "isGroup": true }, "Temporary Accounts": { "Temporary Opening": { @@ -126,7 +126,7 @@ }, "Indirect Income": { "accountType": "Income Account", - "isGroup": 1 + "isGroup": true }, "rootType": "Income" }, diff --git a/fixtures/verified/mx.json b/fixtures/verified/mx.json index 7aa93777..9c0badbd 100644 --- a/fixtures/verified/mx.json +++ b/fixtures/verified/mx.json @@ -110,7 +110,7 @@ }, "INVENTARIOS": { "accountType": "Stock", - "isGroup": 1 + "isGroup": true } }, "ACTIVO LARGO PLAZO": { diff --git a/fixtures/verified/ni.json b/fixtures/verified/ni.json index 22333489..7bcf43b9 100644 --- a/fixtures/verified/ni.json +++ b/fixtures/verified/ni.json @@ -57,7 +57,7 @@ }, "Otros Equivalentes a Efectivo": { "accountType": "Cash", - "isGroup": 1 + "isGroup": true } }, "Impuestos Acreditables": { @@ -91,41 +91,41 @@ }, "Todos los Almacenes": { "accountType": "Stock", - "isGroup": 1 + "isGroup": true }, "accountType": "Stock" }, "Otras Cuentas por Cobrar": { "accountType": "Receivable", - "isGroup": 1 + "isGroup": true } }, "Activo no Corriente": { "Activo por Impuestos Diferidos": { - "isGroup": 1 + "isGroup": true }, "Activos Intangibles": { "Amortizacion de Activos Intangibles": { - "isGroup": 1 + "isGroup": true }, "Concesiones": { - "isGroup": 1 + "isGroup": true }, "Derechos de Autor": { - "isGroup": 1 + "isGroup": true }, "Deterioro de Valor de Activos Intangibles": {}, "Gastos de investigacion": { - "isGroup": 1 + "isGroup": true }, "Licencias": { - "isGroup": 1 + "isGroup": true }, "Marcas Registradas": { - "isGroup": 1 + "isGroup": true }, "Patentes": { - "isGroup": 1 + "isGroup": true } }, "Amortizables": { @@ -138,7 +138,7 @@ "accountType": "Expenses Included In Valuation" }, "Mejoras en Bienes Arrendados": { - "isGroup": 1 + "isGroup": true } }, "Bienes en Arrendamiento Financiero": { @@ -147,28 +147,28 @@ }, "Cuentas por Cobrar a Largo Plazo": { "Creditos a Largo Plazo": { - "isGroup": 1 + "isGroup": true } }, "Inversiones Permanentes": { "Inversiones Permanentes 1": { "accountType": "Fixed Asset", - "isGroup": 1 + "isGroup": true }, "Negocios Conjuntos": { "accountType": "Fixed Asset", - "isGroup": 1 + "isGroup": true } }, "Inversiones a Largo Plazo": { "Depositos Bancarios a Plazo": { - "isGroup": 1 + "isGroup": true }, "Intereses percibidos por adelantado": { - "isGroup": 1 + "isGroup": true }, "Titulos y Acciones": { - "isGroup": 1 + "isGroup": true } }, "Propiedad Planta y Equipo": { @@ -203,7 +203,7 @@ } }, "Donaciones": { - "isGroup": 1 + "isGroup": true }, "Ganancias Acumuladas": { "Reservas": { @@ -319,7 +319,7 @@ }, "Pasivo": { "Obligaciones por Arrendamiento Financiero a Largo Plazo": { - "isGroup": 1 + "isGroup": true }, "Pasivo Corriente": { "Anticipos de Clientes": {}, @@ -345,11 +345,11 @@ }, "Gastos por Pagar": { "Prestaciones Sociales": { - "isGroup": 1 + "isGroup": true }, "Salarios por Pagar": {}, "Servicios Basicos 1": { - "isGroup": 1 + "isGroup": true } }, "Impuestos por Pagar": { @@ -372,17 +372,17 @@ } }, "Otras Cuentas por Pagar": { - "isGroup": 1 + "isGroup": true }, "Pasivos Financieros a Corto Plazo": { "Otras Deudas Bancarias": { - "isGroup": 1 + "isGroup": true }, "Prestamos por Pagar a Corto Plazo": { - "isGroup": 1 + "isGroup": true }, "Sobregiros Bancarios": { - "isGroup": 1 + "isGroup": true } }, "Provisiones por Pagar": { @@ -473,20 +473,20 @@ }, "Pasivo No Corriente": { "Cuentas por Pagar a Largo Plaso": { - "isGroup": 1 + "isGroup": true }, "Otras Cuentas por Pagar a Largo Plazo": { - "isGroup": 1 + "isGroup": true }, "Otros Pasivos Financieros a Largo Plaso": { - "isGroup": 1 + "isGroup": true }, "Prestamos a Largo Plazo": { - "isGroup": 1 + "isGroup": true } }, "Pasivo por Impuestos Diferidos": { - "isGroup": 1 + "isGroup": true }, "rootType": "Liability" } diff --git a/fixtures/verified/nl.json b/fixtures/verified/nl.json index 7e5607d1..5c7584ce 100644 --- a/fixtures/verified/nl.json +++ b/fixtures/verified/nl.json @@ -3,7 +3,7 @@ "name": "Netherlands - Grootboekschema", "tree": { "FABRIKAGEREKENINGEN": { - "isGroup": 1, + "isGroup": true, "rootType": "Expense" }, "FINANCIELE REKENINGEN, KORTLOPENDE VORDERINGEN EN SCHULDEN": { @@ -106,7 +106,7 @@ "rootType": "Asset" }, "INDIRECTE KOSTEN": { - "isGroup": 1, + "isGroup": true, "rootType": "Expense" }, "KOSTENREKENINGEN": { diff --git a/fixtures/verified/standardCOA.json b/fixtures/verified/standardCOA.json index 8d0877f1..e57e2dbb 100644 --- a/fixtures/verified/standardCOA.json +++ b/fixtures/verified/standardCOA.json @@ -7,8 +7,8 @@ } }, "Bank Accounts": { - "accountType": "Bank", - "isGroup": 1 + "accountType": "Bank", + "isGroup": true }, "Cash In Hand": { "Cash": { @@ -17,7 +17,7 @@ "accountType": "Cash" }, "Loans and Advances (Assets)": { - "isGroup": 1 + "isGroup": true }, "Securities and Deposits": { "Earnest Money": {} @@ -29,7 +29,7 @@ "accountType": "Stock" }, "Tax Assets": { - "isGroup": 1 + "isGroup": true } }, "Fixed Assets": { @@ -59,7 +59,7 @@ } }, "Investments": { - "isGroup": 1 + "isGroup": true }, "Temporary Accounts": { "Temporary Opening": { @@ -123,7 +123,7 @@ "Service": {} }, "Indirect Income": { - "isGroup": 1 + "isGroup": true }, "rootType": "Income" }, @@ -141,8 +141,8 @@ } }, "Duties and Taxes": { - "accountType": "Tax", - "isGroup": 1 + "accountType": "Tax", + "isGroup": true }, "Loans (Liabilities)": { "Secured Loans": {}, diff --git a/fyo/core/dbHandler.ts b/fyo/core/dbHandler.ts index d1c0cd2b..a2f8f1e2 100644 --- a/fyo/core/dbHandler.ts +++ b/fyo/core/dbHandler.ts @@ -21,6 +21,7 @@ export class DatabaseHandler extends DatabaseBase { #fyo: Fyo; converter: Converter; #demux: DatabaseDemuxBase; + dbPath?: string; schemaMap: Readonly = {}; fieldValueMap: Record> = {}; @@ -39,12 +40,14 @@ export class DatabaseHandler extends DatabaseBase { async createNewDatabase(dbPath: string, countryCode: string) { countryCode = await this.#demux.createNewDatabase(dbPath, countryCode); await this.init(); + this.dbPath = dbPath; return countryCode; } async connectToDatabase(dbPath: string, countryCode?: string) { countryCode = await this.#demux.connectToDatabase(dbPath, countryCode); await this.init(); + this.dbPath = dbPath; return countryCode; } diff --git a/fyo/core/types.ts b/fyo/core/types.ts index 4f22790d..7dd4cac6 100644 --- a/fyo/core/types.ts +++ b/fyo/core/types.ts @@ -34,7 +34,7 @@ export enum ConfigKeys { export interface ConfigFile { id: string; companyName: string; - filePath: string; + dbPath: string; } export interface FyoConfig { diff --git a/fyo/model/doc.ts b/fyo/model/doc.ts index 4e2f4f21..4e7535ca 100644 --- a/fyo/model/doc.ts +++ b/fyo/model/doc.ts @@ -676,6 +676,14 @@ export default class Doc extends Observable { return this.fyo.doc.getCachedValue(schemaName, name, fieldname); } + async setAndUpdate( + fieldname: string | DocValueMap, + value?: DocValue | Doc[] + ) { + await this.set(fieldname, value); + return await this.update(); + } + async duplicate(shouldInsert: boolean = true): Promise { const updateMap: DocValueMap = {}; const docValueMap = this.getValidDict(); diff --git a/fyo/telemetry/helpers.ts b/fyo/telemetry/helpers.ts index 93a8ef96..5320ee4a 100644 --- a/fyo/telemetry/helpers.ts +++ b/fyo/telemetry/helpers.ts @@ -79,7 +79,7 @@ function addNewFile( ): UniqueId { const newFile: ConfigFile = { companyName, - filePath: fyo.config.get(ConfigKeys.LastSelectedFilePath, '') as string, + dbPath: fyo.config.get(ConfigKeys.LastSelectedFilePath, '') as string, id: getId(), }; diff --git a/models/baseModels/Account/types.ts b/models/baseModels/Account/types.ts index 8b9c4b33..9d8b5d49 100644 --- a/models/baseModels/Account/types.ts +++ b/models/baseModels/Account/types.ts @@ -25,3 +25,19 @@ export type AccountRootType = | 'Equity' | 'Income' | 'Expense'; + +export interface COARootAccount { + rootType: AccountRootType; + [key: string]: COAChildAccount | AccountRootType; +} + +export interface COAChildAccount { + accountType?: AccountType; + accountNumber?: string; + isGroup?: boolean; + [key: string]: COAChildAccount | boolean | AccountType | string | undefined; +} + +export interface COATree { + [key: string]: COARootAccount; +} diff --git a/reports/commonExporter.js b/reports/commonExporter.js deleted file mode 100644 index 5c19a827..00000000 --- a/reports/commonExporter.js +++ /dev/null @@ -1,109 +0,0 @@ -import frappe from 'fyo'; -import telemetry from '../src/telemetry/telemetry'; -import { Verb } from '../src/telemetry/types'; -import { getSavePath, saveData, showExportInFolder } from '../src/utils'; - -function templateToInnerText(innerHTML) { - const temp = document.createElement('template'); - temp.innerHTML = innerHTML.trim(); - return temp.content.firstChild.innerText; -} - -function deObjectify(value) { - if (typeof value !== 'object') return value; - if (value === null) return ''; - - const innerHTML = value.template; - if (!innerHTML) return ''; - return templateToInnerText(innerHTML); -} - -function csvFormat(value) { - if (typeof value === 'string') { - return `"${value}"`; - } else if (value === null) { - return ''; - } else if (typeof value === 'object') { - const innerHTML = value.template; - if (!innerHTML) return ''; - return csvFormat(deObjectify(value)); - } - return value; -} - -export async function exportCsv(rows, columns, filePath) { - const fieldnames = columns.map(({ fieldname }) => fieldname); - const labels = columns.map(({ label }) => csvFormat(label)); - const csvRows = [ - labels.join(','), - ...rows.map((row) => fieldnames.map((f) => csvFormat(row[f])).join(',')), - ]; - - saveExportData(csvRows.join('\n'), filePath); -} - -async function exportJson(rows, columns, filePath, filters, reportName) { - const exportObject = {}; - const fieldnames = columns.map(({ fieldname }) => fieldname); - - exportObject.columns = columns.map(({ fieldname, label }) => ({ - fieldname, - label, - })); - - exportObject.rows = rows.map((row) => - fieldnames.reduce((acc, f) => { - acc[f] = deObjectify(row[f]); - return acc; - }, {}) - ); - - exportObject.filters = Object.keys(filters) - .filter((name) => filters[name] !== null && filters[name] !== undefined) - .reduce((acc, name) => { - acc[name] = filters[name]; - return acc; - }, {}); - - exportObject.timestamp = new Date().toISOString(); - exportObject.reportName = reportName; - exportObject.softwareName = 'Frappe Books'; - exportObject.softwareVersion = frappe.store.appVersion; - - await saveExportData(JSON.stringify(exportObject), filePath); -} - -async function exportReport(extention, reportName, getReportData) { - const { rows, columns, filters } = getReportData(); - - const { filePath, canceled } = await getSavePath(reportName, extention); - if (canceled || !filePath) return; - - switch (extention) { - case 'csv': - await exportCsv(rows, columns, filePath); - break; - case 'json': - await exportJson(rows, columns, filePath, filters, reportName); - break; - default: - return; - } - - telemetry.log(Verb.Exported, reportName, { extention }); -} - -export default function getCommonExportActions(reportName) { - return ['csv', 'json'].map((ext) => ({ - group: frappe.t`Export`, - label: ext.toUpperCase(), - type: 'primary', - action: async (getReportData) => - await exportReport(ext, reportName, getReportData), - })); -} - -export async function saveExportData(data, filePath) { - await saveData(data, filePath); - showExportInFolder(frappe.t`Export Successful`, filePath); -} diff --git a/src/initFyo.ts b/src/initFyo.ts index a7d7f126..14a68fb1 100644 --- a/src/initFyo.ts +++ b/src/initFyo.ts @@ -1,3 +1,15 @@ import { Fyo } from 'fyo'; +import models, { getRegionalModels } from 'models'; export const fyo = new Fyo({ isTest: false, isElectron: true }); + +export async function initializeModels(dbPath: string, countryCode?: string) { + if (countryCode) { + countryCode = await fyo.db.createNewDatabase(dbPath, countryCode); + } else { + countryCode = await fyo.db.connectToDatabase(dbPath); + } + + const regionalModels = await getRegionalModels(countryCode); + await fyo.initializeAndRegister(models, regionalModels); +} diff --git a/src/pages/ChartOfAccounts.vue b/src/pages/ChartOfAccounts.vue index 5ad8a8a3..6f62efd5 100644 --- a/src/pages/ChartOfAccounts.vue +++ b/src/pages/ChartOfAccounts.vue @@ -1,9 +1,3 @@ -import PageHeader from 'src/components/PageHeader'; -import SearchBar from 'src/components/SearchBar'; -import { openQuickEdit } from 'src/utils'; -import frappe from 'frappe'; -import { nextTick } from 'vue'; -import { handleErrorWithDialog } from '../errorHandling';