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.
127 lines
3.5 KiB
Python
127 lines
3.5 KiB
Python
from django.shortcuts import render, get_object_or_404, redirect
|
|
from osinacore.models import *
|
|
from billing.models import *
|
|
from django.http import JsonResponse, HttpResponse
|
|
from django.template.loader import get_template
|
|
from django.conf import settings
|
|
import os
|
|
from osinacore.decorators import *
|
|
from django.core.files.base import ContentFile
|
|
|
|
|
|
|
|
@staff_login_required
|
|
def add_product(request, *args, **kwargs):
|
|
item_types = ProjectType.objects.all().order_by('name')
|
|
if request.method == 'POST':
|
|
title = request.POST.get('title')
|
|
description = request.POST.get('description')
|
|
|
|
item_type_id = request.POST.get('item_type')
|
|
item_type = get_object_or_404(ProjectType, id=item_type_id)
|
|
|
|
amount = request.POST.get('amount')
|
|
recurring = request.POST.get('recurring')
|
|
|
|
Item.objects.create(
|
|
type='Product',
|
|
title=title,
|
|
description = description,
|
|
item_type = item_type,
|
|
amount = amount,
|
|
recurring = recurring,
|
|
)
|
|
return redirect('items')
|
|
context = {
|
|
'item_types' : item_types,
|
|
|
|
}
|
|
return render(request, 'add_templates/add-product.html', context)
|
|
|
|
|
|
@staff_login_required
|
|
def add_service (request, *args, **kwargs):
|
|
item_types = ProjectType.objects.all().order_by('name')
|
|
customers = CustomerProfile.objects.all().order_by('user__first_name')
|
|
if request.method == 'POST':
|
|
title = request.POST.get('title')
|
|
description = request.POST.get('description')
|
|
|
|
customer_id = request.POST.get('customer')
|
|
customer = get_object_or_404(CustomerProfile, id=customer_id)
|
|
|
|
item_type_id = request.POST.get('item_type')
|
|
item_type = get_object_or_404(ProjectType, id=item_type_id)
|
|
|
|
amount = request.POST.get('amount')
|
|
recurring = request.POST.get('recurring')
|
|
|
|
Item.objects.create(
|
|
type='Service',
|
|
title=title,
|
|
description = description,
|
|
customer = customer,
|
|
item_type = item_type,
|
|
amount = amount,
|
|
recurring = recurring,
|
|
)
|
|
return redirect('items')
|
|
context = {
|
|
'item_types' : item_types,
|
|
'customers' : customers
|
|
}
|
|
return render(request, 'add_templates/add-service.html', context)
|
|
|
|
|
|
@staff_login_required
|
|
def add_order(request, customer_id):
|
|
customer= get_object_or_404(CustomerProfile, id=customer_id)
|
|
businesses = Business.objects.filter(customer=customer)
|
|
|
|
if request.method == 'POST':
|
|
status = request.POST.get('status')
|
|
business_id = request.POST.get('business')
|
|
if business_id:
|
|
business = get_object_or_404(Business, id=business_id)
|
|
else:
|
|
business = None
|
|
|
|
|
|
order = Order.objects.create(
|
|
customer=customer,
|
|
status=status,
|
|
business=business,
|
|
)
|
|
return redirect('orderdetails', order_id=order.id)
|
|
|
|
context = {
|
|
'customer' : customer,
|
|
'businesses' : businesses,
|
|
}
|
|
|
|
return render(request, 'add_templates/add-order.html', context)
|
|
|
|
|
|
|
|
@staff_login_required
|
|
def add_service_in_order(request, service_id, order_id):
|
|
service =get_object_or_404(Item, id=service_id)
|
|
order= get_object_or_404(Order, id=order_id)
|
|
|
|
order_item = OrderItem.objects.create(
|
|
order = order,
|
|
item = service,
|
|
purchased_at = datetime.now()
|
|
)
|
|
order_item.save()
|
|
return redirect('orderdetails', order_id=order.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|