'issue (item quantity) that is pending to issue or desire to transfer,
whichever is less'

def get_pending_raw_materials(self):

    item_dict = self.get_pro_order_required_items()
    max_qty = flt(self.pro_doc.qty)
    for (item, item_details) in item_dict.items():
        pending_to_issue = (flt(item_details.required_qty) - flt(item_details.transferred_qty))
        desire_to_transfer = ((flt(self.fg_completed_qty) * flt(item_details.required_qty)) / max_qty)
        if (desire_to_transfer <= pending_to_issue):
            item_dict[item][u'qty'] = desire_to_transfer
        elif (pending_to_issue > 0):
            item_dict[item][u'qty'] = pending_to_issue
        else:
            item_dict[item][u'qty'] = 0
    for item in item_dict.keys():
        if (not item_dict[item][u'qty']):
            del item_dict[item]
    if (not len(item_dict)):
        frappe.msgprint(_(u'All    items    have    already    been    transferred    for    this    Production    Order.'))
    return item_dict
