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 calculateReserva(self): from processor.DespesaMensalProcessor import DespesaMensalProcessor from processor.DespesaTempProcessor import DespesaTempProcessor sumDespesaMensal = DespesaMensalProcessor(month = self.month).sum() sumDespesaTemp = DespesaTempProcessor(month = self.month).sum() return sumDespesaMensal + sumDespesaTemp
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
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)
def changeMonth(self): ''' Changes the month and then copy despesas mensais from previous months if they don't exist. ''' from processor.DespesaMensalProcessor import DespesaMensalProcessor monthFilter = self.month months = self.monthDAO.find(monthFilter) month = None if len(months) == 1: month = months[0] else: month = monthFilter monthId = self.monthDAO.add(month) month.id = monthId print('Copying despesas from the past months...') DespesaMensalProcessor(month = month).copy() print('...Done') despesaMensalProcessor = DespesaMensalProcessor(month = month) despesaMensalProcessor.updateDespReservaAnual() despesaMensalProcessor.updateDespCarneLeao() month.month = DateUtil.toDate(month.month) return month
def ls_desp(params=None): despesas = DespesaMensalProcessor(month=month).find() despesaMensalHeader = DespesaMensal() print(despesaMensalHeader.defOutputStrHeader()) print(despesaMensalHeader.defOutputHr()) for d in despesas: print(d.defOutputStr()) despTotal = DespesaMensal(despesa=calculateDespesaTotal(despesas)) print(despesaMensalHeader.defOutputHr()) print(despTotal.defOutputStr()) print()
class DespesaAnualProcessor(DespesaChildProcessor): def __init__(self, month=None): super().__init__(month=month) self.despesaAnualDAO = DespesaAnualDAO() self.despesaMensalProcessor = DespesaMensalProcessor(month=month) def getDAO(self): return self.despesaAnualDAO def getModelType(self): return DespesaAnual def add(self, model): # skipping DespesaChildProcessor intentionally to avoid post CRUD actions GenericProcessor.add(self, model) self.despesaMensalProcessor.updateDespReservaAnual() def delete(self, model): # skipping DespesaChildProcessor intentionally to avoid post CRUD actions GenericProcessor.delete(self, model) self.despesaMensalProcessor.updateDespReservaAnual() def update(self, model): # skipping DespesaChildProcessor intentionally to avoid post CRUD actions GenericProcessor.update(self, model) self.despesaMensalProcessor.updateDespReservaAnual()
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)
def rm_desp(params=None): despesaMensal = DespesaMensal(despesa=Despesa(id=params[0])) DespesaMensalProcessor(month=month).delete(despesaMensal)
def add_desp(params=None): despesaMensal = DespesaMensal() despesaMensal.despesa.desc = input('Description: ') despesaMensal.despesa.val = input('Value: ') DespesaMensalProcessor(month=month).add(despesaMensal)
def __init__(self, month=None): super().__init__(month=month) self.despesaAnualDAO = DespesaAnualDAO() self.despesaMensalProcessor = DespesaMensalProcessor(month=month)
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'))
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'))