Ejemplo n.º 1
0
def get_loan_to_save(data, amount = None, lid = None):
    if not lid:
        l = Loan.objects.get(pk=data['loan.id'])
    else:
        l = Loan.objects.get(pk=lid)
    if not amount:
        amount = round(l.amount / l.instalments,2)
        if amount > l.remain:
            amount = l.remain 
        validate_amount(amount)

    if param_exist("id",data):
        p = Payment.objects.get(pk=data['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.parseDate(data['date'])
    else:
        raise ValidationError(_('The entered amount is greater than the amount owed.'))
    return (l,p)
Ejemplo n.º 2
0
def save_or_update_old(request):
    data = '{"success":true}'
    req = request.REQUEST
    amount=req['amount']
    try:
        validate_amount(amount)
    except ValidationError, va1:
        return '{"success":false, "msg": "%s"}' % ("".join(va1.messages))
Ejemplo n.º 3
0
def save_or_update(request):
    req = request.REQUEST
    dt = DateService.parse(req['period']) 
    dt = datetime.date(dt.tm_year, dt.tm_mon, 1)
    
    amount=req['amount']
    try:
        validate_amount(amount)
    except ValidationError, va1:
        return '{"success":false, "msg": "%s"}' % ("".join(va1.messages))
Ejemplo n.º 4
0
                    'subCategoryId': exp.subCategory.id})

    data = '{"total": %s, "rows": %s, "amount": %s}' % (q.count(), JsonParser.parse(res), amount)
    return data

def fromParams(req):
    if not req['date']:
        raise ValidationError(_('Enter a valid date.'))
        
    amount = req['amount']
    if re.match('^[-\+\d\.]+$',amount):
        try:
            amount = str(eval(amount))
        except Exception, e:
            logger.error(e)
    validate_amount(amount)
    
    if not amount or float(amount) == 0.0:
        raise ValidationError(_('Enter a valid amount.'))

    try:
        s = SubCategory.objects.get(pk=req['subCategory.id'])
    except SubCategory.DoesNotExist:
        raise ValidationError(_('Select a valid category.'))
    try:
        p = PaymentType.objects.get(pk=req['paymentType.id'])
    except (PaymentType.DoesNotExist, KeyError):
        raise ValidationError(_('Select a valid payment type.'))
        
    if param_exist("text",req):
        text = req['text']