def rebuild_node(doctype, parent, left, parent_field):
 from frappe.utils import now
 n = now()
 right = (left + 1)
 result = frappe.db.sql((u'SELECT name FROM `tab%s` WHERE `%s`=%s' % (doctype, parent_field, u'%s')), parent)
 for r in result:
  right = rebuild_node(doctype, r[0], right, parent_field)
 frappe.db.sql(u'UPDATE `tab{0}` SET lft=%s, rgt=%s, modified=%s\n DCTB  DCTB WHERE name=%s'.format(doctype), (left, right, n, parent))
 return (right + 1)

def rebuild_node ( doctype , parent , left , parent_field ) : from frappe . utils import now n = now ( ) right = ( left + 1 ) result = frappe . db . sql ( ( u'SELECT name FROM `tab%s` WHERE `%s`=%s' % ( doctype , parent_field , u'%s' ) ) , parent ) for r in result : right = rebuild_node ( doctype , r [ 0 ] , right , parent_field ) frappe . db . sql ( u'UPDATE `tab{0}` SET lft=%s, rgt=%s, modified=%s\n DCTB  DCTB WHERE name=%s' . format ( doctype ) , ( left , right , n , parent ) ) return ( right + 1 )
reset lft .