diff --git a/ordr2/schemas/orders.py b/ordr2/schemas/orders.py
index d56050c..a826d08 100644
--- a/ordr2/schemas/orders.py
+++ b/ordr2/schemas/orders.py
@@ -162,6 +162,11 @@ class EditOrderSchema(CSRFSchema):
settings = {
'buttons': (
deform.Button(name='save', title='Edit Order'),
+ deform.Button(
+ name='reorder',
+ title='Reorder',
+ css_class='btn-success'
+ ),
deform.Button(
name='delete',
title='Delete Order',
diff --git a/ordr2/templates/orders/splash.jinja2 b/ordr2/templates/orders/splash.jinja2
new file mode 100644
index 0000000..27d6414
--- /dev/null
+++ b/ordr2/templates/orders/splash.jinja2
@@ -0,0 +1,69 @@
+{% extends "ordr2:templates/layout.jinja2" %}
+{% import 'ordr2:templates/macros.jinja2' as macros with context %}
+
+{% block subtitle %} Order | Place Order {% endblock subtitle %}
+
+{% block content %}
+
+
+
+
+
+
Place an Order
+
+
+
+
+
+
+
You can choose from a number of options to place a new order.
+
+ - Place a custom order (empty, not prepopulated order form)
+ - Use the search field to find a consumable and use a prepopulated order form.
+ - Choose one of the consumables from a list to use a prepopulated order form.
+
+
+
+ {{ macros.flash_messages() }}
+
+
+
+
+
+ {% for category, items in consumables.items() %}
+
+ {% endfor %}
+
+
+
+
+
+
+
+{% endblock content %}
+
+
+
diff --git a/ordr2/views/orders.py b/ordr2/views/orders.py
index c5b61b8..43bf4e6 100644
--- a/ordr2/views/orders.py
+++ b/ordr2/views/orders.py
@@ -1,13 +1,14 @@
import deform
from datetime import datetime
+from collections import OrderedDict
from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render
from pyramid.view import view_config
from ordr2.events import OrderStatusChange
-from ordr2.models import Category, Order, OrderStatus, User
+from ordr2.models import Category, Consumable, Order, OrderStatus, User
from ordr2.schemas.orders import NewOrderSchema, EditOrderSchema
from . import update_column_display
@@ -284,6 +285,15 @@ def order_edit_form_processing(context, request):
elif 'delete' in request.POST and context.model:
return HTTPFound(request.resource_url(context, 'delete'))
+ elif 'reorder' in request.POST and context.model:
+ return HTTPFound(
+ request.resource_url(
+ context.__parent__,
+ 'new',
+ query={'reorder': context.model.id}
+ )
+ )
+
return HTTPFound(context.__parent__.url())
@@ -296,9 +306,101 @@ def order_edit_form_processing(context, request):
)
def order_new_form(context, request):
form = NewOrderSchema.as_form(request)
+
+ consumable_id = request.GET.get('consumable', None)
+ order_id = request.GET.get('reorder', None)
+ prefill = None
+
+ if order_id:
+ prefill = request.dbsession.query(Order).get(order_id)
+ elif consumable_id:
+ prefill = request.dbsession.query(Consumable).get(consumable_id)
+
+ if prefill:
+ 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 ''
+ item = {
+ 'cas_description': prefill.cas_description,
+ 'category': prefill.category.name,
+ 'vendor': prefill.vendor,
+ 'catalog_nr': prefill.catalog_nr,
+ 'package_size': prefill.package_size
+ }
+ pricing = {
+ 'unit_price': {
+ 'amount': '%.2f' % prefill.unit_price,
+ 'currency': prefill.currency
+ },
+ 'quantity': quantity,
+ 'total_price': {
+ 'amount': '%.2f' % total_price,
+ 'currency': prefill.currency
+ },
+ }
+ optional = {
+ 'account': account,
+ 'comment': prefill.comment
+ }
+
+ form_data = {
+ 'item_information': item,
+ 'pricing': pricing,
+ 'optional_information': optional
+ }
+ form.set_appstruct(form_data)
+
return {'form': form}
+@view_config(
+ context='ordr2:resources.OrderList',
+ name='splash',
+ permission='create',
+ request_method='GET',
+ renderer='ordr2:templates/orders/splash.jinja2'
+ )
+def order_splash(context, request):
+ structured = OrderedDict()
+ for cat in Category:
+ structured[cat] = []
+ available = request.dbsession.\
+ query(Consumable).\
+ order_by(Consumable.cas_description).\
+ all()
+ names = []
+ for consumable in available:
+ names.append(consumable.cas_description)
+ structured[consumable.category].append(consumable)
+ return {'consumable_names': names, 'consumables': structured}
+
+
+@view_config(
+ context='ordr2:resources.OrderList',
+ name='splash',
+ permission='create',
+ request_method='POST',
+ renderer='ordr2:templates/orders/splash.jinja2'
+ )
+def order_splash_processing(context, request):
+ name = request.POST.get('search')
+ consumable = request.dbsession.\
+ query(Consumable).\
+ filter_by(cas_description=name).\
+ first()
+ if consumable:
+ return HTTPFound(
+ request.resource_url(
+ context,
+ 'new',
+ query={'consumable': consumable.id}
+ )
+ )
+
+ request.flash('error', 'No consumable selected')
+ return HTTPFound(request.resource_url(context, 'splash'))
+
+
@view_config(
context='ordr2:resources.OrderList',
name='new',