コード例 #1
0
ファイル: persistentstore.py プロジェクト: assem-ch/wxbanker
    def result2transaction(self, result, parentObj, linkedTransaction=None, recurringCache=None):
        tid, pid, amount, description, date, linkId, recurringId = result
        t = Transaction(tid, parentObj, amount, description, date)

        # Handle a linked transaction being passed in, a special case called from a few lines down.
        if linkedTransaction:
            t.LinkedTransaction = linkedTransaction
        else:
            # Handle recurring parents.
            if recurringId:
                t.RecurringParent = recurringCache[recurringId]

            # Handle linked transactions.
            if linkId:
                try:
                    link, linkAccount = self.getTransactionAndParentById(linkId, parentObj, t)
                except MissingLinkException:
                    # The link is gone, it's Account was likely deleted before LP: #514183/605591 was fixed. Remove it.
                    t.LinkedTransaction = None
                else:
                    # If the link parent hasn't loaded its transactions yet, put this in its pre list so this
                    # object is used if and when they are loaded.
                    if linkAccount._Transactions is None:
                        linkAccount._preTransactions.append(link)
                    t.LinkedTransaction = link
                    # Synchronize the RecurringParent attribute.
                    t.LinkedTransaction.RecurringParent = t.RecurringParent
        return t
コード例 #2
0
 def testTransactionTagEquality(self):
     t1 = Transaction(None, None, 1, "", None)
     t2 = Transaction(None, None, 1, "", None)
     
     self.assertEqual(t1, t2)
     
     t2._Tags = set("foo")
     
     self.assertNotEqual(t1, t2)
コード例 #3
0
    def testTransactionTagEquality(self):
        t1 = Transaction(None, None, 1, "", None)
        t2 = Transaction(None, None, 1, "", None)
        
        self.assertEqual(t1, t2)
        
        t2._Tags = set(["foo"])

        self.assertFalse(t1 == t2) # Why does assertNotEquals(t1, t2) not work?
コード例 #4
0
    def testTransactionTagEquality(self):
        t1 = Transaction(None, None, 1, "", None)
        t2 = Transaction(None, None, 1, "", None)

        self.assertEqual(t1, t2)

        t2._Tags = set(["foo"])

        self.assertFalse(
            t1 == t2)  # Why does assertNotEquals(t1, t2) not work?
コード例 #5
0
ファイル: csvimporter.py プロジェクト: Karagul/wxbanker
    def getTransactionsFromCSV(self, csvdata, settings):
        csvdata = StringIO(csvdata)
        csvReader = csv.reader(UTF8Recoder(csvdata, settings['encoding']),
                               delimiter=settings['delimiter'])

        transactions = []
        linesSkipped = 0
        for row in csvReader:
            # Unfortunately csvReader is not subscriptable so we must count ourselves.
            if settings['linesToSkip'] > linesSkipped:
                linesSkipped += 1
                continue

            # If we find a blank line, assume we've hit the end of the transactions.
            if not row:
                break

            # convert to python unicode strings
            row = [unicode(s, "utf-8") for s in row]

            amount = self.parseAmount(row[settings['amountColumn'] - 1],
                                      settings['decimalSeparator'])
            # Properly parse amounts from mint.
            if settings == shippedProfiles['mint'] and row[4] == "debit":
                amount *= -1

            desc = re.sub('\d+', lambda x: row[int(x.group(0)) - 1],
                          settings['descriptionColumns'])
            tdate = datetime.strptime(
                row[settings['dateColumn'] - 1],
                settings['dateFormat']).strftime('%Y-%m-%d')

            transactions.append(Transaction(None, None, amount, desc, tdate))

        return TransactionContainer(transactions)
コード例 #6
0
 def __init__(self, tID, parent, amount, description, date, repeatType, repeatEvery=1, repeatOn=None, endDate=None, source=None, lastTransacted=None):
     Transaction.__init__(self, tID, parent, amount, description, date)
     ORMObject.__init__(self)
     
     # If the transaction recurs weekly and repeatsOn isn't specified, use the starting date.
     if repeatType == self.WEEKLY and repeatOn is None:
         todaydaynumber = date.weekday()
         repeatOn = [int(i==todaydaynumber) for i in range(7)]
     
     self.IsFrozen = True
     self.RepeatType = repeatType
     self.RepeatEvery = repeatEvery
     self.RepeatOn = repeatOn
     self.EndDate = endDate
     self.Source = source
     self.LastTransacted = lastTransacted
     self.IsFrozen = False
コード例 #7
0
    def AddTransaction(self,
                       amount=None,
                       description="",
                       date=None,
                       source=None,
                       transaction=None):
        """
        Enter a transaction in this account, optionally making the opposite
        transaction in the source account first.
        """
        Publisher.sendMessage("batch.start")

        if transaction:
            # It is "partial" because its ID and parent aren't necessarily correct.
            partialTrans = transaction
            partialTrans.Parent = self
        elif amount is not None:
            # No transaction object was given, we need to make one.
            partialTrans = Transaction(None, self, amount, description, date)
        else:
            raise Exception(
                "AddTransaction: Must provide either transaction arguments or a transaction object."
            )

        if source:
            otherTrans = source.AddTransaction(-1 * partialTrans.Amount,
                                               partialTrans._Description,
                                               partialTrans.Date)

        transaction = self.Store.MakeTransaction(self, partialTrans)

        # If it was a transfer, link them together
        if source:
            transaction.LinkedTransaction = otherTrans
            otherTrans.LinkedTransaction = transaction

        # Don't append if there aren't transactions loaded yet, it is already in the model and will appear on a load. (LP: 347385).
        if self._Transactions is not None:
            self.Transactions.append(transaction)
        else:
            # We will need to do some magic with these later when transactions are loaded.
            self._preTransactions.append(transaction)

        Publisher.sendMessage("transaction.created", (self, transaction))

        # Update the balance.
        self.Balance += transaction.Amount
        Publisher.sendMessage("batch.end")

        if source:
            return transaction, otherTrans
        else:
            return transaction
コード例 #8
0
    def result2transaction(self,
                           result,
                           parentObj,
                           linkedTransaction=None,
                           recurringCache=None):
        tid, pid, amount, description, date, linkId, recurringId = result
        t = Transaction(tid, parentObj, amount, description, date)

        # Handle a linked transaction being passed in, a special case called from a few lines down.
        if linkedTransaction:
            t.LinkedTransaction = linkedTransaction
        else:
            # Handle recurring parents.
            if recurringId:
                t.RecurringParent = recurringCache[recurringId]

            # Handle linked transactions.
            if linkId:
                try:
                    link, linkAccount = self.getTransactionAndParentById(
                        linkId, parentObj, t)
                except MissingLinkException:
                    # The link is gone, it's Account was likely deleted before LP: #514183/605591 was fixed. Remove it.
                    t.LinkedTransaction = None
                else:
                    # If the link parent hasn't loaded its transactions yet, put this in its pre list so this
                    # object is used if and when they are loaded.
                    if linkAccount._Transactions is None:
                        linkAccount._preTransactions.append(link)
                    t.LinkedTransaction = link
                    # Synchronize the RecurringParent attribute.
                    t.LinkedTransaction.RecurringParent = t.RecurringParent
        return t
コード例 #9
0
    def __eq__(self, other):
        if other is None:
            return False

        assert isinstance(other, RecurringTransaction), other
        return (
            Transaction.__eq__(self, other) and
            self.RepeatType == other.RepeatType and
            self.RepeatEvery == other.RepeatEvery and
            self.RepeatOn == other.RepeatOn and
            self.EndDate == other.EndDate and
            self.Source == other.Source and
            self.LastTransacted == other.LastTransacted
            )