fix: Parent company defaulting on creation of new company (#20422)

* fix: Parent company defaulting on creation of new company

* fix: Test Cases

* fix: Test Cases

* fix: Test Cases for staffing plan
This commit is contained in:
Deepesh Garg
2020-01-28 12:54:45 +05:30
committed by Nabin Hait
parent 3fb48ebf61
commit cd8d667861
3 changed files with 22 additions and 4 deletions

View File

@@ -4,6 +4,15 @@
frappe.provide("erpnext.company");
frappe.ui.form.on("Company", {
onload: function(frm) {
if (frm.doc.__islocal && frm.doc.parent_company) {
frappe.db.get_value('Company', frm.doc.parent_company, 'is_group', (r) => {
if (!r.is_group) {
frm.set_value('parent_company', '');
}
});
}
},
setup: function(frm) {
erpnext.company.setup_queries(frm);
frm.set_query("hra_component", function(){

View File

@@ -47,6 +47,7 @@ class Company(NestedSet):
self.validate_perpetual_inventory()
self.check_country_change()
self.set_chart_of_accounts()
self.validate_parent_company()
def validate_abbr(self):
if not self.abbr:
@@ -189,6 +190,13 @@ class Company(NestedSet):
self.create_chart_of_accounts_based_on = "Existing Company"
self.existing_company = self.parent_company
def validate_parent_company(self):
if self.parent_company:
is_group = frappe.get_value('Company', self.parent_company, 'is_group')
if not is_group:
frappe.throw(_("Parent Company must be a group company"))
def set_default_accounts(self):
default_accounts = {
"default_cash_account": "Cash",