From cd7f7ee4446f623380267d8edbde6815d173438a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 11 Feb 2013 19:08:24 -0800 Subject: [PATCH] Added "preferred only" option to Ordering Worksheet. --- rattail/pyramid/templates/reports/ordering.mako | 4 ++++ rattail/pyramid/views/reports.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rattail/pyramid/templates/reports/ordering.mako b/rattail/pyramid/templates/reports/ordering.mako index 2eca252f..4cd014fc 100644 --- a/rattail/pyramid/templates/reports/ordering.mako +++ b/rattail/pyramid/templates/reports/ordering.mako @@ -34,6 +34,10 @@ ${h.hidden('departments', value='')}
+
+ ${h.checkbox('preferred_only', label="Include only those products for which this vendor is preferred.", checked=True)} +
+
${h.submit('submit', "Generate Report")}
diff --git a/rattail/pyramid/views/reports.py b/rattail/pyramid/views/reports.py index 0df29850..4776fa92 100644 --- a/rattail/pyramid/views/reports.py +++ b/rattail/pyramid/views/reports.py @@ -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: