diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index f1d822a89c..46f75208fc 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -23,6 +23,7 @@ class Account(Document): def validate(self): self.validate_parent() self.validate_root_details() + self.set_root_and_report_type() self.validate_mandatory() self.validate_warehouse_account() self.validate_frozen_accounts_modifier() @@ -32,7 +33,7 @@ class Account(Document): """Fetch Parent Details and validate parent account""" if self.parent_account: par = frappe.db.get_value("Account", self.parent_account, - ["name", "is_group", "report_type", "root_type", "company"], as_dict=1) + ["name", "is_group", "company"], as_dict=1) if not par: throw(_("Account {0}: Parent account {1} does not exist").format(self.name, self.parent_account)) elif par.name == self.name: @@ -43,10 +44,24 @@ class Account(Document): throw(_("Account {0}: Parent account {1} does not belong to company: {2}") .format(self.name, self.parent_account, self.company)) + def set_root_and_report_type(self): + if self.parent_account: + par = frappe.db.get_value("Account", self.parent_account, ["report_type", "root_type"], as_dict=1) + if par.report_type: self.report_type = par.report_type if par.root_type: self.root_type = par.root_type + + if self.is_group: + db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1) + if db_value: + if self.report_type != db_value.report_type: + frappe.db.sql("update `tabAccount` set report_type=%s where lft > %s and rgt < %s", + (self.report_type, self.lft, self.rgt)) + if self.root_type != db_value.root_type: + frappe.db.sql("update `tabAccount` set root_type=%s where lft > %s and rgt < %s", + (self.root_type, self.lft, self.rgt)) def validate_root_details(self): # does not exists parent diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 75c1dff576..78e1609990 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -183,4 +183,5 @@ execute:frappe.delete_doc("DocType", "Party Type") execute:frappe.delete_doc("Module Def", "Contacts") erpnext.patches.v5_4.fix_reserved_qty_and_sle_for_packed_items # 30-07-2015 execute:frappe.reload_doctype("Leave Type") -execute:frappe.db.sql("update `tabLeave Type` set include_holiday=0") \ No newline at end of file +execute:frappe.db.sql("update `tabLeave Type` set include_holiday=0") +erpnext.patches.v5_4.set_root_and_report_type \ No newline at end of file diff --git a/erpnext/patches/v5_4/set_root_and_report_type.py b/erpnext/patches/v5_4/set_root_and_report_type.py new file mode 100644 index 0000000000..9147644da2 --- /dev/null +++ b/erpnext/patches/v5_4/set_root_and_report_type.py @@ -0,0 +1,12 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + roots = frappe.db.sql("""select lft, rgt, report_type, root_type + from `tabAccount` where ifnull(parent_account, '')=''""", as_dict=1) + for d in roots: + frappe.db.sql("update `tabAccount` set report_type=%s, root_type=%s where lft > %s and rgt < %s", + (d.report_type, d.root_type, d.lft, d.rgt)) \ No newline at end of file