Exemplo n.º 1
0
def add_renda(params=None):
    rendaProcessor = RendaProcessor(month=month)
    tipoRenda = inputTipoRenda()
    renda = Renda(tipoRenda=tipoRenda)
    renda.val = input('Value: ')
    renda.taxable = inputTaxable()
    rendaProcessor.add(renda)
Exemplo n.º 2
0
    def testBody(self):
        self.despesaMensalProcessor = DespesaMensalProcessor(month=self.month)
        self.rendaProcessor = RendaProcessor(month=self.month)

        self.despesaMensalFilter = DespesaMensal(despesa=Despesa(
            month=self.month))
        self.rendaFilter = Renda(month=self.month)

        self.testAdd()
        self.testUpdate()
        self.testDelete()
Exemplo n.º 3
0
 def buildSummary(self):
     summary = Summary()
     summary.rendas = RendaProcessor(month = self.month).find()
     summary.despesasAnuais = DespesaAnualProcessor(month = self.month).find()
     summary.despesasMensais = DespesaMensalProcessor(month = self.month).find()
     summary.despesasTemp = DespesaTempProcessor(month = self.month).find()
     return summary
Exemplo n.º 4
0
def ls_renda(params=None):
    rendas = RendaProcessor(month=month).find()
    rendaHeader = Renda()
    print(rendaHeader.defOutputStrHeader())
    print(rendaHeader.defOutputHr())
    total = 0.0
    for r in rendas:
        total += r.val if not r.tipoRenda.auto else 0.0
        print(r.defOutputStr())

    rendaTotal = Renda(TipoRenda(desc='Total'), val=total)
    print(rendaHeader.defOutputHr())
    print(rendaTotal.defOutputStr())
    print()
Exemplo n.º 5
0
class DespesaChildProcessor(GenericProcessor):
    def __init__(self, month=None):
        super().__init__(month=month)
        self.rendaProcessor = RendaProcessor(month=month)

    def pay(self, model):
        id = model.despesa.id
        paidVal = model.despesa.paidVal
        modelType = self.getModelType()
        modelFilter = modelType(despesa=Despesa(id=id))
        modelFilter.setMonth(self.month)
        models = self.getDAO().find(modelFilter)

        if len(models) != 1:
            return

        model = models[0]
        if paidVal:
            model.despesa.paidVal += paidVal
            if model.despesa.paidVal >= model.despesa.val:
                model.despesa.paid = 1

            if model.despesa.paidVal > model.despesa.val:
                model.despesa.val = model.despesa.paidVal
        else:
            model.despesa.paid = 1
            model.despesa.paidVal = model.despesa.val

        self.getDAO().update(model)

    def sum(self):
        modelType = self.getModelType()
        model = modelType()
        model.setMonth(self.month)
        resultModel = self.getDAO().sum(model)[0]
        return resultModel.despesa.val or 0

    def add(self, model):
        super().add(model)
        self.rendaProcessor.updateReserva()

    def delete(self, model):
        super().delete(model)
        self.rendaProcessor.updateReserva()

    def update(self, model):
        super().update(model)
        self.rendaProcessor.updateReserva()
Exemplo n.º 6
0
def clearMonthData(month):
    despesaAnual = DespesaAnual()
    despesaAnualProcessor = DespesaAnualProcessor(month)
    for despesaAnual in despesaAnualProcessor.find():
        despesaAnualProcessor.delete(despesaAnual)

    despesaTemp = DespesaTemp()
    despesaTempProcessor = DespesaTempProcessor(month)
    for despesaTemp in despesaTempProcessor.find():
        despesaTempProcessor.delete(despesaTemp)

    despesaMensal = DespesaMensal()
    despesaMensalProcessor = DespesaMensalProcessor(month)
    for despesaMensal in despesaMensalProcessor.find():
        despesaMensalProcessor.delete(despesaMensal)

    renda = Renda()
    RendaProcessor(month).delete(renda)

    carneLeao = CarneLeao()
    CarneLeaoProcessor(month).delete(carneLeao)

    MonthProcessor(month.user, month=month).delete(month)
Exemplo n.º 7
0
def rm_renda(params=None):
    renda = Renda(tipoRenda=TipoRenda(id=params[0]))
    RendaProcessor(month=month).delete(renda)
Exemplo n.º 8
0
 def __init__(self, month=None):
     super().__init__(month=month)
     self.rendaProcessor = RendaProcessor(month=month)
