Example #1
0
    def Run(self, transactions):
        self.SortTransactions(transactions)

        results = []
        if len(self.transactions) == 0:
            return
        if len(self.transactions[0]) == 0:
            return
        earliestDate = Dates(self.transactions[0][0]["date"].month,
                             self.transactions[0][0]["date"].year)
        months = Dates.monthDifference(self.date, earliestDate)

        for index in range(0, len(months)):
            if len(self.transactions) < index + 1:
                trans = [{
                    "date": months[index].getDate(),
                    "amount": 0,
                    "empty": True
                }]
            else:
                trans = self.transactions[index]
            currentDate = months[index]
            if currentDate > self.date:
                break
            val = self.Calculate(trans)
            if self.history.needsPosted(
                    currentDate) or currentDate == self.date:
                results.append(val)

        # for trans in self.transactions:
        #     if (len(trans) == 0):
        #         continue
        #     currentDate = Dates(trans[0]["date"].month, trans[0]["date"].year)
        #     if currentDate > self.date:
        #         break
        #     val = self.Calculate(trans)
        #     if self.history.needsPosted(currentDate) or currentDate == self.date:
        #        results.append(val)
        return results