Added "preferred only" option to Ordering Worksheet.

This commit is contained in:
Lance Edgar 2013-02-11 19:08:24 -08:00
parent 80eb558783
commit cd7f7ee444
2 changed files with 9 additions and 2 deletions

View file

@ -34,6 +34,10 @@ ${h.hidden('departments', value='')}
<div class="grid"></div>
</div>
<div class="field-wrapper">
${h.checkbox('preferred_only', label="Include only those products for which this vendor is preferred.", checked=True)}
</div>
<div class="buttons">
${h.submit('submit', "Generate Report")}
</div>

View file

@ -34,7 +34,8 @@ def ordering_report(request):
dept = Session.query(rattail.Department).get(uuid)
if dept:
departments.append(dept)
body = write_ordering_worksheet(vendor, departments)
preferred_only = request.params.get('preferred_only') == '1'
body = write_ordering_worksheet(vendor, departments, preferred_only)
response = Response(content_type='text/html')
response.headers['Content-Length'] = len(body)
response.headers['Content-Disposition'] = 'attachment; filename=ordering.html'
@ -43,7 +44,7 @@ def ordering_report(request):
return {}
def write_ordering_worksheet(vendor, departments):
def write_ordering_worksheet(vendor, departments, preferred_only):
"""
Rendering engine for the ordering worksheet report.
"""
@ -52,6 +53,8 @@ def write_ordering_worksheet(vendor, departments):
q = q.join(rattail.Product)
q = q.filter(rattail.ProductCost.vendor == vendor)
q = q.filter(rattail.Product.department_uuid.in_([x.uuid for x in departments]))
if preferred_only:
q = q.filter(rattail.ProductCost.preference == 1)
costs = {}
for cost in q: