Ejemplo n.º 1
14
def createTransaction(transaction_date, account1_uuid, account1_memo, account2_uuid, account2_memo,
                      transaction_currency, transaction_value, transaction_description):
    try:
        # create a new transaction with two splits - just lovely this
        # pyxb design - the below is written by _just_ looking at the
        # rng schema
        return gnc.transaction(
            trn.id( uuid.uuid4().hex, type="guid" ),
            trn.currency( cmdty.space("ISO4217"), cmdty.id(transaction_currency) ),
            trn.date_posted( ts.date(transaction_date) ),
            trn.date_entered( ts.date(now) ),
            trn.description(transaction_description),
            trn.splits(
                trn.split(
                    split.id( uuid.uuid4().hex, type="guid" ),
                    split.memo( account1_memo ),
                    split.reconciled_state( "n" ),
                    split.value( gnucashFromAmount(transaction_value) ),
                    split.quantity( gnucashFromAmount(transaction_value) ),
                    split.account( account1_uuid, type="guid" )),
                trn.split(
                    split.id( uuid.uuid4().hex, type="guid" ),
                    split.memo( account2_memo ),
                    split.reconciled_state( "n" ),
                    split.value( gnucashFromAmount(-transaction_value) ),
                    split.quantity( gnucashFromAmount(-transaction_value) ),
                    split.account( account2_uuid, type="guid" ))),
            version="2.0.0" )
    except pyxb.UnrecognizedContentError as e:
        print '*** ERROR validating input:'
        print 'Unrecognized element "%s" at %s (details: %s)' % (e.content.expanded_name, e.content.location, e.details())
Ejemplo n.º 2
12
    def addTransaction(self, **kwargs):
        transaction_date = kwargs.pop('date')
        transaction_currency = kwargs.pop('currency')
        transaction_description = kwargs.pop('description')
        txn = kwargs.pop('txn')

        # don't accept non-default currencies here, unless it at least
        # appears to be a multi-currency split transaction
        if (self.default_currency != transaction_currency and
            len(txn[0]) < 2 and len(txn[1]) < 2):
            # well - actually _do_ accept it if net value is zero,
            # since it obviously does not affect the balance
            if ((len(txn[0]) > 0 and txn[0][0][2] == '0,00') or
                (len(txn[1]) > 0 and txn[1][0][2] == '0,00')):
                # fake main transaction currency. amount is zero anyway
                transaction_currency = self.default_currency
            else:
                print "Wrong currency for main transaction encountered, bailing out!"
                if args.verbosity > 0: print "Context: "+str(currLine)
                exit(1)

        try:
            transaction=gnc.transaction(
                trn.id( uuid.uuid4().hex, type="guid" ),
                trn.currency( cmdty.space("ISO4217"), cmdty.id(transaction_currency) ),
                trn.date_posted( ts.date(getGNCDateStr(transaction_date)) ),
                trn.date_entered( ts.date(self.now) ),
                trn.description(transaction_description),
                trn.splits(),
                version="2.0.0")

            for curr_split in txn[0]:
                split_account = curr_split[0]
                split_memo    = curr_split[1]
                split_value   = curr_split[2]

                if isinstance(split_value, str):
                    split_value = self.amountFromPayPal(split_value)
                if len(curr_split) > 3:
                    split_uuid = self.lookupAccountUUID(split_account, type=curr_split[3])
                else:
                    split_uuid = self.lookupAccountUUID(split_account)

                transaction.splits.append(
                    trn.split(
                        split.id( uuid.uuid4().hex, type="guid" ),
                        split.memo( split_memo ),
                        split.reconciled_state( "n" ),
                        split.value( gnucashFromAmount(split_value) ),
                        split.quantity( gnucashFromAmount(split_value) ),
                        split.account( split_uuid, type="guid" )) )

            for curr_split in txn[1]:
                split_account = curr_split[0]
                split_memo    = curr_split[1]
                split_value   = curr_split[2]

                if isinstance(split_value, str):
                    split_value = self.amountFromPayPal(split_value)
                if len(curr_split) > 3:
                    split_uuid = self.lookupAccountUUID(split_account, type=curr_split[3])
                else:
                    split_uuid = self.lookupAccountUUID(split_account)

                transaction.splits.append(
                    trn.split(
                        split.id( uuid.uuid4().hex, type="guid" ),
                        split.memo( split_memo ),
                        split.reconciled_state( "n" ),
                        split.value( gnucashFromAmount(-split_value) ),
                        split.quantity( gnucashFromAmount(-split_value) ),
                        split.account( split_uuid, type="guid" )) )

            self.document.append(transaction)

        except pyxb.UnrecognizedContentError as e:
            print '*** ERROR validating input:'
            print 'Unrecognized element "%s" at %s (details: %s)' % (e.content.expanded_name,
                                                                     e.content.location, e.details())
