Refactor the Ordering Worksheet generator, per Buefy

This commit is contained in:
Lance Edgar 2023-02-03 16:08:29 -06:00
parent eddbfcab36
commit 2ebae17839
6 changed files with 121 additions and 82 deletions

View file

@ -24,8 +24,6 @@
App Menus
"""
from __future__ import unicode_literals, absolute_import
import re
import logging
import warnings
@ -527,6 +525,19 @@ class MenuHandler(GenericHandler):
},
])
if kwargs.get('include_worksheets', False):
items.extend([
{'type': 'sep'},
{
'title': "Ordering Worksheet",
'route': 'reports.ordering',
},
{
'title': "Inventory Worksheet",
'route': 'reports.inventory',
},
])
if kwargs.get('include_trainwreck', False):
items.extend([
{'type': 'sep'},

View file

@ -111,7 +111,7 @@
<td class="brand">${cost.product.brand or ''}</td>
<td class="desc">${cost.product.description}</td>
<td class="size">${cost.product.size or ''}</td>
<td class="case-qty">${cost.case_size} ${"LB" if cost.product.weighed else "EA"}</td>
<td class="case-qty">${app.render_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>
% for i in range(14):

View file

@ -1,4 +0,0 @@
## -*- coding: utf-8; -*-
<%inherit file="/page.mako" />
${parent.body()}

View file

@ -1,7 +1,7 @@
## -*- coding: utf-8 -*-
<%inherit file="/reports/base.mako" />
<%inherit file="/page.mako" />
<%def name="title()">Report : Inventory Worksheet</%def>
<%def name="title()">Inventory Worksheet</%def>
<%def name="page_content()">

View file

@ -1,89 +1,120 @@
## -*- coding: utf-8 -*-
<%inherit file="/reports/base.mako" />
<%inherit file="/page.mako" />
<%def name="title()">Report : Ordering Worksheet</%def>
<%def name="title()">Ordering Worksheet</%def>
<%def name="head_tags()">
${parent.head_tags()}
<style type="text/css">
<%def name="page_content()">
div.grid {
clear: none;
}
<p class="block">
Please provide the following criteria to generate your report:
</p>
<div style="max-width: 50%;">
${h.form(request.current_route_url(), **{'@submit': 'validateForm'})}
${h.csrf_token(request)}
${h.hidden('departments', **{':value': 'departmentUUIDs'})}
<b-field label="Vendor">
<tailbone-autocomplete v-model="vendorUUID"
service-url="${url('vendors.autocomplete')}"
name="vendor"
@input="vendorChanged">
</tailbone-autocomplete>
</b-field>
<b-field label="Departments">
<b-table v-if="fetchedDepartments"
:data="departments"
narrowed
checkable
:checked-rows.sync="checkedDepartments"
:loading="fetchingDepartments">
<b-table-column field="number"
label="Number"
v-slot="props">
{{ props.row.number }}
</b-table-column>
<b-table-column field="name"
label="Name"
v-slot="props">
{{ props.row.name }}
</b-table-column>
</b-table>
</b-field>
<b-field>
<b-checkbox name="preferred_only" :value="true"
native-value="1">
Only include products for which this vendor is preferred.
</b-checkbox>
</b-field>
${self.extra_fields()}
<div class="buttons">
<b-button type="is-primary"
native-type="submit"
icon-pack="fas"
icon-left="arrow-circle-right">
Generate Report
</b-button>
</div>
${h.end_form()}
</div>
</style>
</%def>
<p>Please provide the following criteria to generate your report:</p>
<br />
<%def name="extra_fields()"></%def>
${h.form(request.current_route_url())}
${h.hidden('departments', value='')}
<%def name="modify_this_page_vars()">
${parent.modify_this_page_vars()}
<script type="text/javascript">
<div class="field-wrapper">
${h.hidden('vendor', value='')}
<label for="vendor-name">Vendor:</label>
${h.text('vendor-name', size='40', value='')}
<div id="vendor-display" style="display: none;">
<span>(no vendor)</span>&nbsp;
<button type="button" id="change-vendor">Change</button>
</div>
</div>
ThisPageData.vendorUUID = null
ThisPageData.departments = []
ThisPageData.checkedDepartments = []
ThisPageData.fetchingDepartments = false
ThisPageData.fetchedDepartments = false
<div class="field-wrapper">
<label>Departments:</label>
<div class="grid"></div>
</div>
ThisPage.computed.departmentUUIDs = function() {
let uuids = []
for (let dept of this.checkedDepartments) {
uuids.push(dept.uuid)
}
return uuids.join(',')
}
<div class="field-wrapper">
${h.checkbox('preferred_only', label="Include only those products for which this vendor is preferred.", checked=True)}
</div>
ThisPage.methods.vendorChanged = function(uuid) {
if (uuid) {
this.fetchingDepartments = true
<div class="buttons">
${h.submit('submit', "Generate Report")}
</div>
let url = '${url('departments.by_vendor')}'
let params = {uuid: uuid}
this.$http.get(url, {params: params}).then(response => {
this.departments = response.data
this.fetchingDepartments = false
this.fetchedDepartments = true
})
${h.end_form()}
} else {
this.departments = []
this.fetchedDepartments = false
}
}
<script type="text/javascript">
ThisPage.methods.validateForm = function(event) {
if (!this.departmentUUIDs.length) {
alert("You must select at least one Department.")
event.preventDefault()
}
}
$(function() {
</script>
</%def>
var autocompleter = $('#vendor-name').autocomplete({
serviceUrl: '${url('vendors.autocomplete')}',
width: 300,
onSelect: function(value, data) {
$('#vendor').val(data);
$('#vendor-name').hide();
$('#vendor-name').val('');
$('#vendor-display span').html(value);
$('#vendor-display').show();
loading($('div.grid'));
$('div.grid').load('${url('departments.by_vendor')}', {'uuid': data});
},
});
$('#vendor-name').focus();
$('#change-vendor').click(function() {
$('#vendor').val('');
$('#vendor-display').hide();
$('#vendor-name').show();
$('#vendor-name').focus();
$('div.grid').empty();
});
$('form').submit(function() {
var depts = [];
$('div.grid table tbody tr').each(function() {
if ($(this).find('td.checkbox input[type=checkbox]').is(':checked')) {
depts.push(get_uuid(this));
}
$('#departments').val(depts.toString());
return true;
});
});
});
</script>
${parent.body()}

View file

@ -135,7 +135,8 @@ class OrderingWorksheet(View):
time=now.strftime('%I:%M %p'),
get_upc=self.upc_getter,
rattail=rattail,
)
app=self.get_rattail_app(),
)
template_path = resource_path(self.report_template_path)
template = Template(filename=template_path)