Broad refactor to improve customization of purchase order form etc.

* add dropdown alternative for autocomplete renderer
* auto-enhance some common dropdowns
* refactor new purchase batch, order form view/templates
This commit is contained in:
Lance Edgar 2017-03-24 17:22:12 -05:00
parent e71204dcec
commit d373eb9ac1
9 changed files with 260 additions and 148 deletions

View file

@ -1,40 +1,13 @@
## -*- coding: utf-8 -*-
## -*- coding: utf-8; -*-
<%inherit file="/newbatch/create.mako" />
<%def name="head_tags()">
${parent.head_tags()}
<%def name="extra_javascript()">
${parent.extra_javascript()}
${self.func_show_mode()}
<script type="text/javascript">
function show_mode(mode) {
if (mode == ${enum.PURCHASE_BATCH_MODE_ORDERING}) {
$('.field-wrapper.store_uuid').show();
$('.field-wrapper.purchase_uuid').hide();
$('.field-wrapper.department_uuid').show();
$('.field-wrapper.buyer_uuid').show();
$('.field-wrapper.date_ordered').show();
$('.field-wrapper.date_received').hide();
$('.field-wrapper.invoice_date').hide();
$('.field-wrapper.invoice_number').hide();
} else if (mode == ${enum.PURCHASE_BATCH_MODE_RECEIVING}) {
$('.field-wrapper.store_uuid').hide();
$('.field-wrapper.purchase_uuid').show();
$('.field-wrapper.department_uuid').hide();
$('.field-wrapper.buyer_uuid').hide();
$('.field-wrapper.date_ordered').hide();
$('.field-wrapper.date_received').show();
$('.field-wrapper.invoice_date').show();
$('.field-wrapper.invoice_number').show();
} else if (mode == ${enum.PURCHASE_BATCH_MODE_COSTING}) {
$('.field-wrapper.store_uuid').hide();
$('.field-wrapper.purchase_uuid').show();
$('.field-wrapper.department_uuid').hide();
$('.field-wrapper.buyer_uuid').hide();
$('.field-wrapper.date_ordered').hide();
$('.field-wrapper.date_received').hide();
$('.field-wrapper.invoice_date').show();
$('.field-wrapper.invoice_number').show();
}
}
var purchases_field = '${purchases_field}';
var purchases = null; // TODO: where is this used?
function vendor_selected(uuid, name) {
var mode = $('.mode select').val();
@ -78,9 +51,6 @@
}
});
$('.field-wrapper.purchase_uuid select').selectmenu();
$('.field-wrapper.department_uuid select').selectmenu();
show_mode(${form.fieldset.model.mode or enum.PURCHASE_BATCH_MODE_ORDERING});
});
@ -88,4 +58,42 @@
</script>
</%def>
<%def name="func_show_mode()">
<script type="text/javascript">
function show_mode(mode) {
if (mode == ${enum.PURCHASE_BATCH_MODE_ORDERING}) {
$('.field-wrapper.store_uuid').show();
$('.field-wrapper.' + purchases_field).hide();
$('.field-wrapper.department_uuid').show();
$('.field-wrapper.buyer_uuid').show();
$('.field-wrapper.date_ordered').show();
$('.field-wrapper.date_received').hide();
$('.field-wrapper.po_number').show();
$('.field-wrapper.invoice_date').hide();
$('.field-wrapper.invoice_number').hide();
} else if (mode == ${enum.PURCHASE_BATCH_MODE_RECEIVING}) {
$('.field-wrapper.store_uuid').hide();
$('.field-wrapper.purchase_uuid').show();
$('.field-wrapper.department_uuid').hide();
$('.field-wrapper.buyer_uuid').hide();
$('.field-wrapper.date_ordered').hide();
$('.field-wrapper.date_received').show();
$('.field-wrapper.invoice_date').show();
$('.field-wrapper.invoice_number').show();
} else if (mode == ${enum.PURCHASE_BATCH_MODE_COSTING}) {
$('.field-wrapper.store_uuid').hide();
$('.field-wrapper.purchase_uuid').show();
$('.field-wrapper.department_uuid').hide();
$('.field-wrapper.buyer_uuid').hide();
$('.field-wrapper.date_ordered').hide();
$('.field-wrapper.date_received').hide();
$('.field-wrapper.invoice_date').show();
$('.field-wrapper.invoice_number').show();
}
}
</script>
</%def>
${parent.body()}