Ejemplo n.º 3
0
    def addTransaction(self, **kwargs):
        transaction_date = kwargs.pop('date')
        transaction_currency = kwargs.pop('currency')
        transaction_description = kwargs.pop('description')
        txn = kwargs.pop('txn')

        # don't accept non-default currencies here, unless it at least
        # appears to be a multi-currency split transaction
        if (self.default_currency != transaction_currency and len(txn[0]) < 2
                and len(txn[1]) < 2):
            # well - actually _do_ accept it if net value is zero,
            # since it obviously does not affect the balance
            if ((len(txn[0]) > 0 and txn[0][0][2] == '0,00')
                    or (len(txn[1]) > 0 and txn[1][0][2] == '0,00')):
                # fake main transaction currency. amount is zero anyway
                transaction_currency = self.default_currency
            else:
                print "Wrong currency for main transaction encountered, bailing out!"
                if args.verbosity > 0: print "Context: " + str(currLine)
                exit(1)

        try:
            transaction = gnc.transaction(
                trn.id(uuid.uuid4().hex, type="guid"),
                trn.currency(cmdty.space("ISO4217"),
                             cmdty.id(transaction_currency)),
                trn.date_posted(ts.date(getGNCDateStr(transaction_date))),
                trn.date_entered(ts.date(self.now)),
                trn.description(transaction_description),
                trn.splits(),
                version="2.0.0")

            for curr_split in txn[0]:
                split_account = curr_split[0]
                split_memo = curr_split[1]
                split_value = curr_split[2]

                if isinstance(split_value, str):
                    split_value = self.amountFromPayPal(split_value)
                if len(curr_split) > 3:
                    split_uuid = self.lookupAccountUUID(split_account,
                                                        type=curr_split[3])
                else:
                    split_uuid = self.lookupAccountUUID(split_account)

                transaction.splits.append(
                    trn.split(split.id(uuid.uuid4().hex, type="guid"),
                              split.memo(split_memo),
                              split.reconciled_state("n"),
                              split.value(gnucashFromAmount(split_value)),
                              split.quantity(gnucashFromAmount(split_value)),
                              split.account(split_uuid, type="guid")))

            for curr_split in txn[1]:
                split_account = curr_split[0]
                split_memo = curr_split[1]
                split_value = curr_split[2]

                if isinstance(split_value, str):
                    split_value = self.amountFromPayPal(split_value)
                if len(curr_split) > 3:
                    split_uuid = self.lookupAccountUUID(split_account,
                                                        type=curr_split[3])
                else:
                    split_uuid = self.lookupAccountUUID(split_account)

                transaction.splits.append(
                    trn.split(split.id(uuid.uuid4().hex, type="guid"),
                              split.memo(split_memo),
                              split.reconciled_state("n"),
                              split.value(gnucashFromAmount(-split_value)),
                              split.quantity(gnucashFromAmount(-split_value)),
                              split.account(split_uuid, type="guid")))

            self.document.append(transaction)

        except pyxb.UnrecognizedContentError as e:
            print '*** ERROR validating input:'
            print 'Unrecognized element "%s" at %s (details: %s)' % (
                e.content.expanded_name, e.content.location, e.details())