mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-03 00:23:21 +00:00
Merge pull request #7050 from nabinhait/coa_based_on_existing_company
Create Chart of Accounts based on existing company
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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