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
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
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
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
def accounts_put(**kwargs): a = DB.query(Account).get(kwargs['id']) obj = json.loads(request.data.decode('utf-8', 'strict')) a.title = obj['title'] a.show = obj['show'] a.currency_id = obj['currency.id'] delta_sum = decimal.Decimal(strip_numbers(obj['sum'])) - a.sum() if delta_sum != 0: t = Transaction(time=datetime.date.today(), sum=delta_sum, account_id=kwargs['id'], comment='fix account summ') DB.add(t) DB.commit() return {'updated': DB.query(Account).get(kwargs['id']), "previous": a}
def transactions_put(**kwargs): i = DB.query(Transaction).get(kwargs['id']) obj = json.loads(request.data.decode('utf-8', 'strict')) # try: i.time = datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date() i.account_id = int(obj['account.id']) if obj['account.id'] != '' else None i.sum = decimal.Decimal(strip_numbers(obj['sum'])) i.transfer = int(obj['transfer']) if obj['transfer'] not in [ '0', ''] else None i.income_id = int(obj['income.id']) if obj['income.id'] not in [ '0', ''] else None i.comment = obj['comment'] # except: # abort(400) DB.commit() return {'updated': DB.query(Transaction).get(kwargs['id']), "previous": i}
def incomes_put(**kwargs): i = DB.query(Income).get(kwargs['id']) obj = json.loads(request.data.decode('utf-8', 'strict')) # try: i.title = obj['title'] i.currency_id = int(obj['currency.id']) i.sum = decimal.Decimal(strip_numbers(obj['sum'])) i.start_date = datetime.datetime.strptime( obj['start_date'], '%Y-%m-%d').date() i.end_date = ( None if obj['end_date'] == '' else datetime.datetime.strptime( obj['end_date'], '%Y-%m-%d').date()) i.period_id = int(obj['period.id']) # except: # abort(400) DB.commit() return {'updated': DB.query(Income).get(kwargs['id']), "previous": i}
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
def transaction_post(**kwargs): # pylint: disable=C0111 i = DB.query(Transaction).get(kwargs['id']) obj = json.loads(request.data.decode('utf-8', 'strict')) print(obj) print(obj['time']) # try: i.time = datetime.datetime.strptime(obj['time'], '%Y-%m-%d').date() # TODO: check if account valid for this user i.account_id = int(obj['account.id']) if obj['account.id'] != '' else None i.user_id = session['user'][0] i.summ = decimal.Decimal(strip_numbers(obj['summ'])) # TODO: check if transfer transaction valid for this user i.transfer = int(obj['transfer']) if obj['transfer'] not in ['0', '' ] else None i.income_id = int(obj['income.id']) if obj['income.id'] not in ['0', '' ] else None i.comments = obj['comments'] # except: # abort(400) DB.commit() return {'updated': DB.query(Transaction).get(kwargs['id']), "previous": i}