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)
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: pass try: p.save() except _mysql_exceptions.Warning: pass except Exception, e1: data = '{"success":false, "msg": "%s"}' % (e1.args) else: data = '{"success":false, "msg": "%s"}' % (_('The entered amount is greater than the amount owned')) return data @json_response 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):