Exemple #1
0
def stockonhand_facility(request, facility_code, context={}, template="logistics/stockonhand_facility.html"):
    """
     this view currently only shows the current stock on hand for a given facility
    """
    facility = get_object_or_404(SupplyPoint, code=facility_code)
    last_reports = ProductReport.objects.filter(supply_point=facility).order_by('-report_date')
    transactions = StockTransaction.objects.filter(supply_point=facility)
    if transactions:
        context['last_reported'] = last_reports[0].report_date
        context['chart_data'] = stocklevel_plot(transactions)
    context['facility'] = facility
    context["location"] = facility.location
    context["destination_url"] = "aggregate"
    return render_to_response(
        template, context, context_instance=RequestContext(request)
    )
def stockonhand_facility(request, facility_code, context={}, template="logistics/stockonhand_facility.html"):
    """
     this view currently only shows the current stock on hand for a given facility
    """
    facility = get_object_or_404(SupplyPoint, code=facility_code)
    last_reports = ProductReport.objects.filter(supply_point=facility).order_by('-report_date')
    transactions = StockTransaction.objects.filter(supply_point=facility)
    if transactions:
        context['last_reported'] = last_reports[0].report_date
        context['chart_data'] = stocklevel_plot(transactions)
    context['facility'] = facility
    context["location"] = facility.location
    context["destination_url"] = "aggregate"
    return render_to_response(
        template, context, context_instance=RequestContext(request)
    )
Exemple #3
0
def hsa(request, code):
    if Contact.objects.filter(supply_point__code=code, is_active=True).count():
        hsa = get_object_or_404(Contact, supply_point__code=code, is_active=True)
    elif Contact.objects.filter(supply_point__code=code).count():
        hsa = Contact.objects.filter(supply_point__code=code)[0]
    else:
        return Http404("Contact not found!")
    assert(hsa.supply_point.type.code == config.SupplyPointCodes.HSA)
    
    transactions = StockTransaction.objects.filter(supply_point=hsa.supply_point)
    chart_data = stocklevel_plot(transactions) 
    
    stockrequest_table = StockRequestTable(hsa.supply_point.stockrequest_set\
                                           .exclude(status=StockRequestStatus.CANCELED), request)
    return render_to_response("malawi/single_hsa.html",
        {
            "hsa": hsa,
            "id_str": "%s %s" % (hsa.supply_point.code[-2:], hsa.supply_point.code[:-2]),
            "chart_data": chart_data,
            "stockrequest_table": stockrequest_table
        }, context_instance=RequestContext(request)
    )