Пример #1
0
    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()        
Пример #2
0
    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'))
Пример #3
0
def pay_desp(params=None):
    id = params[0]
    paidVal = None
    if len(params) > 1:
        paidVal = float(params[1])

    despesaMensal = DespesaMensal(despesa=Despesa(id=id, paidVal=paidVal))
    DespesaMensalProcessor(month=month).pay(despesaMensal)
Пример #4
0
def calculateDespesaTotal(despesasChild):
    totalVal = 0.0
    totalPaidVal = 0.0
    for d in despesasChild:
        totalVal += d.despesa.val or 0.0
        totalPaidVal += d.despesa.paidVal or 0.0

    return Despesa(desc='Total', val=totalVal, paidVal=totalPaidVal)
Пример #5
0
 def buildJoinedModels(self, model, row):
     keys = row.keys()
     model.despesa = Despesa(
         id = row['id'] if 'id' in keys else None, 
         desc = row['desc'] if 'desc' in keys else None, 
         val = row['val'] if 'val' in keys else None, 
         paidVal = row['paid_val'] if 'paid_val' in keys else None, 
         paid = row['paid'] if 'paid' in keys else None, 
         month = Month(
             id = row['month_id'] if 'month_id' in keys else None,
             month = row['month'] if 'month' in keys else None
         )
     )
Пример #6
0
    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'))
Пример #7
0
    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)
Пример #8
0
def rm_desp(params=None):
    despesaMensal = DespesaMensal(despesa=Despesa(id=params[0]))
    DespesaMensalProcessor(month=month).delete(despesaMensal)
Пример #9
0
def pay_desp_tmp(params=None):
    id = params[0]
    despesaTemp = DespesaTemp(despesa=Despesa(id=id))
    DespesaTempProcessor(month=month).pay(despesaTemp)
Пример #10
0
def rm_desp_tmp(params=None):
    despesaTemp = DespesaTemp(despesa=Despesa(id=params[0]))
    DespesaTempProcessor(month=month).delete(despesaTemp)
Пример #11
0
 def __init__(self, despesa = None):
     self.despesa = despesa if despesa != None else Despesa()
Пример #12
0
 def getTestRowFilterModel2(self):
     return DespesaAnual(
         despesa=Despesa(desc='desp test', month='2018-03-01'))
Пример #13
0
 def getTestRowFilterModel1(self):
     return DespesaMensal(despesa = Despesa(desc = 'desp test', month = '2018-02-01'))
Пример #14
0
 def getDespesaTempFilterModel2(self):
     return DespesaTemp(
         despesa=Despesa(desc='desp test', month='2018-03-01'))
Пример #15
0
 def buildJoinedModels(self, model, row):
     despesa = Despesa(id=row['id'],
                       month=Month(id=row['month_id'],
                                   month=row['despesa_month']))
     despesaTemp = DespesaTemp(despesa=despesa)
     model.despesaTemp = despesaTemp