mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 11:19:09 +00:00
chore: validate is_group of child parent account before auto creating an account
This commit is contained in:
@@ -162,9 +162,16 @@ class Account(NestedSet):
|
|||||||
|
|
||||||
def create_account_for_child_company(self, parent_acc_name_map, descendants, parent_acc_name):
|
def create_account_for_child_company(self, parent_acc_name_map, descendants, parent_acc_name):
|
||||||
for company in descendants:
|
for company in descendants:
|
||||||
|
company_bold = frappe.bold(company)
|
||||||
|
parent_acc_name_bold = frappe.bold(parent_acc_name)
|
||||||
if not parent_acc_name_map.get(company):
|
if not parent_acc_name_map.get(company):
|
||||||
frappe.throw(_("While creating account for child Company {0}, parent account {1} not found. Please create the parent account in corresponding COA")
|
frappe.throw(_("While creating account for Child Company {0}, parent account {1} not found. Please create the parent account in corresponding COA")
|
||||||
.format(company, parent_acc_name))
|
.format(company_bold, parent_acc_name_bold), title=_("Account Not Found"))
|
||||||
|
if (frappe.db.get_value("Account", self.parent_account, "is_group")
|
||||||
|
and not frappe.db.get_value("Account", parent_acc_name_map[company], "is_group")):
|
||||||
|
frappe.throw(_("While creating account for Child Company {0}, parent account {1} is found \
|
||||||
|
as a ledger account.<br><br>Please convert the parent account in corresponding child company COA to a group account.")
|
||||||
|
.format(company_bold, parent_acc_name_bold), title=_("Invalid Parent Account"))
|
||||||
|
|
||||||
filters = {
|
filters = {
|
||||||
"account_name": self.account_name,
|
"account_name": self.account_name,
|
||||||
|
|||||||
@@ -111,6 +111,17 @@ class TestAccount(unittest.TestCase):
|
|||||||
self.assertEqual(acc_tc_4, "Test Sync Account - _TC4")
|
self.assertEqual(acc_tc_4, "Test Sync Account - _TC4")
|
||||||
self.assertEqual(acc_tc_5, "Test Sync Account - _TC5")
|
self.assertEqual(acc_tc_5, "Test Sync Account - _TC5")
|
||||||
|
|
||||||
|
def test_add_account_to_a_group(self):
|
||||||
|
frappe.db.set_value("Account", "Office Rent - _TC3", "is_group", 1)
|
||||||
|
|
||||||
|
acc = frappe.new_doc("Account")
|
||||||
|
acc.account_name = "Test Group Account"
|
||||||
|
acc.parent_account = "Office Rent - _TC3"
|
||||||
|
acc.company = "_Test Company 3"
|
||||||
|
self.assertRaises(frappe.ValidationError, acc.insert)
|
||||||
|
|
||||||
|
frappe.db.set_value("Account", "Office Rent - _TC3", "is_group", 0)
|
||||||
|
|
||||||
def _make_test_records(verbose):
|
def _make_test_records(verbose):
|
||||||
from frappe.test_runner import make_test_objects
|
from frappe.test_runner import make_test_objects
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user