diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index 0e57b3f1986..1adc4c4d2f8 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -128,7 +128,8 @@ class Account(NestedSet): "account_currency": self.account_currency, "parent_account": parent_acc_name_map[company] }) - doc.save() + if not self.check_if_child_acc_exists(doc): + doc.save() frappe.msgprint(_("Account {0} is added in the child company {1}") .format(doc.name, company)) @@ -172,6 +173,24 @@ class Account(NestedSet): if frappe.db.get_value("GL Entry", {"account": self.name}): frappe.throw(_("Currency can not be changed after making entries using some other currency")) + def check_if_child_acc_exists(self, doc): + ''' Checks if a account in parent company exists in the ''' + info = frappe.db.get_value("Account", { + "account_name": doc.account_name, + "account_number": doc.account_number + }, ['company', 'account_currency', 'is_group', 'root_type', 'account_type', 'balance_must_be', 'account_name'], as_dict=1) + + if not info: + return + + doc = vars(doc) + dict_diff = [k for k in info if k in doc and info[k] != doc[k] and k != "company"] + if dict_diff: + frappe.throw(_("Account {0} already exists in child company {1}. The following fields have different values, they should be same: