def linkStockLevel(request, **kwargs): """ Link a level with facility and stock """ form = StockLevelForm() save_error_name = '' controller = StockController() facility = controller.getFacility(kwargs.get('facility_id')) if request.method == "POST": form = StockLevelForm(request.POST) if form.is_valid(): try: controller = StockController() stock_item = controller.getStockItem(request.POST.get('stock_item')) form.save(stock_item, facility) return redirect('/stock/stock_level/facility/levels/%s/' % facility.id) except IntegrityError: save_error_name = "The combination selected already exists. View facility profile to adjust levels." except: save_error_name = "The name selected is an existing stock item, please try again." return render_to_response( 'stock_level/link_stock.html', { 'form':form, 'save_error_name':save_error_name, 'facility':facility, }, context_instance=RequestContext(request) )
def indexFacilityLevels(request, **kwargs): """ List all stock levels for a specific facility """ facility_id = kwargs.get('facility_id') controller = StockController() stock_levels = controller.getAllStockLevelsPerFacility(facility_id=facility_id) facility = controller.getFacility(facility_id) return render_to_response( 'stock_level/index_per_facility.html', { 'stock_levels':stock_levels, 'facility':facility, 'facility_true':True, }, context_instance=RequestContext(request) )