def getInvestments(self, investmentId, startDate, endDate, active): investmentList = [] # if no period is informed, find the second max date in such a way to allow evaluate the evolution # TODO: figure out a better way to do this # TODO: after inserting an operation with bigger date than the end date of balance, the same is not returned in the result: this must be fixed somehow if startDate is None and endDate is None: for investment in self.investment: if active == True and investment.balance[0].amount == 0: continue if len(investment.balance) > 1 and ( startDate is None or investment.balance[1].date < startDate): startDate = investment.balance[1].date if endDate is None or investment.balance[0].date > endDate: endDate = investment.balance[0].date print(f'[debug] get investment: {startDate} - {endDate}') # trasverse the investments list to fetch those that satisfy all search criteria for investment in self.investment: if active == True and investment.balance[0].amount == 0: continue if investmentId is not None and investmentId != str(investment.id): continue balance = [] for balanceItem in investment.balance: if startDate <= balanceItem.date and endDate >= balanceItem.date: balance.append(balanceItem) operation = [] for operationItem in investment.operation: if startDate <= operationItem.date and endDate >= operationItem.date: operation.append(operationItem) revenue = [] for revenueItem in investment.revenue: if startDate <= revenueItem.date and endDate >= revenueItem.date: revenue.append(revenueItem) if len(balance) > 0: investmentAux = Investment() investmentAux.id = investment.id investmentAux.name = investment.name investmentAux.type = investment.type investmentAux.bank = investment.bank investmentAux.operation = operation investmentAux.balance = balance investmentAux.revenue = revenue investmentList.append(investmentAux.to_json()) return investmentList