Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add new fields to voucher sort
fowczarek8e3f004b2eb0
diff --git a/saleor/graphql/discount/sorters.py b/saleor/graphql/discount/sorters.pyindex cc8015b529..27a08efbb1 100644--- a/saleor/graphql/discount/sorters.py+++ b/saleor/graphql/discount/sorters.py@@ -32,23 +32,25 @@ class SaleSortingInput(SortInputObjectType):class VoucherSortField(graphene.Enum):- NAME = "name"+ CODE = "code"START_DATE = "start_date"END_DATE = "end_date"VALUE = "discount_value"TYPE = "type"USAGE_LIMIT = "usage_limit"+ MINIMUM_SPENT_AMOUNT = "min_spent_amount"@propertydef description(self):# pylint: disable=no-memberif self in [- VoucherSortField.NAME,+ VoucherSortField.CODE,VoucherSortField.START_DATE,VoucherSortField.END_DATE,VoucherSortField.VALUE,VoucherSortField.TYPE,VoucherSortField.USAGE_LIMIT,+ VoucherSortField.MINIMUM_SPENT_AMOUNT,]:sort_name = self.name.lower().replace("_", " ")return f"Sort vouchers by {sort_name}."diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex ea44fccbec..b42f302279 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -4465,12 +4465,13 @@ type VoucherRemoveCatalogues {}enum VoucherSortField {- NAME+ CODESTART_DATEEND_DATEVALUETYPEUSAGE_LIMIT+ MINIMUM_SPENT_AMOUNT}input VoucherSortingInput {diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex b47446d590..7e6b6b1135 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -976,12 +976,12 @@ QUERY_VOUCHER_WITH_SORT = """"voucher_sort, result_order",[(- {"field": "NAME", "direction": "ASC"},- ["FreeShipping", "Voucher1", "Voucher2"],+ {"field": "CODE", "direction": "ASC"},+ ["Voucher2", "Voucher1", "FreeShipping"],),(- {"field": "NAME", "direction": "DESC"},- ["Voucher2", "Voucher1", "FreeShipping"],+ {"field": "CODE", "direction": "DESC"},+ ["FreeShipping", "Voucher1", "Voucher2"],),({"field": "VALUE", "direction": "ASC"},@@ -1023,6 +1023,14 @@ QUERY_VOUCHER_WITH_SORT = """{"field": "USAGE_LIMIT", "direction": "DESC"},["Voucher2", "FreeShipping", "Voucher1"],),+ (+ {"field": "MINIMUM_SPENT_AMOUNT", "direction": "ASC"},+ ["Voucher2", "FreeShipping", "Voucher1"],+ ),+ (+ {"field": "MINIMUM_SPENT_AMOUNT", "direction": "DESC"},+ ["Voucher1", "FreeShipping", "Voucher2"],+ ),],)def test_query_vouchers_with_sort(@@ -1046,6 +1054,7 @@ def test_query_vouchers_with_sort(type=VoucherType.ENTIRE_ORDER,start_date=timezone.now().replace(year=2012, month=1, day=5),end_date=timezone.now().replace(year=2013, month=1, day=5),+ min_spent_amount=50,),Voucher(name="FreeShipping",@@ -1056,6 +1065,7 @@ def test_query_vouchers_with_sort(start_date=timezone.now().replace(year=2011, month=1, day=5),end_date=timezone.now().replace(year=2015, month=12, day=31),usage_limit=1000,+ min_spent_amount=500,),])