Example #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)})
Example #2
0
def action(request):
    type = request.GET.get("type")
    si_id = request.GET.get("siid")
    sid = request.GET.get("sid")

    si = ShipmentItem()
    if ShipmentItem.objects.filter(pk=int(si_id)).count():
        si = ShipmentItem.objects.get(pk=int(si_id))
    else:
        si.barcode = si_id
        si.shipment = Shipment.objects.get(pk=sid)

    if type == "1":
        si.quantity_received +=1
        if si.quantity_stocked == si.quantity:
            si.save()
            return HttpResponse("2", mimetype='application/json; charset=utf8')

        si.quantity_stocked += 1
    if type == "2":
        si.quantity_received +=1
        si.quantity_photomismatch += 1
    if type == "3":
        si.quantity_received +=1
        si.quantity_damaged += 1
    if type == "4":
        si.quantity_stocked -= 1
        si.quantity_received -=1
    if type == "5":
        si.quantity_photomismatch -= 1
        si.quantity_received -=1
    if type == "6":
        si.quantity_damaged -= 1
        si.quantity_received -=1

    si.save()
    return HttpResponse("1", mimetype='application/json; charset=utf8')