Skip to content

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

Fix differences after merging with master

Marcin Gębaladdcf19c53e58
diff --git a/saleor/checkout/migrations/0015_merge_20180928_0658.py b/saleor/checkout/migrations/0015_merge_20180928_0658.py
new file mode 100644
index 0000000000..1b64b5ecb4
--- /dev/null
+++ b/saleor/checkout/migrations/0015_merge_20180928_0658.py
@@ -0,0 +1,14 @@
+# Generated by Django 2.0.8 on 2018-09-28 11:58
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('checkout', '0014_auto_20180921_0751'),
+ ('checkout', '0011_auto_20180814_0216'),
+ ]
+
+ operations = [
+ ]
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 377d3d3866..687612cf69 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -1,5 +1,6 @@
import graphene
from django.db import transaction
+from django.utils.translation import pgettext_lazy
from ...account.models import Address
from ...checkout import models
@@ -10,7 +11,6 @@ from ...core import analytics
from ...core.exceptions import InsufficientStock
from ..account.types import AddressInput, User
from ..core.mutations import BaseMutation, ModelMutation
-from ..order.mutations.draft_orders import check_lines_quantity
from ..order.types import Order
from ..product.types import ProductVariant
from ..shipping.types import ShippingMethod
@@ -18,6 +18,24 @@ from ..utils import get_nodes
from .types import Checkout, CheckoutLine
+def check_lines_quantity(variants, quantities):
+ """Check if stock is sufficient for each line in the list of dicts.
+ Return list of errors.
+ """
+ errors = []
+
+ for variant, quantity in zip(variants, quantities):
+ try:
+ variant.check_quantity(quantity)
+ except InsufficientStock as e:
+ message = pgettext_lazy(
+ 'Add line mutation error',
+ 'Could not add item. Only %(remaining)d remaining in stock.' %
+ {'remaining': e.item.quantity_available})
+ errors.append((variant.name, message))
+ return errors
+
+
class CheckoutLineInput(graphene.InputObjectType):
quantity = graphene.Int(description='quantity')
variant_id = graphene.ID(description='ID of product variant')