Merge branch 'v0.3'
This commit is contained in:
commit
6744c77cc0
96
rattail/pyramid/reports/inventory_worksheet.mako
Normal file
96
rattail/pyramid/reports/inventory_worksheet.mako
Normal file
|
@ -0,0 +1,96 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html style="direction: ltr;" xmlns="http://www.w3.org/1999/xhtml" lang="en-us">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
<title>Inventory Worksheet : ${department.name}</title>
|
||||
<style type="text/css">
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
margin: 10px 0px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
table {
|
||||
border-bottom: 1px solid #000000;
|
||||
border-left: 1px solid #000000;
|
||||
border-collapse: collapse;
|
||||
empty-cells: show;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th {
|
||||
border-right: 1px solid #000000;
|
||||
border-top: 1px solid #000000;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
th.subdepartment {
|
||||
border-left: none;
|
||||
font-size: 1.2em;
|
||||
padding: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
td {
|
||||
border-right: 1px solid #000000;
|
||||
border-top: 1px solid #000000;
|
||||
padding: 2px 4px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
td.upc {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
td.count {
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
td.spacer {
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Inventory Worksheet</h1>
|
||||
<h2>Department: ${department.name} (${department.number})</h2>
|
||||
<h3>generated on ${date} at ${time}</h3>
|
||||
<br clear="all" />
|
||||
|
||||
<table>
|
||||
% for subdepartment in department.subdepartments:
|
||||
<% products = get_products(subdepartment) %>
|
||||
% if products:
|
||||
<tr>
|
||||
<th class="subdepartment" colspan="4">Subdepartment: ${subdepartment.name} (${subdepartment.number})</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>UPC</th>
|
||||
<th>Brand</th>
|
||||
<th>Description</th>
|
||||
<th>Count</th>
|
||||
</tr>
|
||||
% for product in products:
|
||||
<tr>
|
||||
<td class="upc">${get_upc(product)}</td>
|
||||
<td class="brand">${product.brand or ''}</td>
|
||||
<td class="description">${product.description}</td>
|
||||
<td class="count"> </td>
|
||||
</tr>
|
||||
% endfor
|
||||
<tr>
|
||||
<td class="spacer" colspan="19">
|
||||
</tr>
|
||||
% endif
|
||||
% endfor
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
29
rattail/pyramid/templates/reports/inventory.mako
Normal file
29
rattail/pyramid/templates/reports/inventory.mako
Normal file
|
@ -0,0 +1,29 @@
|
|||
<%inherit file="/reports/base.mako" />
|
||||
|
||||
<%def name="title()">Report : Inventory Worksheet</%def>
|
||||
|
||||
<p>Please provide the following criteria to generate your report:</p>
|
||||
<br />
|
||||
|
||||
${h.form(request.current_route_url())}
|
||||
|
||||
<div class="field-wrapper">
|
||||
<label for="department">Department</label>
|
||||
<div class="field">
|
||||
<select name="department">
|
||||
% for department in departments:
|
||||
<option value="${department.uuid}">${department.name}</option>
|
||||
% endfor
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
${h.checkbox('weighted-only', label=h.literal("Include items sold by weight <strong>only</strong>."))}
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
${h.submit('submit', "Generate Report")}
|
||||
</div>
|
||||
|
||||
${h.end_form()}
|
|
@ -33,8 +33,9 @@ import formalchemy
|
|||
from webhelpers.html import HTML
|
||||
|
||||
from edbob.pyramid import Session
|
||||
from edbob.pyramid.grids.search import BooleanSearchFilter
|
||||
from edbob.pyramid.views import SearchableAlchemyGridView, CrudView
|
||||
from edbob.pyramid.grids.search import BooleanSearchFilter
|
||||
from edbob.pyramid.forms import StrippingFieldRenderer
|
||||
|
||||
import rattail
|
||||
|
||||
|
@ -101,6 +102,8 @@ class ProfileCrud(CrudView):
|
|||
return super(FormatFieldRenderer, self).render(**kwargs)
|
||||
|
||||
fs = self.make_fieldset(model)
|
||||
fs.printer_spec.set(renderer=StrippingFieldRenderer)
|
||||
fs.formatter_spec.set(renderer=StrippingFieldRenderer)
|
||||
fs.format.set(renderer=FormatFieldRenderer)
|
||||
fs.configure(
|
||||
include=[
|
||||
|
|
|
@ -19,6 +19,70 @@ from edbob.files import resource_path
|
|||
import rattail
|
||||
|
||||
|
||||
plu_upc_pattern = re.compile(r'^000000000(\d{5})$')
|
||||
weighted_upc_pattern = re.compile(r'^002(\d{5})00000\d$')
|
||||
|
||||
def get_upc(product):
|
||||
upc = '%014u' % product.upc
|
||||
m = plu_upc_pattern.match(upc)
|
||||
if m:
|
||||
return str(int(m.group(1)))
|
||||
m = weighted_upc_pattern.match(upc)
|
||||
if m:
|
||||
return str(int(m.group(1)))
|
||||
return upc
|
||||
|
||||
|
||||
def inventory_report(request):
|
||||
"""
|
||||
This is the "Inventory Worksheet" report.
|
||||
"""
|
||||
|
||||
departments = Session.query(rattail.Department)
|
||||
|
||||
if request.params.get('department'):
|
||||
department = departments.get(request.params['department'])
|
||||
if department:
|
||||
body = write_inventory_worksheet(request, department)
|
||||
response = Response(content_type='text/html')
|
||||
response.headers['Content-Length'] = len(body)
|
||||
response.headers['Content-Disposition'] = 'attachment; filename=inventory.html'
|
||||
response.text = body
|
||||
return response
|
||||
|
||||
departments = departments.order_by(rattail.Department.name)
|
||||
departments = departments.all()
|
||||
return{'departments': departments}
|
||||
|
||||
|
||||
def write_inventory_worksheet(request, department):
|
||||
"""
|
||||
Generates the Inventory Worksheet report.
|
||||
"""
|
||||
|
||||
def get_products(subdepartment):
|
||||
q = Session.query(rattail.Product)
|
||||
q = q.outerjoin(rattail.Brand)
|
||||
q = q.filter(rattail.Product.subdepartment == subdepartment)
|
||||
if request.params.get('weighted-only'):
|
||||
q = q.filter(rattail.Product.unit_of_measure == rattail.UNIT_OF_MEASURE_POUND)
|
||||
q = q.order_by(rattail.Brand.name, rattail.Product.description)
|
||||
return q.all()
|
||||
|
||||
now = edbob.local_time()
|
||||
data = dict(
|
||||
date=now.strftime('%a %d %b %Y'),
|
||||
time=now.strftime('%I:%M %p'),
|
||||
department=department,
|
||||
get_products=get_products,
|
||||
get_upc=get_upc,
|
||||
)
|
||||
|
||||
report = resource_path('rattail.pyramid:reports/inventory_worksheet.mako')
|
||||
template = Template(filename=report)
|
||||
return template.render(**data)
|
||||
|
||||
|
||||
def ordering_report(request):
|
||||
"""
|
||||
This is the "Ordering Worksheet" report.
|
||||
|
@ -39,7 +103,7 @@ def ordering_report(request):
|
|||
response = Response(content_type='text/html')
|
||||
response.headers['Content-Length'] = len(body)
|
||||
response.headers['Content-Disposition'] = 'attachment; filename=ordering.html'
|
||||
response.body = body
|
||||
response.text = body
|
||||
return response
|
||||
return {}
|
||||
|
||||
|
@ -64,19 +128,6 @@ def write_ordering_worksheet(vendor, departments, preferred_only):
|
|||
costs[dept].setdefault(subdept, [])
|
||||
costs[dept][subdept].append(cost)
|
||||
|
||||
plu_upc_pattern = re.compile(r'^0000000(\d{5})$')
|
||||
weighted_upc_pattern = re.compile(r'^02(\d{5})00000$')
|
||||
|
||||
def get_upc(prod):
|
||||
upc = '%012u' % prod.upc
|
||||
m = plu_upc_pattern.match(upc)
|
||||
if m:
|
||||
return str(int(m.group(1)))
|
||||
m = weighted_upc_pattern.match(upc)
|
||||
if m:
|
||||
return str(int(m.group(1)))
|
||||
return upc
|
||||
|
||||
now = edbob.local_time()
|
||||
data = dict(
|
||||
vendor=vendor,
|
||||
|
@ -91,10 +142,18 @@ def write_ordering_worksheet(vendor, departments, preferred_only):
|
|||
report = edbob.config.get('rattail.pyramid', 'report.ordering_worksheet',
|
||||
default=report)
|
||||
report = os.path.abspath(report)
|
||||
template = Template(filename=report, disable_unicode=True)
|
||||
template = Template(filename=report)
|
||||
return template.render(**data)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
||||
config.add_route('reports.inventory', '/reports/inventory')
|
||||
config.add_view(inventory_report,
|
||||
route_name='reports.inventory',
|
||||
renderer='/reports/inventory.mako')
|
||||
|
||||
config.add_route('reports.ordering', '/reports/ordering')
|
||||
config.add_view(ordering_report, route_name='reports.ordering', renderer='/reports/ordering.mako')
|
||||
config.add_view(ordering_report,
|
||||
route_name='reports.ordering',
|
||||
renderer='/reports/ordering.mako')
|
||||
|
|
Loading…
Reference in a new issue