Refactor ordering worksheet to use shared logic

This commit is contained in:
Lance Edgar 2018-02-19 18:19:19 -06:00
parent b529a005d8
commit 1b059c5293
4 changed files with 12 additions and 28 deletions

View file

@ -6,8 +6,8 @@
<script type="text/javascript">
$(function() {
$('#order-form').click(function() {
% if vendor_cost_count > vendor_cost_threshold:
$('.load-worksheet').click(function() {
% if vendor_cost_count is not Undefined and vendor_cost_threshold is not Undefined and vendor_cost_count > vendor_cost_threshold:
if (! confirm("This vendor has ${'{:,d}'.format(vendor_cost_count)} cost records.\n\n" +
"It is not recommended to use Order Form mode for such a large catalog.\n\n" +
"Are you sure you wish to do it anyway?")) {
@ -15,7 +15,7 @@
}
% endif
$(this).button('disable').button('option', 'label', "Working, please wait...");
location.href = '${url('ordering.order_form', uuid=batch.uuid)}';
location.href = '${url('ordering.worksheet', uuid=batch.uuid)}';
});
});
@ -34,10 +34,4 @@
% endif
</%def>
<%def name="leading_buttons()">
% if not batch.complete and not batch.executed and request.has_perm('ordering.order_form'):
<button type="button" id="order-form">Edit as Worksheet</button>
% endif
</%def>
${parent.body()}

View file

@ -158,7 +158,7 @@
${self.order_form_grid()}
${h.form(url('ordering.order_form_update', uuid=batch.uuid), id='item-update-form', style='display: none;')}
${h.form(url('ordering.worksheet_update', uuid=batch.uuid), id='item-update-form', style='display: none;')}
${h.csrf_token(request)}
${h.hidden('product_uuid')}
${h.hidden('cases_ordered')}

View file

@ -245,7 +245,7 @@ class PurchaseView(MasterView):
url = self.request.route_url(routes[batch.mode], uuid=batch.uuid)
return tags.link_to(text, url)
items = [HTML.tag('li', c=render(batch)) for batch in batches]
items = [HTML.tag('li', c=[render(batch)]) for batch in batches]
return HTML.tag('ul', c=items)
def delete_instance(self, purchase):

View file

@ -53,6 +53,7 @@ class OrderingBatchView(PurchasingBatchView):
mobile_creatable = True
rows_editable = True
mobile_rows_editable = True
has_worksheet = True
mobile_form_fields = [
'vendor',
@ -106,9 +107,9 @@ class OrderingBatchView(PurchasingBatchView):
# purchase
f.remove_field('purchase')
def order_form(self):
def worksheet(self):
"""
View for editing batch row data as an order form.
View for editing batch row data as an order form worksheet.
"""
batch = self.get_instance()
if batch.executed:
@ -116,9 +117,8 @@ class OrderingBatchView(PurchasingBatchView):
# organize existing batch rows by product
order_items = {}
for row in batch.data_rows:
if not row.removed:
order_items[row.product_uuid] = row
for row in batch.active_rows():
order_items[row.product_uuid] = row
# organize vendor catalog costs by dept / subdept
departments = {}
@ -164,7 +164,7 @@ class OrderingBatchView(PurchasingBatchView):
history = list(reversed(history))
title = self.get_instance_title(batch)
return self.render_to_response('order_form', {
return self.render_to_response('worksheet', {
'batch': batch,
'instance': batch,
'instance_title': title,
@ -212,7 +212,7 @@ class OrderingBatchView(PurchasingBatchView):
def decorate_order_form_cost(self, cost):
pass
def order_form_update(self):
def worksheet_update(self):
"""
Handles AJAX requests to update current batch, from Order Form view.
"""
@ -354,16 +354,6 @@ class OrderingBatchView(PurchasingBatchView):
cls._batch_defaults(config)
cls._defaults(config)
# ordering form
config.add_tailbone_permission(permission_prefix, '{}.order_form'.format(permission_prefix),
"Edit {} data as worksheet".format(model_title))
config.add_route('{}.order_form'.format(route_prefix), '{}/{{{}}}/order-form'.format(url_prefix, model_key))
config.add_view(cls, attr='order_form', route_name='{}.order_form'.format(route_prefix),
permission='{}.order_form'.format(permission_prefix))
config.add_route('{}.order_form_update'.format(route_prefix), '{}/{{{}}}/order-form/update'.format(url_prefix, model_key))
config.add_view(cls, attr='order_form_update', route_name='{}.order_form_update'.format(route_prefix),
renderer='json', permission='{}.order_form'.format(permission_prefix))
# download as Excel
config.add_route('{}.download_excel'.format(route_prefix), '{}/{{uuid}}/excel'.format(url_prefix))
config.add_view(cls, attr='download_excel', route_name='{}.download_excel'.format(route_prefix),