Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add voucher once per customer in API
fowczarekcd4a90a69921
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.pyindex f44dc82ae3..21344ed386 100644--- a/saleor/graphql/discount/mutations.py+++ b/saleor/graphql/discount/mutations.py@@ -111,6 +111,9 @@ class VoucherInput(graphene.InputObjectType):apply_once_per_order = graphene.Boolean(description="Voucher should be applied to the cheapest item or entire order.")+ apply_once_per_customer = graphene.Boolean(+ description="Voucher should be applied once per customer."+ )usage_limit = graphene.Int(description="Limit number of times this voucher can be used in total")diff --git a/saleor/graphql/discount/types.py b/saleor/graphql/discount/types.pyindex 88710c0714..d1232366d1 100644--- a/saleor/graphql/discount/types.py+++ b/saleor/graphql/discount/types.py@@ -110,6 +110,7 @@ class Voucher(CountableDjangoObjectType):providing valid voucher codes."""only_fields = ["apply_once_per_order",+ "apply_once_per_customer","code","discount_value","discount_value_type",diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex 44b5d670ad..595e1fbd53 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -82,6 +82,7 @@ def test_voucher_query(startDatediscountValueTypediscountValue+ applyOncePerCustomercountries {codecountry@@ -101,6 +102,7 @@ def test_voucher_query(assert data["name"] == voucher_countries.nameassert data["code"] == voucher_countries.codeassert data["usageLimit"] == voucher_countries.usage_limit+ assert data["applyOncePerCustomer"] == voucher_countries.apply_once_per_customerassert data["used"] == voucher_countries.usedassert data["startDate"] == voucher_countries.start_date.isoformat()assert data["discountValueType"] == voucher_countries.discount_value_type.upper()@@ -142,15 +144,16 @@ mutation voucherCreate($type: VoucherTypeEnum, $name: String, $code: String,$discountValueType: DiscountValueTypeEnum, $usageLimit: Int,$discountValue: Decimal, $minAmountSpent: Decimal, $minCheckoutItemsQuantity: Int,- $startDate: DateTime, $endDate: DateTime, $applyOncePerOrder: Boolean) {+ $startDate: DateTime, $endDate: DateTime, $applyOncePerOrder: Boolean,+ $applyOncePerCustomer: Boolean) {voucherCreate(input: {name: $name, type: $type, code: $code,discountValueType: $discountValueType,- discountValue: $discountValue,- minAmountSpent: $minAmountSpent,+ discountValue: $discountValue, minAmountSpent: $minAmountSpent,minCheckoutItemsQuantity: $minCheckoutItemsQuantity,- startDate: $startDate, endDate: $endDate,- applyOncePerOrder: $applyOncePerOrder, usageLimit: $usageLimit}) {+ startDate: $startDate, endDate: $endDate, usageLimit: $usageLimit+ applyOncePerOrder: $applyOncePerOrder,+ applyOncePerCustomer: $applyOncePerCustomer}) {errors {fieldmessage@@ -167,6 +170,7 @@ mutation voucherCreate(startDateendDateapplyOncePerOrder+ applyOncePerCustomer}}}@@ -188,6 +192,7 @@ def test_create_voucher(staff_api_client, permission_manage_discounts):"startDate": start_date.isoformat(),"endDate": end_date.isoformat(),"applyOncePerOrder": True,+ "applyOncePerCustomer": True,"usageLimit": 3,}@@ -204,6 +209,7 @@ def test_create_voucher(staff_api_client, permission_manage_discounts):assert voucher.start_date == start_dateassert voucher.end_date == end_dateassert voucher.apply_once_per_order+ assert voucher.apply_once_per_customerassert voucher.usage_limit == 3