def METHOD_NAME(query, store_id, category, min_price, max_price, sale):
    if sale:
        query = (
            query.select_from(models.Product.join(models.DiscountxProduct).join(models.Discount))
            .having(func.count(models.DiscountxProduct.product_id) > 0)
            .where(models.Discount.end_date > utils.time.now())
        )
    if store_id is not None:
        query = query.where(models.Product.store_id == store_id)
    if category and category != "all":
        query = query.where(models.Product.category == category)
    if min_price is not None:
        query = query.where(models.Product.price >= min_price)
    if max_price is not None:
        query = query.where(models.Product.price <= max_price)
    return query