示例#1
0
def step_add_transactions(context):
    """
    Add transactions from a table in the format given below

    | account | date       | desc | amount | reconciled | category |
    | test    | 01-01-2014 |      | 100.0  | False      | cat1     |

    Where category is optional.
    """
    for row in context.table:
        with session_scope() as session:
            account = session.query(Account) \
                             .filter_by(name=row['account']) \
                             .one()
        tx = Transaction(
            account, datetime.datetime.strptime(row['date_time'],
                                                '%d-%m-%Y'), row['desc'],
            float(row['amount']),
            True if row['reconciled'] == 'True' else False)

        if 'category' in row.as_dict():
            with session_scope() as session:
                category = session.query(Category) \
                                  .filter_by(name=row['category']) \
                                  .one()
            tx.category = category
        save_object(tx)
示例#2
0
def step_add_transactions(context):
    """
    Add transactions from a table in the format given below

    | account | date       | desc | amount | reconciled | category |
    | test    | 01-01-2014 |      | 100.0  | False      | cat1     |

    Where category is optional.
    """
    for row in context.table:
        with session_scope() as session:
            account = session.query(Account) \
                             .filter_by(name=row['account']) \
                             .one()
        tx = Transaction(account,
                         datetime.datetime.strptime(row['date_time'],
                                                    '%d-%m-%Y'),
                         row['desc'],
                         float(row['amount']),
                         True if row['reconciled'] == 'True' else False)

        if 'category' in row.as_dict():
            with session_scope() as session:
                category = session.query(Category) \
                                  .filter_by(name=row['category']) \
                                  .one()
            tx.category = category
        save_object(tx)
示例#3
0
def step_add_categories(context):
    """
    Add categories from a table in the format given below

    | name |
    | cat1 |
    """
    for row in context.table:
        cat = Category(row['name'])
        save_object(cat)
示例#4
0
def test_cmd_assign_tx_similar_category():
    account = Account(u'test', u'12345')
    save_object(account)
    save_object(Category(u'cat1'))
    save_object(Transaction(account,
                            datetime.datetime.now().date(), u'desc', 1.0))

    CmdAssignTx(u'Cat1', '1')()

    with session_scope() as session:
        count = session.query(Category).count()
        eq_(count, 1)
示例#5
0
def test_cmd_assign_tx_similar_category():
    account = Account(u'test', u'12345')
    save_object(account)
    save_object(Category(u'cat1'))
    save_object(
        Transaction(account,
                    datetime.datetime.now().date(), u'desc', 1.0))

    CmdAssignTx(u'Cat1', '1')()

    with session_scope() as session:
        count = session.query(Category).count()
        eq_(count, 1)
示例#6
0
 def __call__(self):
     account = Account(self.name, self.number)
     save_object(account)
     return "Account '{}' created".format(self.name)
示例#7
0
def step_add_accounts(context):
    for row in context.table:
        account = Account(row['name'], row['number'])
        save_object(account)