from oscar.apps.customer.views import OrderHistoryView as BaseOrderHistoryView

from ocyan.plugin.oscar.pipeline import PIPELINE_STATUS_CANCELLED, PIPELINE_STATUS_NEW


class OrderHistoryView(BaseOrderHistoryView):
    def get_queryset(self):
        qs = self.model._default_manager.filter(  # pylint: disable=W0212
            user=self.request.user
        ).exclude(status__in=[PIPELINE_STATUS_CANCELLED, PIPELINE_STATUS_NEW])
        if self.form.is_bound and self.form.is_valid():
            qs = qs.filter(**self.form.get_filters())
        return qs
