示例#1
0
def delete(request):
    e = Expense(pk=request.REQUEST['id'])
    try:
        e.delete()
        data = '{"success":true}'
    except Exception, e1:
        data = '{"success":false, "msg": "%s"}' % (e1.args)   
示例#2
0
def pay(request):
    req = request.REQUEST
    e = Tax.objects.get(pk=req['id'])
    if e:
        if param_exist("nextExpire",req):
            e.expire = DateService.invert(req['nextExpire'])
        else:
            e.expire = e.nextExpire
        if param_exist("nextExpire2",req):
            e.nextExpire = DateService.invert(req['nextExpire2'])
        else:
            e.nextExpire = None
        e.amount = req['amount']
        e.lastPay = DateService.todayDate()
        if e.account=="":
            service = e.service
        else:
            service = "%s (%s)" % (e.service, e.account)
        expense = Expense(date=DateService.todayDate(), text=service, amount=e.amount, subCategory=e.subCategory, paymentType=e.paymentType)
        
        data = '{"success":true}'
        
        safe = True
        try:
            e.save()
        except _mysql_exceptions.Warning:
            pass
        except Exception, e1:
            safe = False
            transaction.rollback()
            data = '{"success":false, "msg": "%s"}' % (e1.args)
        
        if safe:
            try:
                expense.save()
                transaction.commit()
            except _mysql_exceptions.Warning:
                transaction.commit()
            except Exception, e2:
                safe = False
                transaction.rollback()
                data = '{"success":false, "msg": "%s"}' % (e2.args)
示例#3
0
def fromParams(req):
    s = SubCategory.objects.get(pk=req['subCategory.id'])
    p = PaymentType(pk=req['paymentType.id'])
    if param_exist("text",req):
        text = req['text']
    else:
        text = s.name 

    if param_exist("id",req):
        e = Expense.objects.get(pk=req['id'])
    else:
        e = Expense()
        
    e.text=text
    e.date=DateService.invert(req['date']) 
    e.amount=req['amount']
    e.subCategory=s
    e.paymentType=p
    return e
示例#4
0
def fromParams(req):
    if not req['date']:
        raise ValidationError(_('Enter a valid date'))
        
    amount = req['amount']
    number = validators.RegexValidator('^-?([0-9])+(\.[0-9]{1,2})?$', message=_('Enter a valid amount'))
    number(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:
        raise ValidationError(_('Select a valid payment type'))
        
    if param_exist("text",req):
        text = req['text']
    else:
        text = s.name 

    if param_exist("id",req):
        e = Expense.objects.get(pk=req['id'])
    else:
        e = Expense()
        
    e.text=text
    e.date=DateService.invert(req['date']) 
    e.amount=amount
    e.subCategory=s
    e.paymentType=p
    return e
示例#5
0
from cash.models import Expense, SubCategory, PaymentType
from django.conf import settings

class SyncServiceClass(object):

    def __init__(self):
        self.server = xmlrpclib.ServerProxy(settings.RPC_HOST).app
            
    def sync_expenses(self):
        try:
            data = self.server.getData()
        except Exception, e:
            raise
        else:
            if data:
                for e in data:
                    expense = Expense()
                    s = SubCategory.objects.get(pk=e['subCategory'])
                    p = PaymentType.objects.get(pk=e['paymentType'])
                    if e['text']:
                        expense.text = e['text']
                    else:
                        expense.text = s.name
                    expense.subCategory=s
                    expense.paymentType=p
                    expense.date=e['date']
                    expense.amount=e['amount']
                    expense.save()
                return len(data)
            else:
                return 0