mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-03 00:23:21 +00:00
Create Chart of Accounts based on existing company
This commit is contained in:
@@ -294,6 +294,34 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "default_currency",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 1,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Currency",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@@ -349,61 +377,6 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "default_currency",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 1,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Currency",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "column_break_14",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@@ -449,7 +422,7 @@
|
||||
"in_standard_filter": 0,
|
||||
"label": "Chart Of Accounts Template",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"no_copy": 1,
|
||||
"options": "",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
@@ -479,7 +452,7 @@
|
||||
"in_standard_filter": 0,
|
||||
"label": "Existing Company ",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"no_copy": 1,
|
||||
"options": "Company",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
@@ -1633,7 +1606,7 @@
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"menu_index": 0,
|
||||
"modified": "2016-11-22 04:14:51.319655",
|
||||
"modified": "2016-11-23 16:32:04.893315",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Company",
|
||||
|
||||
@@ -30,6 +30,7 @@ class Company(Document):
|
||||
self.validate_abbr()
|
||||
self.validate_default_accounts()
|
||||
self.validate_currency()
|
||||
self.validate_coa_input()
|
||||
|
||||
def validate_abbr(self):
|
||||
if not self.abbr:
|
||||
@@ -113,16 +114,25 @@ class Company(Document):
|
||||
warehouse.insert()
|
||||
|
||||
def create_default_accounts(self):
|
||||
if not self.chart_of_accounts:
|
||||
self.chart_of_accounts = "Standard"
|
||||
|
||||
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts
|
||||
create_charts(self.chart_of_accounts, self.name)
|
||||
create_charts(self.name, self.chart_of_accounts, self.existing_company)
|
||||
|
||||
frappe.db.set(self, "default_receivable_account", frappe.db.get_value("Account",
|
||||
{"company": self.name, "account_type": "Receivable", "is_group": 0}))
|
||||
frappe.db.set(self, "default_payable_account", frappe.db.get_value("Account",
|
||||
{"company": self.name, "account_type": "Payable", "is_group": 0}))
|
||||
|
||||
def validate_coa_input(self):
|
||||
if self.create_chart_of_accounts_based_on == "Existing Company":
|
||||
self.chart_of_accounts = None
|
||||
if not self.existing_company:
|
||||
frappe.throw(_("Please select Existing Company for creating Chart of Accounts"))
|
||||
|
||||
else:
|
||||
self.existing_company = None
|
||||
self.create_chart_of_accounts_based_on = "Standard Template"
|
||||
if not self.chart_of_accounts:
|
||||
self.chart_of_accounts = "Standard"
|
||||
|
||||
def set_default_accounts(self):
|
||||
self._set_default_account("default_cash_account", "Cash")
|
||||
|
||||
@@ -7,8 +7,40 @@ test_ignore = ["Account", "Cost Center"]
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
class TestCompany(unittest.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
test_records = frappe.get_test_records('Company')
|
||||
|
||||
class TestCompany(unittest.TestCase):
|
||||
def test_coa_based_on_existing_company(self):
|
||||
make_company()
|
||||
|
||||
expected_results = {
|
||||
"Debtors - CFEC": {
|
||||
"account_type": "Receivable",
|
||||
"is_group": 0,
|
||||
"root_type": "Asset",
|
||||
"parent_account": "Accounts Receivable - CFEC",
|
||||
},
|
||||
"_Test Cash - CFEC": {
|
||||
"account_type": "Cash",
|
||||
"is_group": 0,
|
||||
"root_type": "Asset",
|
||||
"parent_account": "Cash In Hand - CFEC"
|
||||
}
|
||||
}
|
||||
|
||||
for account, acc_property in expected_results.items():
|
||||
acc = frappe.get_doc("Account", account)
|
||||
for prop, val in acc_property.items():
|
||||
self.assertEqual(acc.get(prop), val)
|
||||
|
||||
|
||||
def make_company():
|
||||
company = frappe.new_doc("Company")
|
||||
company.company_name = "COA from Existing Company"
|
||||
company.abbr = "CFEC"
|
||||
company.default_currency = "INR"
|
||||
company.create_chart_of_accounts_based_on = "Existing Company"
|
||||
company.existing_company = "_Test Company"
|
||||
company.save()
|
||||
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ def create_fiscal_year_and_company(args):
|
||||
'abbr':args.get('company_abbr'),
|
||||
'default_currency':args.get('currency'),
|
||||
'country': args.get('country'),
|
||||
'create_chart_of_accounts_based_on': 'Standard Template',
|
||||
'chart_of_accounts': args.get(('chart_of_accounts')),
|
||||
'domain': args.get('domain')
|
||||
}).insert()
|
||||
|
||||
Reference in New Issue
Block a user