Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor check lines quantity
fowczareke8c4295c09d2
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 97af0ea496..c517996127 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -70,10 +70,11 @@ def check_lines_quantity(variants, quantities):variant.check_quantity(quantity)except InsufficientStock as e:message = (- 'Add line mutation error',- 'Could not add item. Only %(remaining)d remaining in stock.' %- {'remaining': e.item.quantity_available})- errors.append((variant.name, message))+ 'Could not add item '+ + '%(item_name)s. Only %(remaining)d remaining in stock.' % {+ 'remaining': e.item.quantity_available,+ 'item_name': e.item.display_product()})+ errors.append(('quantity', message))return errors@@ -180,6 +181,8 @@ class CheckoutLinesAdd(BaseMutation):if line_errors:for err in line_errors:cls.add_error(errors, field=err[0], message=err[1])+ if errors:+ return CheckoutLinesAdd(errors=errors)if variants and quantities:for variant, quantity in zip(variants, quantities):diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.pyindex 352769f691..1b7406e931 100644--- a/tests/api/test_checkout.py+++ b/tests/api/test_checkout.py@@ -127,7 +127,6 @@ def test_checkout_check_lines_quantity('lines': [{'variantId': variant_id, 'quantity': 3}]}response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_ADD, variables)- # import ipdb; ipdb.set_trace()content = get_graphql_content(response)data = content['data']['checkoutLinesAdd']assert data['errors'][0]['message'] == 'Could not add item Test product (SKU_A). Only 2 remaining in stock.'