From 5c9fd405f0c79b24bfa73f19a3a3109c3c769c4f Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 2 Apr 2018 23:24:45 +0530 Subject: [PATCH] import Standard Chart of Accounts --- client/index.js | 2 +- electron/client.js | 7 +- fixtures/standardCOA.js | 173 ++++++++++++++++++++++++++++ models/doctype/account/importCOA.js | 48 ++++++++ www/dist/js/bundle.js | 54 +++++++-- 5 files changed, 270 insertions(+), 14 deletions(-) create mode 100644 fixtures/standardCOA.js create mode 100644 models/doctype/account/importCOA.js diff --git a/client/index.js b/client/index.js index 5379465e..39f1dd03 100644 --- a/client/index.js +++ b/client/index.js @@ -27,7 +27,7 @@ module.exports = { frappe.desk.menu.addItem('Contact', "#list/Contact"); frappe.desk.menu.addItem('Settings', () => frappe.desk.showFormModal('SystemSettings')); - frappe.router.default = '#list/ToDo'; + frappe.router.default = '#list/Invoice'; frappe.router.show(window.location.hash); diff --git a/electron/client.js b/electron/client.js index 7de196bf..51cd26e9 100644 --- a/electron/client.js +++ b/electron/client.js @@ -50,15 +50,18 @@ const SetupWizard = require('../setup'); const doc = await frappe.getDoc('AccountingSettings'); await doc.set('companyName', companyName); - await doc.set('file', dbPath); await doc.set('country', country); await doc.set('fullname', name); await doc.set('email', email); - await doc.set('abbreviation', abbreviation); await doc.set('bankName', bankName); await doc.update(); + // bootstrap Chart of Accounts + const importCOA = require('../models/doctype/account/importCOA'); + const chart = require('../fixtures/standardCOA'); + await importCOA(chart); + appClient.start(); }) } diff --git a/fixtures/standardCOA.js b/fixtures/standardCOA.js new file mode 100644 index 00000000..a7ab0a29 --- /dev/null +++ b/fixtures/standardCOA.js @@ -0,0 +1,173 @@ +const frappe = require('frappejs'); +const _ = frappe._.bind(frappe); + +module.exports = { + [_("Application of Funds (Assets)")]: { + [_("Current Assets")]: { + [_("Accounts Receivable")]: { + [_("Debtors")]: { + "accountType": "Receivable" + } + }, + [_("Bank Accounts")]: { + "accountType": "Bank", + "isGroup": 1 + }, + [_("Cash In Hand")]: { + [_("Cash")]: { + "accountType": "Cash" + }, + "accountType": "Cash" + }, + [_("Loans and Advances (Assets)")]: { + "isGroup": 1 + }, + [_("Securities and Deposits")]: { + [_("Earnest Money")]: {} + }, + [_("Stock Assets")]: { + [_("Stock In Hand")]: { + "accountType": "Stock" + }, + "accountType": "Stock", + }, + [_("Tax Assets")]: { + "isGroup": 1 + } + }, + [_("Fixed Assets")]: { + [_("Capital Equipments")]: { + "accountType": "Fixed Asset" + }, + [_("Electronic Equipments")]: { + "accountType": "Fixed Asset" + }, + [_("Furnitures and Fixtures")]: { + "accountType": "Fixed Asset" + }, + [_("Office Equipments")]: { + "accountType": "Fixed Asset" + }, + [_("Plants and Machineries")]: { + "accountType": "Fixed Asset" + }, + [_("Buildings")]: { + "accountType": "Fixed Asset" + }, + [_("Softwares")]: { + "accountType": "Fixed Asset" + }, + [_("Accumulated Depreciation")]: { + "accountType": "Accumulated Depreciation" + } + }, + [_("Investments")]: { + "isGroup": 1 + }, + [_("Temporary Accounts")]: { + [_("Temporary Opening")]: { + "accountType": "Temporary" + } + }, + "rootType": "Asset" + }, + [_("Expenses")]: { + [_("Direct Expenses")]: { + [_("Stock Expenses")]: { + [_("Cost of Goods Sold")]: { + "accountType": "Cost of Goods Sold" + }, + [_("Expenses Included In Valuation")]: { + "accountType": "Expenses Included In Valuation" + }, + [_("Stock Adjustment")]: { + "accountType": "Stock Adjustment" + } + }, + }, + [_("Indirect Expenses")]: { + [_("Administrative Expenses")]: {}, + [_("Commission on Sales")]: {}, + [_("Depreciation")]: { + "accountType": "Depreciation" + }, + [_("Entertainment Expenses")]: {}, + [_("Freight and Forwarding Charges")]: { + "accountType": "Chargeable" + }, + [_("Legal Expenses")]: {}, + [_("Marketing Expenses")]: { + "accountType": "Chargeable" + }, + [_("Miscellaneous Expenses")]: { + "accountType": "Chargeable" + }, + [_("Office Maintenance Expenses")]: {}, + [_("Office Rent")]: {}, + [_("Postal Expenses")]: {}, + [_("Print and Stationery")]: {}, + [_("Round Off")]: { + "accountType": "Round Off" + }, + [_("Salary")]: {}, + [_("Sales Expenses")]: {}, + [_("Telephone Expenses")]: {}, + [_("Travel Expenses")]: {}, + [_("Utility Expenses")]: {}, + [_("Write Off")]: {}, + [_("Exchange Gain/Loss")]: {}, + [_("Gain/Loss on Asset Disposal")]: {} + }, + "rootType": "Expense" + }, + [_("Income")]: { + [_("Direct Income")]: { + [_("Sales")]: {}, + [_("Service")]: {} + }, + [_("Indirect Income")]: { + "isGroup": 1 + }, + "rootType": "Income" + }, + [_("Source of Funds (Liabilities)")]: { + [_("Current Liabilities")]: { + [_("Accounts Payable")]: { + [_("Creditors")]: { + "accountType": "Payable" + }, + [_("Payroll Payable")]: {}, + }, + [_("Stock Liabilities")]: { + [_("Stock Received But Not Billed")]: { + "accountType": "Stock Received But Not Billed" + }, + }, + [_("Duties and Taxes")]: { + "accountType": "Tax", + "isGroup": 1 + }, + [_("Loans (Liabilities)")]: { + [_("Secured Loans")]: {}, + [_("Unsecured Loans")]: {}, + [_("Bank Overdraft Account")]: {}, + }, + }, + "rootType": "Liability" + }, + [_("Equity")]: { + [_("Capital Stock")]: { + "accountType": "Equity" + }, + [_("Dividends Paid")]: { + "accountType": "Equity" + }, + [_("Opening Balance Equity")]: { + "accountType": "Equity" + }, + [_("Retained Earnings")]: { + "accountType": "Equity" + }, + "rootType": "Equity" + } +} \ No newline at end of file diff --git a/models/doctype/account/importCOA.js b/models/doctype/account/importCOA.js new file mode 100644 index 00000000..d067fe98 --- /dev/null +++ b/models/doctype/account/importCOA.js @@ -0,0 +1,48 @@ +const frappe = require('frappejs'); +const accountFields = ['accountType', 'rootType', 'isGroup']; + +async function importAccounts(children, parent, rootType, rootAccount) { + for (let accountName in children) { + const child = children[accountName]; + + if (rootAccount) { + rootType = child.rootType; + } + + if (!accountFields.includes(accountName)) { + let isGroup = identifyIsGroup(child); + + const doc = frappe.newDoc({ + doctype: 'Account', + name: accountName, + parentAccount: parent, + isGroup, + rootType, + accountType: child.accountType + }) + + await doc.insert() + + await importAccounts(child, accountName, rootType) + } + } +} + +function identifyIsGroup(child) { + if (child.isGroup) { + return child.isGroup; + } + + if (Object.keys(child).some(key => accountFields.includes(key))) { + return 0; + } + + return 1; +} + +module.exports = async function importCharts(chart) { + if (chart) { + await importAccounts(chart, '', '', true) + } +} + diff --git a/www/dist/js/bundle.js b/www/dist/js/bundle.js index 93525a2b..fdee88e5 100644 --- a/www/dist/js/bundle.js +++ b/www/dist/js/bundle.js @@ -57989,11 +57989,11 @@ var GeneralLedgerView_1 = class GeneralLedgerView extends reportpage { var AccountDocument = class Account extends document$1 { async validate() { - if (!this.account_type) { - if (this.parent_account) { - this.account_type = await frappejs.db.getValue('Account', this.parent_account, 'account_type'); + if (!this.accountType) { + if (this.parentAccount) { + this.accountType = await frappejs.db.getValue('Account', this.parentAccount, 'accountType'); } else { - this.account_type = 'Asset'; + this.accountType = 'Asset'; } } } @@ -58007,7 +58007,8 @@ module.exports = { "isSingle": 0, "keywordFields": [ "name", - "account_type" + "rootType", + "accountType" ], "fields": [ { @@ -58017,7 +58018,7 @@ module.exports = { "required": 1 }, { - "fieldname": "parent_account", + "fieldname": "parentAccount", "label": "Parent Account", "fieldtype": "Link", "target": "Account", @@ -58029,8 +58030,8 @@ module.exports = { } }, { - "fieldname": "account_type", - "label": "Account Type", + "fieldname": "rootType", + "label": "Root Type", "fieldtype": "Select", "options": [ "Asset", @@ -58039,6 +58040,37 @@ module.exports = { "Income", "Expense" ] + }, + { + "fieldname": "accountType", + "label": "Account Type", + "fieldtype": "Select", + "options": [ + "Accumulated Depreciation", + "Bank", + "Cash", + "Chargeable", + "Cost of Goods Sold", + "Depreciation", + "Equity", + "Expense Account", + "Expenses Included In Valuation", + "Fixed Asset", + "Income Account", + "Payable", + "Receivable", + "Round Off", + "Stock", + "Stock Adjustment", + "Stock Received But Not Billed", + "Tax", + "Temporary" + ] + }, + { + "fieldname": "isGroup", + "label": "Is Group", + "fieldtype": "Check" } ], @@ -58050,10 +58082,10 @@ module.exports = { listSettings: { getFields(list) { - return ['name', 'account_type']; + return ['name', 'accountType', 'rootType']; }, getRowHTML(list, data) { - return `
${list.getNameHTML(data)} (${data.account_type})
`; + return `
${list.getNameHTML(data)} (${data.rootType})
`; } } }; @@ -59718,7 +59750,7 @@ var client$2 = { frappejs.desk.menu.addItem('Contact', "#list/Contact"); frappejs.desk.menu.addItem('Settings', () => frappejs.desk.showFormModal('SystemSettings')); - frappejs.router.default = '#list/ToDo'; + frappejs.router.default = '#list/Invoice'; frappejs.router.show(window.location.hash);