
from django.db.models import Q

from shuup.core.models import Order


class OrderReportMixin(object):
    def get_objects(self):
        queryset = Order.objects.filter(
            shop=self.shop,
            order_date__range=(self.start_date, self.end_date))
        creator = self.options.get("creator")
        orderer = self.options.get("orderer")
        customer = self.options.get("customer")
        filters = Q()
        if creator:
            filters &= Q(creator__in=creator)
        if orderer:
            filters &= Q(orderer__in=orderer)
        if customer:
            filters &= Q(customer__in=customer)

        return queryset.filter(filters).valid().paid().order_by("order_date")

from datetime import timedelta

from django.db.models import Q

from shuup.core.models import Order
from shuup.utils.dates import to_aware


class OrderReportMixin(object):
    def get_objects(self):
        start = to_aware(self.start_date)  # 0:00 on start_date
        end = to_aware(self.end_date) + timedelta(days=1)  # 24:00 on end_date
        queryset = Order.objects.filter(
            shop=self.shop, order_date__range=(start, end))
        creator = self.options.get("creator")
        orderer = self.options.get("orderer")
        customer = self.options.get("customer")
        filters = Q()
        if creator:
            filters &= Q(creator__in=creator)
        if orderer:
            filters &= Q(orderer__in=orderer)
        if customer:
            filters &= Q(customer__in=customer)

        return queryset.filter(filters).valid().paid().order_by("order_date")

Include orders which are made during selected end date in reports
Include orders which are made during selected end date in reports

Comparing DateTimeField with date causes lack of precision which
can occur with range. This causes orders which order_date is
the same date than end_date will be not included in the queryset.
Fix this problem with adding one extra day to the end_date value
and so order made during the selected end date will be also included
in the reports.

+ from datetime import timedelta
  
  from django.db.models import Q
  
  from shuup.core.models import Order
+ from shuup.utils.dates import to_aware
  
  
  class OrderReportMixin(object):
      def get_objects(self):
+         start = to_aware(self.start_date)  # 0:00 on start_date
+         end = to_aware(self.end_date) + timedelta(days=1)  # 24:00 on end_date
          queryset = Order.objects.filter(
+             shop=self.shop, order_date__range=(start, end))
-             shop=self.shop,
-             order_date__range=(self.start_date, self.end_date))
          creator = self.options.get("creator")
          orderer = self.options.get("orderer")
          customer = self.options.get("customer")
          filters = Q()
          if creator:
              filters &= Q(creator__in=creator)
          if orderer:
              filters &= Q(orderer__in=orderer)
          if customer:
              filters &= Q(customer__in=customer)
  
          return queryset.filter(filters).valid().paid().order_by("order_date")
  
Include orders which are made during selected end date in reports
## Code Before:

from django.db.models import Q

from shuup.core.models import Order


class OrderReportMixin(object):
    def get_objects(self):
        queryset = Order.objects.filter(
            shop=self.shop,
            order_date__range=(self.start_date, self.end_date))
        creator = self.options.get("creator")
        orderer = self.options.get("orderer")
        customer = self.options.get("customer")
        filters = Q()
        if creator:
            filters &= Q(creator__in=creator)
        if orderer:
            filters &= Q(orderer__in=orderer)
        if customer:
            filters &= Q(customer__in=customer)

        return queryset.filter(filters).valid().paid().order_by("order_date")

## Instruction:
Include orders which are made during selected end date in reports
## Code After:
from datetime import timedelta

from django.db.models import Q

from shuup.core.models import Order
from shuup.utils.dates import to_aware


class OrderReportMixin(object):
    def get_objects(self):
        start = to_aware(self.start_date)  # 0:00 on start_date
        end = to_aware(self.end_date) + timedelta(days=1)  # 24:00 on end_date
        queryset = Order.objects.filter(
            shop=self.shop, order_date__range=(start, end))
        creator = self.options.get("creator")
        orderer = self.options.get("orderer")
        customer = self.options.get("customer")
        filters = Q()
        if creator:
            filters &= Q(creator__in=creator)
        if orderer:
            filters &= Q(orderer__in=orderer)
        if customer:
            filters &= Q(customer__in=customer)

        return queryset.filter(filters).valid().paid().order_by("order_date")
