Browse Source

added new order splash screen

php2python
Holger Frey 7 years ago
parent
commit
59bc6a8f6c
  1. 5
      ordr2/schemas/orders.py
  2. 69
      ordr2/templates/orders/splash.jinja2
  3. 104
      ordr2/views/orders.py

5
ordr2/schemas/orders.py

@ -162,6 +162,11 @@ class EditOrderSchema(CSRFSchema): @@ -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',

69
ordr2/templates/orders/splash.jinja2

@ -0,0 +1,69 @@ @@ -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 %}
<div class="content controls">
<div class="container-fluid">
<div class="page-controls">
<h1>Place an Order</h1>
</div>
<div class="row">
<div class="span10">
<div class="alert alert-block alert-info">
<h3 class="alert-heading">You can choose from a number of options to place a new order.</h3>
<ol>
<li>Place a custom order (empty, not prepopulated order form)</li>
<li>Use the search field to find a consumable and use a prepopulated order form.</li>
<li>Choose one of the consumables from a list to use a prepopulated order form.</li>
</ol>
</div>
{{ macros.flash_messages() }}
<div class="bordered">
<form action="{{ request.resource_url(context, 'splash')}}" method="POST" class="form-inline right" autocomplete="off">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
<input type="search" data-provide="typeahead" data-source='{{ consumable_names|tojson }}' placeholder="Search Consumables" size="50" name="search">
<button class="btn" type="submit" name="search_consumable">Create Order</button>
</form>
<a class="btn" href="{{ request.resource_url(context, 'new') }}">Place a custom order</a>
</div>
<div id="common-consumables-accordion" class="accordion">
{% for category, items in consumables.items() %}
<div class="accordion-group">
<div class="accordion-heading">
<a href="#{{ category.name }}" data-parent="#common-consumables-accordion" data-toggle="collapse">
{{ category.value|capitalize }}
</a>
</div>
<div class="accordion-body collapse" id="{{ category.name }}">
<div class="accordion-inner">
<ul class="unstyled">
{% for item in items %}
<li><a href="{{ request.resource_url(context, 'new', query={'consumable': item.id}) }}">{{ item.cas_description }}</a> <span>({{ item.package_size }})</span></li>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
{% endblock content %}

104
ordr2/views/orders.py

@ -1,13 +1,14 @@ @@ -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): @@ -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): @@ -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',