예제 #1
0
    def test_account_total_is_updated(self):
        tr_1 = Transaction("credit", 10, "Money transfer")
        tr_2 = Transaction("debit", 5, "Purchase")
        self.service.save_transaction(tr_1)
        self.service.save_transaction(tr_2)

        self.assertEqual(self.service.get_account_summary(), 5)
예제 #2
0
    def test_transaction_is_saved_by_id(self):
        tr_1 = Transaction("credit", 10, "Money transfer")
        tr_2 = Transaction("debit", 5, "Purchase")
        saved_tr_1 = self.service.save_transaction(tr_1)
        saved_tr_2 = self.service.save_transaction(tr_2)

        retrieved_tr_1 = self.service.get_transaction_by_id(1)
        retrieved_tr_2 = self.service.get_transaction_by_id(2)

        self.assertEqual(saved_tr_1, retrieved_tr_1)
        self.assertEqual(saved_tr_2, retrieved_tr_2)
        self.assertNotEqual(retrieved_tr_1, retrieved_tr_2)
예제 #3
0
 def btnAddActionPerformed(self):
     customerId = self.__txtCustomerId.get()
     itemId = self.__txtItemId.get()
     number = self.__txtNumber.get()
     employeeId = self.__txtEmployeeId.get()
     if len(customerId) > 0 and len(itemId) > 0 and len(number) > 0 and len(
             employeeId) > 0:
         try:
             customer = Customer(customerId, "", "", "")
             item = Item(itemId, "", "", "")
             employee = Employee(employeeId, "", "", "", "")
             if self.__customers.__contains__(customer) \
                     and self.__items.__contains__(item) and\
                     self.__employees.__contains__(employee):
                 cIndex = self.__customers.index(customer)
                 iIndex = self.__items.index(item)
                 eIndex = self.__employees.index(employee)
                 transaction = Transaction("", self.__customers[cIndex],
                                           self.__items[iIndex], number,
                                           self.__employees[eIndex])
                 transaction.fixId()
                 self.__parent.addTransactionCallBack(transaction)
                 messagebox.showinfo("Success",
                                     "A new transaction has been added")
                 self.showDefaultText()
             else:
                 messagebox.showerror("Error",
                                      "This information does not exist!")
         except Exception:
             messagebox.showerror("Error", "Invalid information format!")
     else:
         messagebox.showerror("Error", "Input fields cannot be left blank!")
예제 #4
0
    def create_debit(self, amount, description):

        account_amount = self.get_account_summary()
        if account_amount - amount < 0:
            raise NegativeTotalError(amount, account_amount)

        tr = Transaction("debit", amount, description)
        return self.db.save_transaction(tr)
예제 #5
0
def createTransaction(pre_out_ids, publicAddrToValueArray):
    tx_ins = __get_tx_ins(pre_out_ids)
    tx_outs = __get_tx_outs(publicAddrToValueArray)

    tx = Transaction(Constants.VERSION, tx_ins, tx_outs, Constants.LOCK_TIME,
                     None, 0)
    if verify(tx):
        insert(tx)
        # 广播新交易
        return tx
예제 #6
0
def deserialize_hello_bank_input_file(file_path: str) -> List[Transaction]:
    transaction_list: List[Transaction] = []
    with open(file_path, 'r') as f:
        reader = csv.reader(f, delimiter=";")
        next(reader)  # skip header
        for row in reader:
            date: datetime = make_date_from_string(row[0])
            transaction_list.append(
                Transaction(date, row[1], row[2], row[3],
                            float(row[4].replace(",", ".").replace(" ", ""))))
    return transaction_list
예제 #7
0
def createFirstTransaction(publicAddrToValueArray):
    tx_in = TransactionIn.coinbase_tx_in()
    tx_ins = []
    tx_ins.append(tx_in)
    tx_outs = __get_tx_outs(publicAddrToValueArray)

    tx = Transaction(Constants.VERSION, tx_ins, tx_outs, Constants.LOCK_TIME,
                     None, 0)
    if verify(tx):
        insert(tx)
        # 广播新交易
        return tx
예제 #8
0
def __getSearchResultSingle(c):
    tmp = c.fetchone()
    if tmp == None:
        return None
    parentBlockId = tmp[4]
    parentTxId = tmp[1]
    txs_in = TransactionInDao.search(parentBlockId, parentTxId)
    txs_out = TransactionOutDao.search(parentBlockId, parentTxId)
    unspents = unspents_from_db(txs_in)
    if tmp[7] == 1:
        tx = Transaction(tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0])
    else:
        tx = TransactionCF(CFHeader(tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14]), tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0])
        
    return tx
예제 #9
0
def __getSearchResult(c):
    txs = []
    for tmp in c.fetchall():
        parentBlockId = tmp[4]
        parentTxId = tmp[1]
        txs_in = TransactionInDao.search(parentBlockId, parentTxId)
        txs_out = TransactionOutDao.search(parentBlockId, parentTxId)
        unspents = unspents_from_db(txs_in)
        if tmp[7] == 1:
            tx = Transaction(tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0])
        else:
            tx = TransactionCF(CFHeader(tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14]), tmp[2], txs_in, txs_out, tmp[3], unspents, tmp[6], tmp[0])
        txs.append(tx)
        
    return txs
예제 #10
0
 def readTransactionTable(self):
     self.__transactions = []
     sql = "SELECT * FROM transactions"
     self.__cursor.execute(sql)
     records = self.__cursor.fetchall()
     for row in records:
         id = str(row[0])
         customerId = str(row[1])
         itemId = str(row[3])
         number = str(row[5])
         employeeId = str(row[7])
         cIndex = self.__customers.index(Customer(customerId, "", "", ""))
         iIndex = self.__items.index(Item(itemId, "", "", ""))
         eIndex = self.__employees.\
             index(Employee(employeeId, "", "", "", ""))
         transaction = Transaction(id, self.__customers[cIndex],
                                   self.__items[iIndex], number,
                                   self.__employees[eIndex])
         self.__transactions.append(transaction)
     return self.__transactions
예제 #11
0
 def create_credit(self, amount, description):
     tr = Transaction("credit", amount, description)
     return self.db.save_transaction(tr)
예제 #12
0
    def test_transaction_is_saved(self):
        tr = Transaction("debit", 10, "Money transfer")
        self.service.save_transaction(tr)

        self.assertEqual(len(self.service.get_all_transactions()), 1)
예제 #13
0
__author__ = 'CSPF'

from . config import app,db_path,db
from model.Users import User
from model.Account import Account
from model.Transaction import Transaction
from os import stat,path


if not path.exists(db_path):
    #first time -default password
    db.create_all()
    user = User("mammoth","mammoth")
    user.id = 100000
    user.create()

    user1 = User("test","test")
    user1.create()

    account = Account(user.id,"13371111",100000)
    account.create()


    account1 = Account(user1.id,"13371112",400000)
    account1.create()

    first_transaction = Transaction(user.id,10000,13371111,13371112,remarks="Salary",transaction_details="User to User 1 (1000)")
    first_transaction.insert()


from . import controller