'Check whether recursion occurs in any bom'

def check_recursion(self):

    check_list = [[u'parent', u'bom_no', u'parent'], [u'bom_no', u'parent', u'child']]
    for d in check_list:
        (bom_list, count) = ([self.name], 0)
        while (len(bom_list) > count):
            boms = frappe.db.sql((u'    select    %s    from    `tabBOM    Item`    where    %s    =    %s    ' % (d[0], d[1], u'%s')), cstr(bom_list[count]))
            count = (count + 1)
            for b in boms:
                if (b[0] == self.name):
                    frappe.throw(_(u'BOM    recursion:    {0}    cannot    be    parent    or    child    of    {2}').format(b[0], self.name))
                if b[0]:
                    bom_list.append(b[0])
