|
|
|
@ -1,9 +1,11 @@
@@ -1,9 +1,11 @@
|
|
|
|
|
''' views for creating and editing orders ''' |
|
|
|
|
|
|
|
|
|
import deform |
|
|
|
|
import io |
|
|
|
|
import xlsxwriter |
|
|
|
|
|
|
|
|
|
from datetime import datetime |
|
|
|
|
from collections import OrderedDict |
|
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
from pyramid.httpexceptions import HTTPFound |
|
|
|
|
from pyramid.renderers import render |
|
|
|
@ -20,6 +22,7 @@ from . import update_column_display
@@ -20,6 +22,7 @@ from . import update_column_display
|
|
|
|
|
# helper method |
|
|
|
|
|
|
|
|
|
def change_in_order_status(request, order, old): |
|
|
|
|
''' notifies a user if a noteworthy change in a order occured ''' |
|
|
|
|
noteworthy = False |
|
|
|
|
if old != OrderStatus.ORDERED and order.status == OrderStatus.ORDERED: |
|
|
|
|
noteworthy = True |
|
|
|
@ -35,7 +38,7 @@ def change_in_order_status(request, order, old):
@@ -35,7 +38,7 @@ def change_in_order_status(request, order, old):
|
|
|
|
|
request.registry.notify(event) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# oder list and multiple editing |
|
|
|
|
# oder list |
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context='ordr2:resources.OrderList', |
|
|
|
@ -70,7 +73,9 @@ def change_column_view(context, request):
@@ -70,7 +73,9 @@ def change_column_view(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/edit_multiple_stati.jinja2' |
|
|
|
|
) |
|
|
|
|
def download_view(context, request): |
|
|
|
|
''' see https://xlsxwriter.readthedocs.io/example_http_server3.html ''' |
|
|
|
|
''' downloads the displayed order list as an excel file |
|
|
|
|
|
|
|
|
|
see https://xlsxwriter.readthedocs.io/example_http_server3.html ''' |
|
|
|
|
# Create an in-memory output file for the new workbook. |
|
|
|
|
output = io.BytesIO() |
|
|
|
|
# Even though the final file will be in memory the module uses temp |
|
|
|
@ -134,6 +139,7 @@ def download_view(context, request):
@@ -134,6 +139,7 @@ def download_view(context, request):
|
|
|
|
|
request_method='POST' |
|
|
|
|
) |
|
|
|
|
def search(context, request): |
|
|
|
|
''' process the search order form ''' |
|
|
|
|
term = request.POST.get('search', '') |
|
|
|
|
term = term.strip() |
|
|
|
|
if term: |
|
|
|
@ -150,6 +156,7 @@ def search(context, request):
@@ -150,6 +156,7 @@ def search(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/edit_multiple_stati.jinja2' |
|
|
|
|
) |
|
|
|
|
def edit_multiple_stati_form(context, request): |
|
|
|
|
''' form for editing the stati of multiple orders ''' |
|
|
|
|
order_ids = [v for k, v in request.POST.items() if k == 'marked'] |
|
|
|
|
orders = request.dbsession.\ |
|
|
|
|
query(Order).\ |
|
|
|
@ -169,6 +176,7 @@ def edit_multiple_stati_form(context, request):
@@ -169,6 +176,7 @@ def edit_multiple_stati_form(context, request):
|
|
|
|
|
request_method='POST' |
|
|
|
|
) |
|
|
|
|
def edit_multiple_stati_form_processing(context, request): |
|
|
|
|
''' change the stati of multiple orders ''' |
|
|
|
|
|
|
|
|
|
if 'change' in request.POST: |
|
|
|
|
count = 0 |
|
|
|
@ -205,6 +213,7 @@ def edit_multiple_stati_form_processing(context, request):
@@ -205,6 +213,7 @@ def edit_multiple_stati_form_processing(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/delete.jinja2' |
|
|
|
|
) |
|
|
|
|
def delete_multiple_orders_form(context, request): |
|
|
|
|
''' show confirmation page for deleting multiple orders ''' |
|
|
|
|
order_ids = [v for k, v in request.POST.items() if k == 'marked'] |
|
|
|
|
orders = request.dbsession.\ |
|
|
|
|
query(Order).\ |
|
|
|
@ -229,6 +238,7 @@ def delete_multiple_orders_form(context, request):
@@ -229,6 +238,7 @@ def delete_multiple_orders_form(context, request):
|
|
|
|
|
request_method='POST' |
|
|
|
|
) |
|
|
|
|
def order_delete_form_processing(context, request): |
|
|
|
|
''' delete one or multiple orders after confirmation ''' |
|
|
|
|
if 'delete' in request.POST: |
|
|
|
|
order_ids = [v for k, v in request.POST.items() if k == 'order'] |
|
|
|
|
orders = request.dbsession.\ |
|
|
|
@ -247,7 +257,7 @@ def order_delete_form_processing(context, request):
@@ -247,7 +257,7 @@ def order_delete_form_processing(context, request):
|
|
|
|
|
return HTTPFound(request.resource_url(request.root, 'orders')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# single order processing |
|
|
|
|
# Single Order views |
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context='ordr2:resources.OrderResource', |
|
|
|
@ -256,8 +266,10 @@ def order_delete_form_processing(context, request):
@@ -256,8 +266,10 @@ def order_delete_form_processing(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/view.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_view(context, request): |
|
|
|
|
''' show the order information ''' |
|
|
|
|
return {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
context='ordr2:resources.OrderResource', |
|
|
|
|
name='delete', |
|
|
|
@ -266,6 +278,7 @@ def order_view(context, request):
@@ -266,6 +278,7 @@ def order_view(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/delete.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_delete_form(context, request): |
|
|
|
|
''' show the confirmation page for deleting one order ''' |
|
|
|
|
return {'orders': [context.model]} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -277,6 +290,7 @@ def order_delete_form(context, request):
@@ -277,6 +290,7 @@ def order_delete_form(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/edit.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_edit_form(context, request): |
|
|
|
|
''' show the edit order form ''' |
|
|
|
|
form = EditOrderSchema.as_form(request) |
|
|
|
|
order = context.model |
|
|
|
|
info = { |
|
|
|
@ -323,7 +337,7 @@ def order_edit_form(context, request):
@@ -323,7 +337,7 @@ def order_edit_form(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/edit.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_edit_form_processing(context, request): |
|
|
|
|
''' process the consumable edit form ''' |
|
|
|
|
''' process the edit order form ''' |
|
|
|
|
|
|
|
|
|
form = EditOrderSchema.as_form(request) |
|
|
|
|
data = request.POST.items() |
|
|
|
@ -375,9 +389,11 @@ def order_edit_form_processing(context, request):
@@ -375,9 +389,11 @@ def order_edit_form_processing(context, request):
|
|
|
|
|
request.flash('success', msg) |
|
|
|
|
|
|
|
|
|
elif 'delete' in request.POST and context.model: |
|
|
|
|
# redirect to delete order confirmation page |
|
|
|
|
return HTTPFound(request.resource_url(context, 'delete')) |
|
|
|
|
|
|
|
|
|
elif 'reorder' in request.POST and context.model: |
|
|
|
|
# redirect to create new order form |
|
|
|
|
return HTTPFound( |
|
|
|
|
request.resource_url( |
|
|
|
|
context.__parent__, |
|
|
|
@ -397,8 +413,11 @@ def order_edit_form_processing(context, request):
@@ -397,8 +413,11 @@ def order_edit_form_processing(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/new.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_new_form(context, request): |
|
|
|
|
''' create a new order ''' |
|
|
|
|
form = NewOrderSchema.as_form(request) |
|
|
|
|
|
|
|
|
|
# check if the form should be prefilled with some data, |
|
|
|
|
# either from selecting a consumable or from reordering an item |
|
|
|
|
consumable_id = request.GET.get('consumable', None) |
|
|
|
|
order_id = request.GET.get('reorder', None) |
|
|
|
|
prefill = None |
|
|
|
@ -408,7 +427,9 @@ def order_new_form(context, request):
@@ -408,7 +427,9 @@ def order_new_form(context, request):
|
|
|
|
|
elif consumable_id: |
|
|
|
|
prefill = request.dbsession.query(Consumable).get(consumable_id) |
|
|
|
|
|
|
|
|
|
# prefill the form data |
|
|
|
|
if prefill: |
|
|
|
|
# some fields depend on if the prefill was a reorder or consumable |
|
|
|
|
quantity = prefill.amount if order_id else 1 |
|
|
|
|
total_price = prefill.total_price if order_id else prefill.unit_price |
|
|
|
|
account = prefill.account if order_id else '' |
|
|
|
@ -453,6 +474,7 @@ def order_new_form(context, request):
@@ -453,6 +474,7 @@ def order_new_form(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/splash.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_splash(context, request): |
|
|
|
|
''' splash screen for a new order where consumables can be selected ''' |
|
|
|
|
structured = OrderedDict() |
|
|
|
|
for cat in Category: |
|
|
|
|
structured[cat] = [] |
|
|
|
@ -475,6 +497,7 @@ def order_splash(context, request):
@@ -475,6 +497,7 @@ def order_splash(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/splash.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_splash_processing(context, request): |
|
|
|
|
''' process the splash screen selection ''' |
|
|
|
|
name = request.POST.get('search') |
|
|
|
|
consumable = request.dbsession.\ |
|
|
|
|
query(Consumable).\ |
|
|
|
@ -501,7 +524,7 @@ def order_splash_processing(context, request):
@@ -501,7 +524,7 @@ def order_splash_processing(context, request):
|
|
|
|
|
renderer='ordr2:templates/orders/new.jinja2' |
|
|
|
|
) |
|
|
|
|
def order_new_form_processing(context, request): |
|
|
|
|
''' process the consumable edit form ''' |
|
|
|
|
''' process the new order form ''' |
|
|
|
|
|
|
|
|
|
form = NewOrderSchema.as_form(request) |
|
|
|
|
data = request.POST.items() |
|
|
|
@ -543,10 +566,3 @@ def order_new_form_processing(context, request):
@@ -543,10 +566,3 @@ def order_new_form_processing(context, request):
|
|
|
|
|
|
|
|
|
|
return HTTPFound(context.url()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|