add inventory worksheet report
This commit is contained in:
		
							parent
							
								
									a53f4477e4
								
							
						
					
					
						commit
						4cd598f33e
					
				
					 3 changed files with 202 additions and 18 deletions
				
			
		
							
								
								
									
										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()}
 | 
				
			||||||
| 
						 | 
					@ -14,10 +14,75 @@ from pyramid.response import Response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import edbob
 | 
					import edbob
 | 
				
			||||||
from edbob.pyramid import Session
 | 
					from edbob.pyramid import Session
 | 
				
			||||||
 | 
					from edbob.files import resource_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import rattail
 | 
					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):
 | 
					def ordering_report(request):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    This is the "Ordering Worksheet" report.
 | 
					    This is the "Ordering Worksheet" report.
 | 
				
			||||||
| 
						 | 
					@ -37,7 +102,7 @@ def ordering_report(request):
 | 
				
			||||||
            response = Response(content_type='text/html')
 | 
					            response = Response(content_type='text/html')
 | 
				
			||||||
            response.headers['Content-Length'] = len(body)
 | 
					            response.headers['Content-Length'] = len(body)
 | 
				
			||||||
            response.headers['Content-Disposition'] = 'attachment; filename=ordering.html'
 | 
					            response.headers['Content-Disposition'] = 'attachment; filename=ordering.html'
 | 
				
			||||||
            response.body = body
 | 
					            response.text = body
 | 
				
			||||||
            return response
 | 
					            return response
 | 
				
			||||||
    return {}
 | 
					    return {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,19 +125,6 @@ def write_ordering_worksheet(vendor, departments):
 | 
				
			||||||
        costs[dept].setdefault(subdept, [])
 | 
					        costs[dept].setdefault(subdept, [])
 | 
				
			||||||
        costs[dept][subdept].append(cost)
 | 
					        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()
 | 
					    now = edbob.local_time()
 | 
				
			||||||
    data = dict(
 | 
					    data = dict(
 | 
				
			||||||
        vendor=vendor,
 | 
					        vendor=vendor,
 | 
				
			||||||
| 
						 | 
					@ -83,12 +135,19 @@ def write_ordering_worksheet(vendor, departments):
 | 
				
			||||||
        rattail=rattail,
 | 
					        rattail=rattail,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    report = os.path.join(os.path.dirname(__file__), os.pardir, 'reports', 'ordering_worksheet.mako')
 | 
					    report = resource_path('rattail.pyramid:reports/ordering_worksheet.mako')
 | 
				
			||||||
    report = os.path.abspath(report)
 | 
					    template = Template(filename=report)
 | 
				
			||||||
    template = Template(filename=report, disable_unicode=True)
 | 
					 | 
				
			||||||
    return template.render(**data)
 | 
					    return template.render(**data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def includeme(config):
 | 
					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_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…
	
	Add table
		Add a link
		
	
		Reference in a new issue