Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Get stock quantity for variant in given country

Mira Szewczyk896f92f4302c
diff --git a/saleor/stock/stock_management.py b/saleor/stock/stock_management.py
index e15e994d8e..a07a3046cf 100644
--- a/saleor/stock/stock_management.py
+++ b/saleor/stock/stock_management.py
@@ -15,3 +15,11 @@ def check_stock_quantity(variant: "ProductVariant", country_code: str, quantity:
if variant.track_inventory and quantity > stock.quantity_available:
raise InsufficientStock(variant)
+
+
+def get_available_quantity(variant: "ProductVariant", country_code: str) -> int:
+ try:
+ stock = Stock.objects.for_country(country_code).get(product_variant=variant)
+ except Stock.DoesNotExist:
+ return 0
+ return stock.quantity_available
diff --git a/tests/test_cart.py b/tests/test_cart.py
index 831439b45c..14e9ecfa87 100644
--- a/tests/test_cart.py
+++ b/tests/test_cart.py
@@ -8,20 +8,7 @@ from prices import Money, TaxedMoney
from saleor.checkout import calculations, utils
from saleor.checkout.context_processors import checkout_counter
from saleor.checkout.models import Checkout
-<<<<<<< HEAD
from saleor.checkout.utils import add_variant_to_checkout
-=======
-from saleor.checkout.utils import (
- add_variant_to_checkout,
- change_checkout_user,
- check_variant_in_stock,
- find_open_checkout_for_user,
- get_shipping_price_estimate,
-)
-from saleor.checkout.views import clear_checkout, update_checkout_line
-from saleor.core.exceptions import InsufficientStock
-from saleor.discount.models import Sale
->>>>>>> Add tests for check_variant_in_stock function
from saleor.product.models import Category
from saleor.stock.models import Stock