Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Get stock quantity for variant in given country
Mira Szewczyk896f92f4302c
diff --git a/saleor/stock/stock_management.py b/saleor/stock/stock_management.pyindex 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_availablediff --git a/tests/test_cart.py b/tests/test_cart.pyindex 831439b45c..14e9ecfa87 100644--- a/tests/test_cart.py+++ b/tests/test_cart.py@@ -8,20 +8,7 @@ from prices import Money, TaxedMoneyfrom saleor.checkout import calculations, utilsfrom saleor.checkout.context_processors import checkout_counterfrom saleor.checkout.models import Checkout-<<<<<<< HEADfrom 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 functionfrom saleor.product.models import Categoryfrom saleor.stock.models import Stock