Esempio n. 1
0
def transaction_put(**kwargs):  # pylint: disable=C0111,W0613
    obj = json.loads(request.data.decode('utf-8', 'strict'))
    print(obj)
    # try:
    i = Transaction(
        time=datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date(),
        account_id=int(obj['account.id']),
        user_id=session['user'][0],
        summ=decimal.Decimal(strip_numbers(obj['summ'])),
        transfer=int(obj['transfer']) if
        (obj['transfer'] != '' and int(obj['transfer']) > 0) else None,
        income_id=int(obj['income.id']) if
        (obj['income.id'] != '' and int(obj['income.id']) > 0) else None,
        comments=obj['comments'])
    DB.add(i)
    DB.flush()
    if 'new_account.id' in obj:
        transfer = Transaction(
            time=datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date(),
            account_id=int(obj['new_account.id']),
            user_id=session['user'][0],
            summ=decimal.Decimal(strip_numbers(obj['new_sum'])),
            transfer=int(obj['transfer'])
            if int(obj['transfer']) > 0 else None,
            income_id=int(obj['income.id'])
            if int(obj['income.id']) > 0 else None,
            comments=obj['comments'])
        DB.add(transfer)
        DB.flush()
        i.transfer = transfer.record_id
        transfer.transfer = i.record_id
    DB.commit()
    # except:
    #    abort(400)
    return i
Esempio n. 2
0
def backlogs_put(**kwargs):
    """
    actually insert transaction
    """
    obj = json.loads(request.data.decode('utf-8', 'strict'))
    origin_time = datetime.datetime.strptime(
            obj['origin_time'], '%Y-%m-%d').date()
    operation_time = datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date()

    transaction = Transaction(
        time=operation_time,
        account_id=int(obj['account.id']),
        sum=strip_numbers(obj['sum']),
        income_id=obj['income.id'],
        comment=obj['comment'])
    DB.add(transaction)
    DB.flush()
    if origin_time != operation_time:
        # payment before
        DB.add(
            Payforward(
                income_id=int(obj['income.id']),
                income_date=origin_time,
                payment_date=operation_time,
                transaction_id=transaction.record_id
            )
        )
    DB.commit()
    return transaction
Esempio n. 3
0
def transactions_post(**kwargs):
    obj = json.loads(request.data.decode('utf-8', 'strict'))
    # try:
    i = Transaction(
        time=datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date(),
        account_id=int(obj['account.id']),
        sum=decimal.Decimal(strip_numbers(obj['sum'])),
        transfer=int(obj['transfer']) if int(obj['transfer']) > 0 else None,
        income_id=int(obj['income.id']) if int(obj['income.id']) > 0 else None,
        comment=obj['comment']
    )
    DB.add(i)
    DB.flush()
    if 'new_account.id' in obj:
        transfer = Transaction(
          time=datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date(),
          account_id=int(obj['new_account.id']),
          sum=decimal.Decimal(strip_numbers(obj['new_sum'])),
          transfer=int(obj['transfer']) if int(obj['transfer']) > 0 else None,
          comment=obj['comment'],
          income_id=int(obj['income.id']) if int(obj['income.id']) > 0 else None
        )
        DB.add(transfer)
        DB.flush()
        i.transfer = transfer.record_id
        transfer.transfer = i.record_id
    DB.commit()
    # except:
    #    abort(400)
    return i
Esempio n. 4
0
def backlogs_delete(**kwargs):
    # just create transaction with sum zero
    obj = json.loads(request.data.decode('utf-8', 'strict'))
    t = Transaction(
        time=datetime.datetime.strptime(obj['origin_time'], '%Y-%m-%d').date(),
        account_id=0,
        sum=0,
        income_id=obj['income.id'],
        comment='cancelled')
    DB.add(t)
    DB.flush()
    DB.commit()
    return t
Esempio n. 5
0
def accounts_post(**kwargs):
    """ add new account and set first transaction with rests of money """
    obj = json.loads(request.data.decode('utf-8', 'strict'))
    new_account = Account(
            title=obj['title'],
            currency_id=int(obj['currency.id']))
    DB.add(new_account)
    DB.flush()
    if float(strip_numbers(obj['sum'])) > 0:
        DB.add(Transaction(account_id=new_account.record_id,
                           show=obj['show'],
                           comment='initial summ',
                           time=datetime.date.today(),
                           sum=strip_numbers(obj['sum'])))
    DB.commit()
    return new_account
Esempio n. 6
0
def incomes_post(**kwargs):
    obj = json.loads(request.data.decode('utf-8', 'strict'))
    # try:
    i = Income(
      title=obj['title'],
      currency_id=int(obj['currency.id']),
      sum=decimal.Decimal(strip_numbers(obj['sum'])),
      start_date=datetime.datetime.strptime(
          obj['start_date'], '%Y-%m-%d').date(),
      end_date=(None if obj['end_date'] == '' else datetime.datetime.strptime(
          obj['end_date'], '%Y-%m-%d').date()),
      period_id=int(obj['period.id'])
    )
    DB.add(i)
    DB.flush()
    DB.commit()
    # except:
    #    abort(400)
    return i