Example #1
0
def order_upload(request):
    form = FileForm(request.POST, request.FILES)

    if form.is_valid():
        upload = request.FILES.values()[0]
        file_name_with_timestamp = accountifie.common.uploaders.csv.save_file(upload)
        dupes, new_packs, missing_ship_codes = process_nc2(file_name_with_timestamp)
        messages.success(request, 'Loaded NC2 file: %d new records and %d duplicate records' % (new_packs, dupes))
        messages.error(request, 'Missing shipping codes: %d ' % (missing_ship_codes))
        context = {}
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    else:
        context = {}
        context.update({'file_name': request.FILES.values()[0]._name, 'success': False, 'out': None, 'err': None})
        messages.error(request, 'Could not process the NC2 file provided, please see below')
        return render(request, 'uploaded.html', context)
Example #2
0
def upload_gl(request):
    if request.method != "POST":
        forecast_obj = Forecast.objects.get(id=request.GET.get('forecast'))
        context = {'file_category': 'GL Projections'}
        context['file_type'] = '.csv'
        context['obj_label'] = forecast_obj.label
        form = FileForm()
        context['form'] = form

        return render(request, 'forecasts/upload_gl.html', context)
    else:
        form = FileForm(request.POST, request.FILES)
        if form.is_valid():
            upload = io.StringIO(unicode(request.FILES.values()[0].read()), newline=None)
            data = [row for row in csv.DictReader(upload)]
            forecast_obj = Forecast.objects.get(id=request.GET.get('forecast'))
            forecast_obj.hardcode_projections = data
            forecast_obj.save()
            return HttpResponseRedirect('/forecasts/forecast/%s' % forecast_obj.id)
Example #3
0
def order_upload(request):
    form = FileForm(request.POST, request.FILES)

    if form.is_valid():
        upload = request.FILES.values()[0]
        file_name = upload._name
        file_name_with_timestamp = accountifie.common.uploaders.csv.save_file(upload)

        rslts = process_shopify(file_name_with_timestamp)
        if rslts['status'] == 'ERROR':
            messages.warning(request, 'File is not csv. Please check file')
        else:
            dupes = rslts['exist_sales_ctr']
            new_sales = rslts['new_sales_ctr']
            unknown_cp_ctr = rslts['unknown_cp_ctr']
            messages.success(request, 'Loaded shopify file: %d new sales and %d duplicate sales' % (new_sales, dupes))
            messages.warning(request, 'Missing counterparty info: %d not recognised. Please see Shopify report.' % unknown_cp_ctr)

        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    else:
        context.update({'file_name': request.FILES.values()[0]._name, 'success': False, 'out': None, 'err': None})
        messages.error(request, 'Could not process the shopify file provided, please see below')
        return render(request, 'uploaded.html', context)