From cbdaa47a3568acac0c26004a2e173a439df1f4c7 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 8 Aug 2013 12:42:17 +0530 Subject: [PATCH] [minor] [validation] ledger can not have a child --- webnotes/utils/nestedset.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/webnotes/utils/nestedset.py b/webnotes/utils/nestedset.py index d781a4e371..95c1bbd90b 100644 --- a/webnotes/utils/nestedset.py +++ b/webnotes/utils/nestedset.py @@ -181,6 +181,7 @@ def validate_loop(doctype, name, lft, rgt): class DocTypeNestedSet(object): def on_update(self): update_nsm(self) + self.validate_ledger() def on_trash(self): parent = self.doc.fields[self.nsm_parent_field] @@ -205,3 +206,11 @@ class DocTypeNestedSet(object): if webnotes.conn.sql("""select count(*) from `tab%s` where ifnull(%s, '')=''""" % (self.doc.doctype, self.nsm_parent_field))[0][0] > 1: webnotes.throw(_("""Multiple root nodes not allowed.""")) + + def validate_ledger(self, group_identifier="is_group"): + if self.doc.fields.get(group_identifier) == "No": + if webnotes.conn.sql("""select name from `tab%s` where %s=%s and docstatus!=2""" % + (self.doc.doctype, self.nsm_parent_field, '%s'), (self.doc.name)): + webnotes.throw(self.doc.doctype + ": " + self.doc.name + + _(" can not be marked as a ledger as it has existing child")) + \ No newline at end of file