'update requested qty (before ordered_qty is updated)'

def update_reserved_qty(self, so_item_rows=None):

    item_wh_list = []
    def _valid_for_reserve(item_code, warehouse):
        if (item_code and warehouse and ([item_code, warehouse] not in item_wh_list) and frappe.db.get_value(u'Item', item_code, u'is_stock_item')):
            item_wh_list.append([item_code, warehouse])
    for d in self.get(u'items'):
        if (((not so_item_rows) or (d.name in so_item_rows)) and (not d.delivered_by_supplier)):
            if self.has_product_bundle(d.item_code):
                for p in self.get(u'packed_items'):
                    if ((p.parent_detail_docname == d.name) and (p.parent_item == d.item_code)):
                        _valid_for_reserve(p.item_code, p.warehouse)
            else:
                _valid_for_reserve(d.item_code, d.warehouse)
    for (item_code, warehouse) in item_wh_list:
        update_bin_qty(item_code, warehouse, {u'reserved_qty': get_reserved_qty(item_code, warehouse)})
