'Pull Material Requests that are pending based on criteria selected'

def get_pending_material_requests(self):

    mr_filter = item_filter = u''
    if self.from_date:
        mr_filter += u'    and    mr.transaction_date    >=    %(from_date)s'
    if self.to_date:
        mr_filter += u'    and    mr.transaction_date    <=    %(to_date)s'
    if self.warehouse:
        mr_filter += u'    and    mr_item.warehouse    =    %(warehouse)s'
    if self.fg_item:
        item_filter += u'    and    mr_item.item_code    =    %(item)s'
    pending_mr = frappe.db.sql(u'\n DCTB  DCTB  DCTB select    distinct    mr.name,    mr.transaction_date\n DCTB  DCTB  DCTB from    `tabMaterial    Request`    mr,    `tabMaterial    Request    Item`    mr_item\n DCTB  DCTB  DCTB where    mr_item.parent    =    mr.name\n DCTB  DCTB  DCTB  DCTB and    mr.material_request_type    =    "Manufacture"\n DCTB  DCTB  DCTB  DCTB and    mr.docstatus    =    1\n DCTB  DCTB  DCTB  DCTB and    mr_item.qty    >    ifnull(mr_item.ordered_qty,0)    {0}    {1}\n DCTB  DCTB  DCTB  DCTB and    (exists    (select    name    from    `tabBOM`    bom    where    bom.item=mr_item.item_code\n DCTB  DCTB  DCTB  DCTB  DCTB and    bom.is_active    =    1))\n DCTB  DCTB  DCTB '.format(mr_filter, item_filter), {u'from_date': self.from_date, u'to_date': self.to_date, u'warehouse': self.warehouse, u'item': self.fg_item}, as_dict=1)
    self.add_mr_in_table(pending_mr)
