diff --git a/order/filters.py b/order/filters.py new file mode 100644 index 0000000..12d04cc --- /dev/null +++ b/order/filters.py @@ -0,0 +1,17 @@ +from django import forms + +import django_filters + +from order.models import Order + + +class OrderFilter(django_filters.FilterSet): + created_time = django_filters.DateFilter( + widget=forms.DateInput(attrs={'class': 'form-control', 'type': 'date', 'data-date-format': 'YYYY-MMMM-DD '}), + lookup_expr='contains' + ) + + status = django_filters.ChoiceFilter( + choices=Order.STATUS, + widget=forms.Select(attrs={'class': 'form-control'}) + ) \ No newline at end of file diff --git a/order/migrations/0003_alter_order_status.py b/order/migrations/0003_alter_order_status.py new file mode 100644 index 0000000..cf7f259 --- /dev/null +++ b/order/migrations/0003_alter_order_status.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2 on 2021-09-15 09:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('order', '0002_auto_20210913_1544'), + ] + + operations = [ + migrations.AlterField( + model_name='order', + name='status', + field=models.PositiveSmallIntegerField(choices=[(0, 'preparing food'), (1, 'sending')], default=0, verbose_name='status'), + ), + ] diff --git a/order/templates/order/service/order_detail.html b/order/templates/order/service/order_detail.html new file mode 100644 index 0000000..1536d92 --- /dev/null +++ b/order/templates/order/service/order_detail.html @@ -0,0 +1,55 @@ +{% extends 'base.html' %} +{% block title %}Order Detail{% endblock %} +{% block content %} + +
+
+
+
+

id : {{ order.id }}

+

status : {{ order.get_status_display }}

+

date time : {{ order.created_time }}

+

total price : {{ order.invoice.price }}$

+
+
+ +
+

Lines:

+
+
+
+

+ Item +

+
+
+

+ Quantity +

+
+
+ {% for cartline in order.invoice.cart.lines.all %} +
+
+
+

+ {{ cartline.item }} +

+
+
+

+ {{ cartline.quantity }} +

+
+
+
+ {% endfor %} +
+
+ Change + Status + +
+
+{% endblock %} \ No newline at end of file diff --git a/order/templates/order/service/order_filter_list.html b/order/templates/order/service/order_filter_list.html new file mode 100644 index 0000000..6701b03 --- /dev/null +++ b/order/templates/order/service/order_filter_list.html @@ -0,0 +1,34 @@ +{% extends 'base.html' %} +{% block title %}Payment Verification{% endblock %} +{% block content %} + +
+
+
+ {{ filter.form.as_p }} + +
+
+
+ {% for order in orders %} +
+
+
+
+

id : {{ order.id }}

+

status : {{ order.get_status_display }}

+

date time : {{ order.created_time }}

+

total price : {{ order.invoice.price }}$

+
+
+
+ Show Factor +
+
+
+ {% endfor %} +
+
+ +{% endblock %} diff --git a/order/templates/order/service/order_list.html b/order/templates/order/service/order_list.html new file mode 100644 index 0000000..b603793 --- /dev/null +++ b/order/templates/order/service/order_list.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} +{% block title %}Payment Verification{% endblock %} +{% block content %} +
Today: {% now "Y-m-d" %}
+
+ {% for order in orders %} +
+
+
+
+

id : {{ order.id }}

+

status : {{ order.get_status_display }}

+

date time : {{ order.created_time }}

+

total price : {{ order.invoice.price }}$

