diff --git a/erpnext/accounts/doctype/account/account.js b/erpnext/accounts/doctype/account/account.js index f085c8bb6b..471fe7e9b6 100644 --- a/erpnext/accounts/doctype/account/account.js +++ b/erpnext/accounts/doctype/account/account.js @@ -49,6 +49,7 @@ cur_frm.cscript.master_type = function(doc, cdt, cdn) { } cur_frm.add_fetch('parent_account', 'report_type', 'report_type'); +cur_frm.add_fetch('parent_account', 'root_type', 'root_type'); cur_frm.cscript.account_type = function(doc, cdt, cdn) { if(doc.group_or_ledger=='Ledger') { diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json index cf9adc59ae..9104b56c2b 100644 --- a/erpnext/accounts/doctype/account/account.json +++ b/erpnext/accounts/doctype/account/account.json @@ -82,6 +82,13 @@ "permlevel": 0, "search_index": 1 }, + { + "fieldname": "root_type", + "fieldtype": "Select", + "label": "Root Type", + "options": "\nAsset\nLiability\nIncome\nExpense\nEquity", + "permlevel": 0 + }, { "fieldname": "report_type", "fieldtype": "Select", @@ -200,7 +207,7 @@ "icon": "icon-money", "idx": 1, "in_create": 1, - "modified": "2014-05-12 17:03:19.733139", + "modified": "2014-05-20 11:44:53.012945", "modified_by": "Administrator", "module": "Accounts", "name": "Account", diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index ad588b5291..11b8d4a79a 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -42,7 +42,7 @@ class Account(Document): """Fetch Parent Details and validation for account not to be created under ledger""" if self.parent_account: par = frappe.db.get_value("Account", self.parent_account, - ["name", "group_or_ledger", "report_type"], as_dict=1) + ["name", "group_or_ledger", "report_type", "root_type"], as_dict=1) if not par: throw(_("Parent account does not exist")) elif par["name"] == self.name: @@ -52,6 +52,8 @@ class Account(Document): if par["report_type"]: self.report_type = par["report_type"] + if par["root_type"]: + self.root_type - par["root_type"] def validate_root_details(self): #does not exists parent @@ -99,6 +101,9 @@ class Account(Document): if not self.report_type: throw(_("Report Type is mandatory")) + if not self.root_type: + throw(_("Root Type is mandatory")) + def validate_warehouse_account(self): if not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")): return @@ -194,10 +199,10 @@ class Account(Document): throw(_("Account {0} does not exist").format(new)) val = list(frappe.db.get_value("Account", new_account, - ["group_or_ledger", "report_type", "company"])) + ["group_or_ledger", "root_type", "company"])) - if val != [self.group_or_ledger, self.report_type, self.company]: - throw(_("""Merging is only possible if following properties are same in both records. Group or Ledger, Report Type, Company""")) + if val != [self.group_or_ledger, self.root_type, self.company]: + throw(_("""Merging is only possible if following properties are same in both records. Group or Ledger, Root Type, Company""")) return new_account diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 3fc2b11536..dc5bb57fb6 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -43,4 +43,4 @@ execute:frappe.delete_doc_if_exists("DocType", "Warehouse User") execute:frappe.db.sql("delete from `tabWebsite Item Group` where ifnull(item_group, '')=''") execute:frappe.delete_doc("Print Format", "SalesInvoice") execute:import frappe.defaults;frappe.defaults.clear_default("price_list_currency") - +erpnext.patches.v4_0.update_account_root_type diff --git a/erpnext/patches/v4_0/update_account_root_type.py b/erpnext/patches/v4_0/update_account_root_type.py new file mode 100644 index 0000000000..9947cb684d --- /dev/null +++ b/erpnext/patches/v4_0/update_account_root_type.py @@ -0,0 +1,32 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + account_table_columns = frappe.db.get_table_columns("Account") + if "debit_or_credit" in account_table_columns and "is_pl_account" in account_table_columns: + frappe.db.sql("""UPDATE tabAccount SET root_type = CASE + WHEN (debit_or_credit='Debit' and is_pl_account = 'No') THEN 'Asset' + WHEN (debit_or_credit='Credit' and is_pl_account = 'No') THEN 'Liability' + WHEN (debit_or_credit='Debit' and is_pl_account = 'Yes') THEN 'Expense' + WHEN (debit_or_credit='Credit' and is_pl_account = 'Yes') THEN 'Income' + END""") + + else: + frappe.db.sql("""UPDATE tabAccount + SET root_type = CASE + WHEN name like '%%asset%%' THEN 'Asset' + WHEN name like '%%liabilities%%' THEN 'Liability' + WHEN name like '%%expense%%' THEN 'Expense' + WHEN name like '%%income%%' THEN 'Income' + END + WHERE + ifnull(parent_account, '') = '' + """) + + for root in frappe.db.sql("""SELECT lft, rgt, root_type FROM `tabAccount` + WHERE ifnull(parent_account, '')=''""", as_dict=True): + frappe.db.sql("""UPDATE tabAccount SET root_type=%s WHERE lft>%s and rgt<%s""", + (root.root_type, root.lft, root.rgt)) diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 6ea4fc2724..b79ea44107 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -81,11 +81,12 @@ class Company(Document): chart = frappe.get_doc("Chart of Accounts", self.chart_of_accounts) chart.create_accounts(self.name) - def add_acc(self,lst): + def add_acc(self, lst): account = frappe.get_doc({ "doctype": "Account", "freeze_account": "No", "master_type": "", + "company": self.name }) for d in self.fld_dict.keys(): @@ -182,77 +183,77 @@ class Company(Document): 'group_or_ledger': 2, 'account_type': 3, 'report_type': 4, - 'company': 5, - 'tax_rate': 6 + 'tax_rate': 5, + 'root_type': 6 } acc_list_common = [ - [_('Application of Funds (Assets)'),'','Group','','Balance Sheet',self.name,''], - [_('Current Assets'),_('Application of Funds (Assets)'),'Group','','Balance Sheet',self.name,''], - [_('Accounts Receivable'),_('Current Assets'),'Group','','Balance Sheet',self.name,''], - [_('Bank Accounts'),_('Current Assets'),'Group','Bank','Balance Sheet',self.name,''], - [_('Cash In Hand'),_('Current Assets'),'Group','Cash','Balance Sheet',self.name,''], - [_('Cash'),_('Cash In Hand'),'Ledger','Cash','Balance Sheet',self.name,''], - [_('Loans and Advances (Assets)'),_('Current Assets'),'Group','','Balance Sheet',self.name,''], - [_('Securities and Deposits'),_('Current Assets'),'Group','','Balance Sheet',self.name,''], - [_('Earnest Money'),_('Securities and Deposits'),'Ledger','','Balance Sheet',self.name,''], - [_('Stock Assets'),_('Current Assets'),'Group','Stock','Balance Sheet',self.name,''], - [_('Tax Assets'),_('Current Assets'),'Group','','Balance Sheet',self.name,''], - [_('Fixed Assets'),_('Application of Funds (Assets)'),'Group','','Balance Sheet',self.name,''], - [_('Capital Equipments'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet',self.name,''], - [_('Computers'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet',self.name,''], - [_('Furniture and Fixture'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet',self.name,''], - [_('Office Equipments'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet',self.name,''], - [_('Plant and Machinery'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet',self.name,''], - [_('Investments'),_('Application of Funds (Assets)'),'Group','','Balance Sheet',self.name,''], - [_('Temporary Accounts (Assets)'),_('Application of Funds (Assets)'),'Group','','Balance Sheet',self.name,''], - [_('Temporary Account (Assets)'),_('Temporary Accounts (Assets)'),'Ledger','','Balance Sheet',self.name,''], - [_('Expenses'),'','Group','Expense Account','Profit and Loss',self.name,''], - [_('Direct Expenses'),_('Expenses'),'Group','Expense Account','Profit and Loss',self.name,''], - [_('Stock Expenses'),_('Direct Expenses'),'Group','Expense Account','Profit and Loss',self.name,''], - [_('Cost of Goods Sold'),_('Stock Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Stock Adjustment'),_('Stock Expenses'),'Ledger','Stock Adjustment','Profit and Loss',self.name,''], - [_('Expenses Included In Valuation'), _("Stock Expenses"), 'Ledger', 'Expenses Included In Valuation', 'Profit and Loss', self.name, ''], - [_('Indirect Expenses'), _('Expenses'),'Group','Expense Account','Profit and Loss',self.name,''], - [_('Marketing Expenses'), _('Indirect Expenses'),'Ledger','Chargeable','Profit and Loss',self.name,''], - [_('Sales Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Administrative Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Charity and Donations'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Commission on Sales'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Travel Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Entertainment Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Depreciation'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Freight and Forwarding Charges'), _('Indirect Expenses'),'Ledger','Chargeable','Profit and Loss',self.name,''], - [_('Legal Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Miscellaneous Expenses'), _('Indirect Expenses'),'Ledger','Chargeable','Profit and Loss',self.name,''], - [_('Office Maintenance Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Office Rent'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Postal Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Print and Stationary'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Rounded Off'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Salary') ,_('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Telephone Expenses') ,_('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Utility Expenses') ,_('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss',self.name,''], - [_('Income'),'','Group','','Profit and Loss',self.name,''], - [_('Direct Income'),_('Income'),'Group','Income Account','Profit and Loss',self.name,''], - [_('Sales'),_('Direct Income'),'Ledger','Income Account','Profit and Loss',self.name,''], - [_('Service'),_('Direct Income'),'Ledger','Income Account','Profit and Loss',self.name,''], - [_('Indirect Income'),_('Income'),'Group','Income Account','Profit and Loss',self.name,''], - [_('Source of Funds (Liabilities)'),'','Group','','Balance Sheet',self.name,''], - [_('Capital Account'),_('Source of Funds (Liabilities)'),'Group','','Balance Sheet',self.name,''], - [_('Reserves and Surplus'),_('Capital Account'),'Ledger','','Balance Sheet',self.name,''], - [_('Shareholders Funds'),_('Capital Account'),'Ledger','','Balance Sheet',self.name,''], - [_('Current Liabilities'),_('Source of Funds (Liabilities)'),'Group','','Balance Sheet',self.name,''], - [_('Accounts Payable'),_('Current Liabilities'),'Group','','Balance Sheet',self.name,''], - [_('Stock Liabilities'),_('Current Liabilities'),'Group','','Balance Sheet',self.name,''], - [_('Stock Received But Not Billed'), _('Stock Liabilities'), 'Ledger', 'Stock Received But Not Billed', 'Balance Sheet', self.name, ''], - [_('Duties and Taxes'),_('Current Liabilities'),'Group','','Balance Sheet',self.name,''], - [_('Loans (Liabilities)'),_('Current Liabilities'),'Group','','Balance Sheet',self.name,''], - [_('Secured Loans'),_('Loans (Liabilities)'),'Group','','Balance Sheet',self.name,''], - [_('Unsecured Loans'),_('Loans (Liabilities)'),'Group','','Balance Sheet',self.name,''], - [_('Bank Overdraft Account'),_('Loans (Liabilities)'),'Group','','Balance Sheet',self.name,''], - [_('Temporary Accounts (Liabilities)'),_('Source of Funds (Liabilities)'),'Group','','Balance Sheet',self.name,''], - [_('Temporary Account (Liabilities)'),_('Temporary Accounts (Liabilities)'),'Ledger','','Balance Sheet',self.name,''] + [_('Application of Funds (Assets)'),'','Group','','Balance Sheet','', 'Asset'], + [_('Current Assets'),_('Application of Funds (Assets)'),'Group','','Balance Sheet','', 'Asset'], + [_('Accounts Receivable'),_('Current Assets'),'Group','','Balance Sheet','', 'Asset'], + [_('Bank Accounts'),_('Current Assets'),'Group','Bank','Balance Sheet','', 'Asset'], + [_('Cash In Hand'),_('Current Assets'),'Group','Cash','Balance Sheet','', 'Asset'], + [_('Cash'),_('Cash In Hand'),'Ledger','Cash','Balance Sheet','', 'Asset'], + [_('Loans and Advances (Assets)'),_('Current Assets'),'Group','','Balance Sheet','', 'Asset'], + [_('Securities and Deposits'),_('Current Assets'),'Group','','Balance Sheet','', 'Asset'], + [_('Earnest Money'),_('Securities and Deposits'),'Ledger','','Balance Sheet','', 'Asset'], + [_('Stock Assets'),_('Current Assets'),'Group','Stock','Balance Sheet','', 'Asset'], + [_('Tax Assets'),_('Current Assets'),'Group','','Balance Sheet','', 'Asset'], + [_('Fixed Assets'),_('Application of Funds (Assets)'),'Group','','Balance Sheet','', 'Asset'], + [_('Capital Equipments'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet','', 'Asset'], + [_('Computers'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet','', 'Asset'], + [_('Furniture and Fixture'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet','', 'Asset'], + [_('Office Equipments'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet','', 'Asset'], + [_('Plant and Machinery'),_('Fixed Assets'),'Ledger','Fixed Asset','Balance Sheet','', 'Asset'], + [_('Investments'),_('Application of Funds (Assets)'),'Group','','Balance Sheet','', 'Asset'], + [_('Temporary Accounts (Assets)'),_('Application of Funds (Assets)'),'Group','','Balance Sheet','', 'Asset'], + [_('Temporary Account (Assets)'),_('Temporary Accounts (Assets)'),'Ledger','','Balance Sheet','', 'Asset'], + [_('Expenses'),'','Group','Expense Account','Profit and Loss','', 'Expense'], + [_('Direct Expenses'),_('Expenses'),'Group','Expense Account','Profit and Loss','', 'Expense'], + [_('Stock Expenses'),_('Direct Expenses'),'Group','Expense Account','Profit and Loss','', 'Expense'], + [_('Cost of Goods Sold'),_('Stock Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Stock Adjustment'),_('Stock Expenses'),'Ledger','Stock Adjustment','Profit and Loss','', 'Expense'], + [_('Expenses Included In Valuation'), _("Stock Expenses"), 'Ledger', 'Expenses Included In Valuation', 'Profit and Loss', '', 'Expense'], + [_('Indirect Expenses'), _('Expenses'),'Group','Expense Account','Profit and Loss','', 'Expense'], + [_('Marketing Expenses'), _('Indirect Expenses'),'Ledger','Chargeable','Profit and Loss','', 'Expense'], + [_('Sales Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Administrative Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Charity and Donations'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Commission on Sales'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Travel Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Entertainment Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Depreciation'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Freight and Forwarding Charges'), _('Indirect Expenses'),'Ledger','Chargeable','Profit and Loss','', 'Expense'], + [_('Legal Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Miscellaneous Expenses'), _('Indirect Expenses'),'Ledger','Chargeable','Profit and Loss','', 'Expense'], + [_('Office Maintenance Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Office Rent'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Postal Expenses'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Print and Stationary'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Rounded Off'), _('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Salary') ,_('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Telephone Expenses') ,_('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Utility Expenses') ,_('Indirect Expenses'),'Ledger','Expense Account','Profit and Loss','', 'Expense'], + [_('Income'),'','Group','','Profit and Loss','', 'Income'], + [_('Direct Income'),_('Income'),'Group','Income Account','Profit and Loss','', 'Income'], + [_('Sales'),_('Direct Income'),'Ledger','Income Account','Profit and Loss','', 'Income'], + [_('Service'),_('Direct Income'),'Ledger','Income Account','Profit and Loss','', 'Income'], + [_('Indirect Income'),_('Income'),'Group','Income Account','Profit and Loss','', 'Income'], + [_('Source of Funds (Liabilities)'),'','Group','','Balance Sheet','', 'Income'], + [_('Capital Account'),_('Source of Funds (Liabilities)'),'Group','','Balance Sheet','', 'Liability'], + [_('Reserves and Surplus'),_('Capital Account'),'Ledger','','Balance Sheet','', 'Liability'], + [_('Shareholders Funds'),_('Capital Account'),'Ledger','','Balance Sheet','', 'Liability'], + [_('Current Liabilities'),_('Source of Funds (Liabilities)'),'Group','','Balance Sheet','', 'Liability'], + [_('Accounts Payable'),_('Current Liabilities'),'Group','','Balance Sheet','', 'Liability'], + [_('Stock Liabilities'),_('Current Liabilities'),'Group','','Balance Sheet','', 'Liability'], + [_('Stock Received But Not Billed'), _('Stock Liabilities'), 'Ledger', 'Stock Received But Not Billed', 'Balance Sheet', '', 'Liability'], + [_('Duties and Taxes'),_('Current Liabilities'),'Group','','Balance Sheet','', 'Liability'], + [_('Loans (Liabilities)'),_('Current Liabilities'),'Group','','Balance Sheet','', 'Liability'], + [_('Secured Loans'),_('Loans (Liabilities)'),'Group','','Balance Sheet','', 'Liability'], + [_('Unsecured Loans'),_('Loans (Liabilities)'),'Group','','Balance Sheet','', 'Liability'], + [_('Bank Overdraft Account'),_('Loans (Liabilities)'),'Group','','Balance Sheet','', 'Liability'], + [_('Temporary Accounts (Liabilities)'),_('Source of Funds (Liabilities)'),'Group','','Balance Sheet','', 'Liability'], + [_('Temporary Account (Liabilities)'),_('Temporary Accounts (Liabilities)'),'Ledger','','Balance Sheet','', 'Liability'] ] # load common account heads