View file

@ -3,8 +3,8 @@
<%def name="title()">Purchase Order Form</%def>
<%def name="head_tags()">
${parent.head_tags()}
<%def name="extra_javascript()">
${parent.extra_javascript()}
${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))}
<script type="text/javascript">
$(function() {
@ -25,7 +25,7 @@
} else {
row.find('input[name^="cases_ordered_"]').val(data.row_cases_ordered);
row.find('input[name^="units_ordered_"]').val(data.row_units_ordered);
row.find('td:eq(15)').html(data.row_po_total);
row.find('td.po-total').html(data.row_po_total);
$('.po-total .field').html(data.batch_po_total);
}
});
@ -93,11 +93,14 @@
</%def>
##############################
## page body
##############################
<ul id="context-menu">
${self.context_menu_items()}
</ul>
<div class="form-wrapper">
<div class="field-wrapper">
@ -134,93 +137,7 @@
</div><!-- form-wrapper -->
<div class="newgrid">
<table class="order-form">
<% column_count = 16 + int(capture(self.extra_count)) %>
% for department in sorted(departments.itervalues(), key=lambda d: d.name if d else ''):
<thead>
<tr>
<th class="department" colspan="${column_count}">Department ${department.number} ${department.name}</th>
</tr>
% for subdepartment in sorted(department._order_subdepartments.itervalues(), key=lambda s: s.name if s else ''):
<tr>
<th class="subdepartment" colspan="${column_count}">Subdepartment ${subdepartment.number} ${subdepartment.name}</th>
</tr>
<tr>
<th>UPC</th>
<th>Brand</th>
<th>Description</th>
<th>Case</th>
<th>Vend. Code</th>
<th>Pref.</th>
<th>Unit Cost</th>
% for data in history:
<th>
% if data:
% if data['purchase']['date_received']:
Rec.<br />
${data['purchase']['date_received'].strftime('%m/%d')}
% elif data['purchase']['date_ordered']:
Ord.<br />
${data['purchase']['date_ordered'].strftime('%m/%d')}
% else:
??
% endif
% endif
</th>
% endfor
<th>
${batch.date_ordered.strftime('%m/%d')}<br />
Cases
</th>
<th>
${batch.date_ordered.strftime('%m/%d')}<br />
Units
</th>
<th>PO Total</th>
${self.extra_th()}
</tr>
</thead>
<tbody>
% for cost in subdepartment._order_costs:
<tr data-uuid="${cost.product_uuid}">
<td class="upc">${get_upc(cost.product)}</td>
<td class="brand">${cost.product.brand or ''}</td>
<td class="desc">${cost.product.description} ${cost.product.size or ''}</td>
<td class="case-qty">${h.pretty_quantity(cost.case_size)} ${"LB" if cost.product.weighed else "EA"}</td>
<td class="code">${cost.code or ''}</td>
<td class="preferred">${'X' if cost.preference == 1 else ''}</td>
<td class="unit-cost">$${'{:0.2f}'.format(cost.unit_cost)}</td>
% for data in history:
<td class="scratch_pad">
% if data:
<% item = data['items'].get(cost.product_uuid) %>
% if item:
% if item['cases_received'] is not None or item['units_received'] is not None:
${'{} / {}'.format(int(item['cases_received'] or 0), int(item['units_received'] or 0))}
% elif item['cases_ordered'] is not None or item['units_ordered'] is not None:
${'{} / {}'.format(int(item['cases_ordered'] or 0), int(item['units_ordered'] or 0))}
% endif
% endif
% endif
</td>
% endfor
<td class="current-order">
${h.text('cases_ordered_{}'.format(cost.uuid), value=int(cost._batchrow.cases_ordered or 0) if cost._batchrow else None)}
</td>
<td class="current-order">
${h.text('units_ordered_{}'.format(cost.uuid), value=int(cost._batchrow.units_ordered or 0) if cost._batchrow else None)}
</td>
<td class="po-total">${'${:0,.2f}'.format(cost._batchrow.po_total) if cost._batchrow else ''}</td>
${self.extra_td(cost)}
</tr>
% endfor
</tbody>
% endfor
% endfor
</table>
</div>
${self.order_form_grid()}
${h.form(url('purchases.batch.order_form_update', uuid=batch.uuid), id='item-update-form', style='display: none;')}
${h.csrf_token(request)}
@ -230,6 +147,10 @@ ${h.hidden('units_ordered')}
${h.end_form()}
##############################
## methods
##############################
<%def name="extra_vendor_fields()"></%def>
<%def name="extra_count()">0</%def>
@ -237,3 +158,116 @@ ${h.end_form()}
<%def name="extra_th()"></%def>
<%def name="extra_td(cost)"></%def>
<%def name="order_form_grid()">
<div class="newgrid">
<table class="order-form">
<% column_count = 8 + len(header_columns) + (0 if ignore_cases else 1) + int(capture(self.extra_count)) %>
% for department in sorted(departments.values(), key=lambda d: d.name if d else ''):
<thead>
<tr>
<th class="department" colspan="${column_count}">Department
% if department.number or department.name:
${department.number} ${department.name}
% else:
(N/A)
% endif
</th>
</tr>
% for subdepartment in sorted(department._order_subdepartments.values(), key=lambda s: s.name if s else ''):
<tr>
<th class="subdepartment" colspan="${column_count}">Subdepartment
% if subdepartment.number or subdepartment.name:
${subdepartment.number} ${subdepartment.name}
% else:
(N/A)
% endif
</th>
</tr>
<tr>
% for title in header_columns:
<th>${title}</th>
% endfor
% for data in history:
<th>
% if data:
% if data['purchase']['date_received']:
Rec.<br />
${data['purchase']['date_received'].strftime('%m/%d')}
% elif data['purchase']['date_ordered']:
Ord.<br />
${data['purchase']['date_ordered'].strftime('%m/%d')}
% else:
??
% endif
% endif
</th>
% endfor
% if not ignore_cases:
<th>
${batch.date_ordered.strftime('%m/%d')}<br />
Cases
</th>
% endif
<th>
${batch.date_ordered.strftime('%m/%d')}<br />
Units
</th>
<th>PO Total</th>
${self.extra_th()}
</tr>
</thead>
<tbody>
% for cost in subdepartment._order_costs:
<tr data-uuid="${cost.product_uuid}">
${self.order_form_row(cost)}
% for data in history:
<td class="scratch_pad">
% if data:
<% item = data['items'].get(cost.product_uuid) %>
% if item:
% if ignore_cases:
% if item['units_received'] is not None:
${int(item['units_received'] or 0)}
% elif item['units_ordered'] is not None:
${int(item['units_ordered'] or 0)}
% endif
% else:
% if item['cases_received'] is not None or item['units_received'] is not None:
${'{} / {}'.format(int(item['cases_received'] or 0), int(item['units_received'] or 0))}
% elif item['cases_ordered'] is not None or item['units_ordered'] is not None:
${'{} / {}'.format(int(item['cases_ordered'] or 0), int(item['units_ordered'] or 0))}
% endif
% endif
% endif
% endif
</td>
% endfor
% if not ignore_cases:
<td class="current-order">
${h.text('cases_ordered_{}'.format(cost.uuid), value=int(cost._batchrow.cases_ordered or 0) if cost._batchrow else None)}
</td>
% endif
<td class="current-order">
${h.text('units_ordered_{}'.format(cost.uuid), value=int(cost._batchrow.units_ordered or 0) if cost._batchrow else None)}
</td>
<td class="po-total">${'${:0,.2f}'.format(cost._batchrow.po_total) if cost._batchrow else ''}</td>
${self.extra_td(cost)}
</tr>
% endfor
</tbody>
% endfor
% endfor
</table>
</div>
</%def>
<%def name="order_form_row(cost)">
<td class="upc">${get_upc(cost.product)}</td>
<td class="brand">${cost.product.brand or ''}</td>
<td class="desc">${cost.product.description} ${cost.product.size or ''}</td>
<td class="case-qty">${h.pretty_quantity(cost.case_size)} ${"LB" if cost.product.weighed else "EA"}</td>
<td class="code">${cost.code or ''}</td>
<td class="preferred">${'X' if cost.preference == 1 else ''}</td>
<td class="unit-cost">$${'{:0.2f}'.format(cost.unit_cost)}</td>
</%def>