def transaction_create(request, account_id): account = Account.get_by_id(int(account_id)) if account is None: raise Http404 if request.method == 'POST': t = Transaction(parent=account) form = TransactionForm(request.POST, instance=t) if form.is_valid(): form.save(commit=False) t.setDate() t.save() logging.info('new transaction created - id: %s key: %s data: %s' % (t.key().id() , t.key(), t)) return redirect('/accounts/'+account_id+'/transactions/') else: form = TransactionForm() return render_to_response('accounts/transaction_create.html', RequestContext(request, { 'form':form }))
def task_do_clearance(request, clearance_id): logging.info('task do clearance - clearance_id=%s'%clearance_id) clearance = Clearance.get_by_id(int(clearance_id)) if clearance is None: raise Http404 logging.info('clearance = %s'%clearance) items = ClearanceItem.objects.all().ancestor(clearance) for i in items: logging.info('i=%s'%i) if not (i.transaction_item is None): logging.info('has transaction...') if not i.clear: logging.info('but,not clear...') i.clear = True i.save() logging.info('cleared') else: tr = Transaction.objects.all().filter('clearance_item_key =', i.key()).get() if not (tr is None): logging.info('corresponding transaction found (%s)'%tr) i.transaction_item=tr logging.info('linked') else: logging.info('no corresponding transaction found') tr = Transaction(parent=i.account) tr.setDate() tr.clearance_item_key = i.key() if i.purpose == 'pick': logging.info('pick item') tr.purpose = 'payment' tr.order_item_key = i.order_item.key() tr.amount = -i.cost tr.desc = i.desc elif i.purpose == 'give': logging.info('give item') tr.purpose = 'payment' tr.amount = -i.cost tr.desc = i.desc elif i.purpose == 'deposit': logging.info('deposit item') tr.purpose = 'deposit' tr.amount = i.cost tr.desc = i.desc elif i.purpose == 'load': logging.info('load item') tr.purpose = 'deposit' tr.amount = i.cost tr.desc = i.desc else: logging.info('unexpected purpose (%s)'%i.purpose) tr = None logging.info('new tr=%s'%tr) if not (tr is None): tr.save() logging.info('tr save ok %s'%tr) i.transaction_item = tr i.clear = True i.save() logging.info('new tr=%s'%tr) logging.info('unlock clearance') clearance.status = 'closed' clearance.lock = False clearance.clear = True clearance.save() return HttpResponse('ok')