コード例 #1
0
ファイル: views.py プロジェクト: byrenx/rbmo
def addAllotmentRelease(request, agency):
    context = RequestContext(request)

    data = {'system_name' : SYSTEM_NAME,
            'year'        : datetime.today().year,
            'allowed_tabs': get_allowed_tabs(request.user.id),
            'agency'      : agency,
            'agency_tabs' : getAgencyTabs(request.user.id, agency.id),
            'current_tab' : 'Allotment Releases',
            'action'      : 'add'
    }
    #add allotment releases action
    allot_release_form = AllotmentReleaseForm(request.POST)
    if allot_release_form.is_valid():
        allot_release = AllotmentReleases(
            ada_no = allot_release_form.cleaned_data['ada'],
            agency = agency,
            allocation = allot_release_form.cleaned_data['allocation'],
            month = allot_release_form.cleaned_data['month'],
            year = request.POST.get('year'),
            date_release = allot_release_form.cleaned_data['date_release'],
            amount_release = allot_release_form.cleaned_data['amount'],
            user = request.user
        )
            
        budget = gettotalAllocation(int(allot_release.year), int(allot_release.month), allot_release.agency, allot_release.allocation)
        #getRelease
        release = getReleaseAmount(int(allot_release.year), int(allot_release.month), allot_release.agency, allot_release.allocation)
        balance = numify(budget)-numify(release)
        if budget==0:
            data['e_msg'] = 'No Alloted amount for %s - %s' %(stringify_month(int(allot_release.month)), allot_release.allocation)
            data['form']   = allot_release_form
            return render_to_response('./fund/fund_release_form.html', data, context)
        elif balance <=0 :
            data['e_msg'] = 'No Remaining Balance for %s - %s Allocation. The full amount already released' %(stringify_month(int(allot_release.month)), allot_release.allocation) 
            data['form']   = allot_release_form
            return render_to_response('./fund/fund_release_form.html', data, context)
        elif allot_release.amount_release<=0:
            data['e_msg'] = 'Please Enter a valid amount'
            data['form']   = allot_release_form
            return render_to_response('./fund/fund_release_form.html', data, context)
        elif allot_release.amount_release>balance:
            data['e_msg'] = 'The amount you enter exceeds the allotment balance'
            data['form']   = allot_release_form
            return render_to_response('./fund/fund_release_form.html', data, context)
        else:
            allot_release.save()
            data['s_msg'] = 'Fund Release was succesfully saved'
            data['agency'] = agency
            data['form']   = allot_release_form
            return render_to_response('./fund/fund_release_form.html', data, context)
    else:
        data['errors'] = allot_release_form.errors
        data['form']   = allot_release_form
        return render_to_response('./fund/fund_release_form.html', data, context)
コード例 #2
0
ファイル: views.py プロジェクト: rumz/rbmo-test
def fundReleaseForm(request):
    context = RequestContext(request)
    data = {'form'        : AllotmentReleaseForm(),
            'system_name' : SYSTEM_NAME,
            'agency_id'   : request.GET.get('agency_id'),
            'year'        : time.strftime('%Y'),
            'agency_tab'  : 'fund_rel'
    }

    data['allowed_tabs'] = get_allowed_tabs(request.user.id)

    if request.method == 'POST':
        allot_release_form = AllotmentReleaseForm(request.POST)
        if allot_release_form.is_valid():
            allot_release = AllotmentReleases(
                ada_no = allot_release_form.cleaned_data['ada'],
                agency = Agency.objects.get(id=request.POST.get('agency_id')),
                allocation = request.POST.get('allocation'),
                month = allot_release_form.cleaned_data['month'],
                year = request.POST.get('year'),
                date_release = datetime.today(),
                amount_release = allot_release_form.cleaned_data['amount']
            )
            allot_release.save()
            data['agency'] = allot_release.agency
            data['s_msg'] = 'Fund Release was succesfully saved'
            return render_to_response('./fund/fund_release_form.html', data, context)
        else:
            data['errors'] = fund_release_form.errors
            return render_to_response('./fund/fund_release_form.html', data, context)
            
    elif data['agency_id'] is None:
        return HttpResponseRedirect('/admin/agencies')
    else:
        agency = Agency.objects.get(id=data['agency_id'])
        data['agency'] = agency
        return render_to_response('./fund/fund_release_form.html', data, context)