Exemplo n.º 1
0
def upload_csv(request):
    if request.method == 'POST':
        file = request.FILES["file"]
        data = csv.reader(file)
        fields = data.next()

        shipment = None
        for row in data:
            cols = row[0].split('\t')
            if shipment is None:
                shipment = Shipment()
                shipment.code = cols[Column.SHIPMENT_ID]
                shipment.save()

            si = ShipmentItem()
            si.code = int(cols[Column.ID_SHIPMENT_ITEM])
            si.barcode = cols[Column.BARCODE]
            si.sku = cols[Column.SKU]
            si.quantity = int(cols[Column.QUANTITY])
            si.photo_url = cols[Column.IMAGE_URL]
            si.shipment = shipment
            si.save()
            print si.pk

        return render_response(request, 'good_acc/item_view.html',{'sid':shipment.pk})

    return render_response(request, 'good_acc/upload_csv.html',{'error':request.GET.get("error",None)})
Exemplo n.º 2
0
def item_view(request):
    sid = request.POST.get("sid",None)
    if sid is None:
        return redirect('/acceptance/upload_csv/?error=1')

    barcode = request.POST.get("barcode",None)

    isExists = False
    si = ShipmentItem()
    if barcode is not None:
        shipment = Shipment.objects.get(pk=int(sid))
        if shipment.shipmentitem_set.filter(barcode = barcode).count():
            si = shipment.shipmentitem_set.get(barcode = barcode)
            isExists = True

    return render_response(request, 'good_acc/item_view.html',{'si':si,'sid':sid,'isExists':isExists})