You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
from django.shortcuts import render, get_object_or_404
|
|
from django.utils import timezone
|
|
from datetime import timedelta
|
|
from .models import *
|
|
from django.http import JsonResponse, HttpResponse
|
|
from django.template.loader import get_template
|
|
|
|
|
|
# LISTING
|
|
def items(request, *args, **kwargs):
|
|
products = Item.objects.filter(type='Product').order_by('-id')
|
|
services = Item.objects.filter(type='Service').order_by('-id')
|
|
context = {
|
|
'products': products,
|
|
'services': services,
|
|
|
|
}
|
|
return render(request, 'listing_pages/items.html', context)
|
|
|
|
|
|
def orders(request, *args, **kwargs):
|
|
orders = Order.objects.all().order_by('-id')
|
|
context = {
|
|
'orders': orders,
|
|
}
|
|
return render(request, 'listing_pages/orders.html', context)
|
|
|
|
|
|
def invoices(request, *args, **kwargs):
|
|
invoices = Invoice.objects.all().order_by('-id')
|
|
|
|
context = {
|
|
'invoices': invoices,
|
|
}
|
|
|
|
return render(request, 'listing_pages/invoices.html', context)
|
|
|
|
|
|
#DETAILS
|
|
def invoice_details(request, order_id):
|
|
order = get_object_or_404(Order, id=order_id)
|
|
|
|
context = {
|
|
'order' : order,
|
|
}
|
|
|
|
return render(request, 'details_templates/invoice-details.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
# TO FETCH THE ITEMS RELATED TO TH SELECTED CUSTOMER AND THE ITEMS THAT ARE NOT RELATED TO A CUSTOMER
|
|
def fetch_customer_items(request, customer_id):
|
|
customer = get_object_or_404(CustomerProfile, id=customer_id)
|
|
|
|
items_related_to_customer = Item.objects.filter(customer=customer)
|
|
|
|
items_without_customer = Item.objects.filter(customer__isnull=True)
|
|
|
|
data = {
|
|
'items_related_to_customer': list(items_related_to_customer.values('id', 'title')),
|
|
'items_without_customer': list(items_without_customer.values('id', 'title')),
|
|
}
|
|
|
|
return JsonResponse(data)
|