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