Exemplo n.º 9
0
class DespesaAnualProcessorTest(GenericTest):

    def __init__(self, month):
        super().__init__(month)

    def testBody(self):
        self.despesaMensalProcessor = DespesaMensalProcessor(month = self.month)
        self.despesaAnualProcessor = DespesaAnualProcessor(month = self.month)
        self.rendaProcessor = RendaProcessor(month = self.month)

        self.despesaMensalFilter = DespesaMensal(despesa = Despesa(month = self.month))
        self.despesaAnualFilter = DespesaAnual(despesa = Despesa(month = self.month))
        self.rendaFilter = Renda(month = self.month)

        self.testAdd()
        self.testUpdate()
        self.testDelete()        

    def testAdd(self):
        val = 1000
        totalAnual = 0.0
        for i in range(2):
            despesa = Despesa(desc = 'Test {}'.format(i + 1), val = val, paidVal = 500, paid = 0, month = self.month)
            despesaAnual = DespesaAnual(despesa = despesa)
            self.despesaAnualProcessor.add(despesaAnual)
            totalAnual += val

        result = self.despesaAnualProcessor.find()
        assert len(result) == 2, 'there must be 2 despesas anuais'

        for despesaAnual in result:
            assert despesaAnual.despesa.id, 'despesa expected id must not be null'
            assert despesaAnual.despesa.desc in ('Test 1', 'Test 2'), 'desc must be {}, not {}'.format('Test 1 or Test 2', despesaAnual.despesa.desc) 
            assert despesaAnual.despesa.val == 1000, 'val must be {}, not {}'.format(1000, despesaAnual.despesa.val)
            assert despesaAnual.despesa.paidVal == 500, 'paidVal must be {}, not {}'.format(500, despesaAnual.despesa.paidVal)
            assert despesaAnual.despesa.month.id == self.month.id, 'month.id must be {}, not {}'.format(self.month.id, despesaAnual.despesa.month.id)

        self.testAfterAddUpdate(totalAnual)

        print(self.getJustifiedSuccessMsg('add'))

    def testUpdate(self):
        result = self.despesaAnualProcessor.find()

        despesaAnual = result[0]
        despesaId = despesaAnual.despesa.id

        # update
        newVal = 500
        newPaidVal = 300
        despesaAnual.despesa.val = newVal
        despesaAnual.despesa.paidVal = newPaidVal

        self.despesaAnualProcessor.update(despesaAnual)

        result = self.despesaAnualProcessor.find()
        
        totalAnual = 0.0
        for despesaAnual in result:
            totalAnual += despesaAnual.despesa.val
            if despesaAnual.despesa.id == despesaId:
                assert despesaAnual.despesa.val == newVal and despesaAnual.despesa.paidVal == newPaidVal, 'val and paidVal must be {}, {}, but resulting despesa anual is {}'.format(val, paidVal, despesaAnual)
            else:
                assert despesaAnual.despesa.val != newVal and despesaAnual.despesa.paidVal != newPaidVal, 'val and paidVal should not be {}, {}, but resulting despesa anual is {}'.format(val, paidVal, despesaAnual)    

        self.testAfterAddUpdate(totalAnual)

        print(self.getJustifiedSuccessMsg('update'))
    
    def testDelete(self):
        result = self.despesaAnualProcessor.find()
        assert len(result) == 2, 'there must be 2 despesas anuais'

        for despesaAnual in result:
            self.despesaAnualProcessor.delete(despesaAnual)

        result = self.despesaAnualProcessor.find()
        assert len(result) == 0, 'there must be no despesas anuais'

        # a despesa mensal 'Reserva' must have been created when despesas anuais were created
        result = self.despesaMensalProcessor.find()
        assert len(result) == 1, 'there must be one and only one despesa mensal'
        assert result[0].auto == 1, 'the despesa mensal created must be automatically calculated'

        self.despesaMensalProcessor.delete(result[0])
        result = self.despesaMensalProcessor.find()
        assert len(result) == 0, 'there must be no despesas mensais'

        # a renda 'Reserva' must have been created when despesas mensais were created
        result = self.rendaProcessor.find()
        assert len(result) == 1, 'there must be one and only one renda'
        assert result[0].tipoRenda.auto == 1, 'the renda created must be a automatically calculated type'

        self.rendaProcessor.delete(result[0])
        result = self.rendaProcessor.find()
        assert len(result) == 0, 'there must be no renda'

        print(self.getJustifiedSuccessMsg('delete'))

    def testAfterAddUpdate(self, totalDespesaAnual):
        # creating despesas anuais must have resulted in a despesa mensal 'reserva' being created
        result = self.despesaMensalProcessor.find()
        assert len(result) == 1, 'there must be 1 despesa mensal'
        despesaMensal = result[0]
        assert despesaMensal.despesa.id, 'despesa expected id must not be null'
        assert despesaMensal.despesa.desc == 'Reserva Anual', 'desc must be {}, not {}'.format('Test 1 or Test 2', despesaMensal.despesa.desc) 
        assert despesaMensal.auto == 1, 'auto must be {}, not {}'.format(1, despesaMensal.auto)
        expectedDespesaMensalVal = (totalDespesaAnual / 12.0)
        assert despesaMensal.despesa.val == expectedDespesaMensalVal, 'val must be {}, not {}'.format(expectedDespesaMensalVal, despesaMensal.despesa.val)
        assert despesaMensal.despesa.paidVal == None, 'paidVal must be {}, not {}'.format(None, despesaMensal.despesa.paidVal)
        assert despesaMensal.despesa.month.id == self.month.id, 'month.id must be {}, not {}'.format(self.month.id, despesaMensal.despesa.month.id)

        # despesa mensal having been created above triggers creation of a renda 'reserva'
        result = self.rendaProcessor.find()
        assert len(result) == 1
        renda = result[0]
        assert renda.tipoRenda.auto == 1, 'tipo renda auto must be {}, not {}'.format(1, renda.tipoRenda.auto)
        assert renda.val == expectedDespesaMensalVal, 'renda must have val {}, not {}'.format(expectedDespesaMensalVal, renda.val)

        print(self.getJustifiedSuccessMsg('after CRUD'))
