from warehouse_management.models import Warehouse


def get_available_stock(product_instance):
    # all_warehouses = Warehouse.objects.filter(recycle_bin=False)
    available_stock = 0.0
    # for warehouse in all_warehouses:
    #     warehouse_product_inventory = warehouse.warehouse_inventories.get(
    #         product=product_instance)
    product_inventories = product_instance.product_inventories.filter(
        recycle_bin=False)
    for inventory in product_inventories:
        if inventory.warehouse is not None:
            available_stock += float(inventory.quantity)
    return available_stock