+
+
+
+ Show Factor +
+
+
+ {% endfor %} +
+ +{% endblock %} \ No newline at end of file diff --git a/order/templates/order/service/order_update.html b/order/templates/order/service/order_update.html new file mode 100644 index 0000000..2d4f93e --- /dev/null +++ b/order/templates/order/service/order_update.html @@ -0,0 +1,9 @@ +{% extends 'base.html' %} +{% block content %} +
+ {% csrf_token %} + {{ form.as_p }} + +
+ cancel +{% endblock %} diff --git a/order/urls.py b/order/urls.py index 388aeb3..f1a4e3e 100644 --- a/order/urls.py +++ b/order/urls.py @@ -1,10 +1,16 @@ from django.urls import path +from order.views import OrderServiceListView, OrderServiceDetailView, OrderServiceUpdateView, OrderServiceListFilterView from order.views import CustomerOrdersListView, CustomerOrderDetailView app_name = 'order' urlpatterns = [ + path('service/list//', OrderServiceListFilterView.as_view(), name='service-order-list'), + path('service/today//', OrderServiceListView.as_view(), name='service-order-today'), + path('service/detail//', OrderServiceDetailView.as_view(), name='service-order-detail'), + path('service/update//', OrderServiceUpdateView.as_view(), name='service-order-update'), + path('customer/list/', CustomerOrdersListView.as_view(), name='customer-list'), path('customer//detail/', CustomerOrderDetailView.as_view(), name='customer-detail'), ] \ No newline at end of file diff --git a/order/views.py b/order/views.py index ce96eb8..5bde7ff 100644 --- a/order/views.py +++ b/order/views.py @@ -1,13 +1,102 @@ +from abc import ABC + from django.contrib.auth.decorators import login_required +from django.http import HttpResponseForbidden +from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy +from django.utils import timezone from django.utils.decorators import method_decorator from django.views.decorators.http import require_http_methods -from django.views.generic import ListView, DetailView +from django.views.generic import ListView, DetailView, UpdateView + +from django_filters.views import FilterView + +from order.filters import OrderFilter +from order.models import Order +from service.models import Service + +from library.utils import CustomUserPasses from accounts.models import Customer from accounts.utils import IsCustomer -from library.utils import CustomUserPasses -from order.models import Order + + + +class BaseOrderServiceList(CustomUserPasses): + model = Order + + def test_func(self): + if self.service.service_provider != self.request.user: + return False + return True + + +class BaseOrderDetailUpdate(CustomUserPasses): + model = Order + + def test_func(self): + order = self.get_object() + if order.invoice.cart.service.service_provider != self.request.user: + return False + return True + + +@method_decorator(require_http_methods(['GET']), name='dispatch') +@method_decorator(login_required(login_url=reverse_lazy('accounts:service-provider-login')), name='dispatch') +class OrderServiceListFilterView(FilterView): + context_object_name = 'orders' + filterset_class = OrderFilter + template_name = 'order/service/order_filter_list.html' + + def dispatch(self, request, *args, **kwargs): + self.service = get_object_or_404(Service, pk=self.kwargs.get('service_pk', None)) + if self.service.service_provider != self.request.user: + return HttpResponseForbidden() + return super().dispatch(request, *args, **kwargs) + + def get_queryset(self): + return Order.objects.filter(invoice__cart__service=self.service) + + +@method_decorator(require_http_methods(['GET']), name='dispatch') +@method_decorator(login_required(login_url=reverse_lazy('accounts:service-provider-login')), name='dispatch') +class OrderServiceListView(BaseOrderServiceList, ListView): + context_object_name = 'orders' + template_name = 'order/service/order_list.html' + + def dispatch(self, request, *args, **kwargs): + self.service = get_object_or_404(Service, pk=self.kwargs.get('service_pk', None)) + return super().dispatch(request, *args, **kwargs) + + def get_queryset(self): + today = timezone.now() + time_filter = dict( + created_time__day=today.strftime('%d'), + created_time__month=today.strftime('%m'), + created_time__year=today.strftime('%Y') + ) + return Order.objects.exclude(is_delivered=True).filter(invoice__cart__service=self.service, **time_filter) + + +@method_decorator(require_http_methods(['GET']), name='dispatch') +@method_decorator(login_required(login_url=reverse_lazy('accounts:service-provider-login')), name='dispatch') +class OrderServiceDetailView(BaseOrderDetailUpdate, DetailView): + context_object_name = 'order' + template_name = 'order/service/order_detail.html' + + +@method_decorator(require_http_methods(['GET', 'POST']), name='dispatch') +@method_decorator(login_required(login_url=reverse_lazy('accounts:service-provider-login')), name='dispatch') +class OrderServiceUpdateView(BaseOrderDetailUpdate, UpdateView): + fields = ('status',) + context_object_name = 'order' + template_name = 'order/service/order_update.html' + + def get_success_url(self): + order = self.get_object() + return reverse_lazy('order:service-order-list', kwargs={'service_pk': order.invoice.cart.service.id}) + + @method_decorator(require_http_methods(['GET']), name='dispatch') diff --git a/service/templates/service/service_provider/list.html b/service/templates/service/service_provider/list.html index 64f5075..e62ea8e 100644 --- a/service/templates/service/service_provider/list.html +++ b/service/templates/service/service_provider/list.html @@ -5,15 +5,19 @@