Exemplo n.º 10
0
class DespesaMensalProcessorTest(GenericTest):
    def __init__(self, month):
        super().__init__(month)

    def testBody(self):
        self.despesaMensalProcessor = DespesaMensalProcessor(month=self.month)
        self.rendaProcessor = RendaProcessor(month=self.month)

        self.despesaMensalFilter = DespesaMensal(despesa=Despesa(
            month=self.month))
        self.rendaFilter = Renda(month=self.month)

        self.testAdd()
        self.testUpdate()
        self.testDelete()

    def testAdd(self):
        for i in range(2):
            despesa = Despesa(desc='Test {}'.format(i + 1),
                              val=1000,
                              paidVal=500,
                              paid=0,
                              month=self.month)
            despesaMensal = DespesaMensal(despesa=despesa, auto=0)
            self.despesaMensalProcessor.add(despesaMensal)

        result = self.despesaMensalProcessor.find()
        assert len(result) == 2, 'there must be 2 despesas mensais'

        for despesaMensal in result:
            assert despesaMensal.despesa.id, 'despesa mensal expected id must not be null'
            assert despesaMensal.despesa.desc in (
                'Test 1', 'Test 2'), 'desc must be {}, not {}'.format(
                    'Test 1 or Test 2', despesaMensal.despesa.desc)
            assert despesaMensal.despesa.val == 1000, 'val must be {}, not {}'.format(
                1000, despesaMensal.despesa.val)
            assert despesaMensal.despesa.paidVal == 500, 'paidVal must be {}, not {}'.format(
                500, despesaMensal.despesa.paidVal)
            assert despesaMensal.despesa.month.id == self.month.id, 'month.id must be {}, not {}'.format(
                self.month.id, despesaMensal.despesa.month.id)

        print(self.getJustifiedSuccessMsg('add'))

    def testUpdate(self):
        result = self.despesaMensalProcessor.find()

        despesaMensal = result[0]
        despesaId = despesaMensal.despesa.id

        # update
        newVal = 500
        newPaidVal = 300
        despesaMensal.despesa.val = newVal
        despesaMensal.despesa.paidVal = newPaidVal

        self.despesaMensalProcessor.update(despesaMensal)

        result = self.despesaMensalProcessor.find()

        for despesaMensal in result:
            if despesaMensal.despesa.id == despesaId:
                assert despesaMensal.despesa.val == newVal and despesaMensal.despesa.paidVal == newPaidVal, 'val and paidVal must be {}, {}, but resulting despesa mensal is {}'.format(
                    val, paidVal, despesaMensal)
            else:
                assert despesaMensal.despesa.val != newVal and despesaMensal.despesa.paidVal != newPaidVal, 'val and paidVal should not be {}, {}, but resulting despesa mensal is {}'.format(
                    val, paidVal, despesaMensal)

        print(self.getJustifiedSuccessMsg('update'))

    def testDelete(self):
        result = self.despesaMensalProcessor.find()
        assert len(result) == 2, 'there must be 2 despesas mensais'

        for despesaMensal in result:
            self.despesaMensalProcessor.delete(despesaMensal)

        result = self.despesaMensalProcessor.find()
        assert len(result) == 0, 'there must be no despesas mensais'

        # a renda 'Reserva' must have been created when despesas were created
        result = self.rendaProcessor.find()
        assert len(result) == 1, 'there must be one and only one renda'
        assert result[
            0].tipoRenda.auto == 1, 'the renda created must be a automatically calculated type'

        self.rendaProcessor.delete(result[0])
        result = self.rendaProcessor.find()
        assert len(result) == 0, 'there must be no renda'

        print(self.getJustifiedSuccessMsg('delete'))