Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change type of start and end date in sales to date time field
fowczarek18a820b2735a
diff --git a/saleor/core/middleware.py b/saleor/core/middleware.pyindex 513b0eb0e0..b7789ce89f 100644--- a/saleor/core/middleware.py+++ b/saleor/core/middleware.py@@ -1,4 +1,3 @@-import datetimeimport loggingfrom functools import wrapsfrom typing import Callable@@ -17,6 +16,7 @@ from django.conf import settingsfrom django.contrib.sites.models import Sitefrom django.core.exceptions import MiddlewareNotUsedfrom django.urls import reverse+from django.utils import timezonefrom django.utils.functional import SimpleLazyObjectfrom django.utils.translation import get_languagefrom django_countries.fields import Country@@ -106,9 +106,7 @@ def discounts(get_response):"""Assign active discounts to `request.discounts`."""def middleware(request):- request.discounts = SimpleLazyObject(- lambda: fetch_discounts(datetime.date.today())- )+ request.discounts = SimpleLazyObject(lambda: fetch_discounts(timezone.now()))return get_response(request)return middlewarediff --git a/saleor/data_feeds/google_merchant.py b/saleor/data_feeds/google_merchant.pyindex 148ecf6736..3e77188963 100644--- a/saleor/data_feeds/google_merchant.py+++ b/saleor/data_feeds/google_merchant.py@@ -1,5 +1,4 @@import csv-import datetimeimport gzipfrom typing import Iterable@@ -7,6 +6,7 @@ from django.conf import settingsfrom django.contrib.sites.models import Sitefrom django.contrib.syndication.views import add_domainfrom django.core.files.storage import default_storage+from django.utils import timezonefrom django.utils.encoding import smart_textfrom ..discount import DiscountInfo@@ -222,7 +222,7 @@ def write_feed(file_obj):writer = csv.DictWriter(file_obj, ATTRIBUTES, dialect=csv.excel_tab)writer.writeheader()categories = Category.objects.all()- discounts = fetch_discounts(datetime.date.today())+ discounts = fetch_discounts(timezone.now())attributes_dict = {a.slug: a.pk for a in Attribute.objects.all()}attribute_values_dict = {smart_text(a.pk): smart_text(a) for a in AttributeValue.objects.all()diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 6610faf3bc..ca56931c9b 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -1,4 +1,3 @@-from datetime import datefrom decimal import Decimalfrom functools import partial@@ -186,8 +185,8 @@ class Sale(models.Model):products = models.ManyToManyField("product.Product", blank=True)categories = models.ManyToManyField("product.Category", blank=True)collections = models.ManyToManyField("product.Collection", blank=True)- start_date = models.DateField(default=date.today)- end_date = models.DateField(null=True, blank=True)+ start_date = models.DateTimeField(default=timezone.now)+ end_date = models.DateTimeField(null=True, blank=True)objects = SaleQueryset.as_manager()translated = TranslationProxy()diff --git a/saleor/graphql/discount/filters.py b/saleor/graphql/discount/filters.pyindex 5845303a4c..3ff97ebf83 100644--- a/saleor/graphql/discount/filters.py+++ b/saleor/graphql/discount/filters.py@@ -7,7 +7,7 @@ from django.utils import timezonefrom ...discount import DiscountValueTypefrom ...discount.models import Sale, Voucher, VoucherQuerysetfrom ..core.filters import ListObjectTypeFilter, ObjectTypeFilter-from ..core.types.common import DateRangeInput, DateTimeRangeInput, IntRangeInput+from ..core.types.common import DateTimeRangeInput, IntRangeInputfrom ..utils import filter_by_query_paramfrom .enums import DiscountStatusEnum, DiscountValueTypeEnum, VoucherDiscountType@@ -103,7 +103,7 @@ class SaleFilter(django_filters.FilterSet):sale_type = ObjectTypeFilter(input_class=DiscountValueTypeEnum, method=filter_sale_type)- started = ObjectTypeFilter(input_class=DateRangeInput, method=filter_started)+ started = ObjectTypeFilter(input_class=DateTimeRangeInput, method=filter_started)search = django_filters.CharFilter(method=filter_sale_search)class Meta:diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.pyindex 8198e93d1c..bc844b7b32 100644--- a/saleor/graphql/discount/mutations.py+++ b/saleor/graphql/discount/mutations.py@@ -211,8 +211,12 @@ class SaleInput(graphene.InputObjectType):description="Collections related to the discount.",name="collections",)- start_date = graphene.Date(description="Start date of the sale in ISO 8601 format.")- end_date = graphene.Date(description="End date of the sale in ISO 8601 format.")+ start_date = graphene.types.datetime.DateTime(+ description="Start date of the voucher in ISO 8601 format."+ )+ end_date = graphene.types.datetime.DateTime(+ description="End date of the voucher in ISO 8601 format."+ )class SaleCreate(ModelMutation):diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex ae7fffadcd..d0958fc4e7 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -747,7 +747,7 @@ def test_sale_remove_no_catalogues(({"status": "ACTIVE"},timezone.now().replace(year=2015, month=1, day=1),- timezone.now().replace(year=2020, month=1, day=1),+ timezone.now() + timedelta(days=365),2,),(diff --git a/tests/test_discounts.py b/tests/test_discounts.pyindex dc59bc8226..766a55ce6b 100644--- a/tests/test_discounts.py+++ b/tests/test_discounts.py@@ -300,7 +300,4 @@ def test_sale_active(current_date, start_date, end_date, is_active):type=DiscountValueType.FIXED, value=5, start_date=start_date, end_date=end_date)sale_is_active = Sale.objects.active(date=current_date).exists()- if not is_active == sale_is_active:- print(current_date.isoformat())- print(start_date.isoformat())assert is_active == sale_is_active