Пример #1
0
def save(request):
    req = request.REQUEST
    l = Loan.objects.get(pk=req['loan.id'])
    p = Payment(loan=l,amount=req['amount'],date=DateService.invert(req['date']))
    
    if checkPayment(l,req['amount'],None):
        data = '{"success":true}'
        l.remain = unicode(float(l.remain) - float(p.amount))
        try:
            l.save()
        except _mysql_exceptions.Warning:
            pass        
        try:
            p.save()
        except _mysql_exceptions.Warning:
            pass        
        except Exception, e1:
            data = '{"success":false, "msg": "%s"}' % (e1.args)
Пример #2
0
    data = '{"success":true}'
    req = request.REQUEST
    number = validators.RegexValidator('^([0-9])+(\.[0-9]{1,2})?$', code=_('Amount'))
    amount=req['amount']
    try:
        number(amount)
    except ValidationError, va1:
        return '{"success":false, "msg": "%s: %s"}' % (va1.code, "".join(va1.messages))

    l = Loan.objects.get(pk=req['loan.id'])
    if param_exist("id",req):
        p = Payment.objects.get(pk=req['id'])    
        prevAmount = p.amount
        
    else:
        p = Payment(loan=l)
        prevAmount = None
    
    if checkPayment(l,amount,prevAmount):
        if prevAmount:
            diff = float(prevAmount) - float(amount)
            l.remain = unicode(float(l.remain) + diff)
        else:
            l.remain = unicode(float(l.remain) - float(amount))

        p.amount=amount
        p.date=DateService.invert(req['date'])
        
        try:
            l.save()
        except _mysql_exceptions.Warning: