当前位置: 首页>>代码示例>>Python>>正文


Python Transaction.type方法代码示例

本文整理汇总了Python中models.Transaction.type方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.type方法的具体用法?Python Transaction.type怎么用?Python Transaction.type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Transaction的用法示例。


在下文中一共展示了Transaction.type方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_balance

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
def add_balance():
    """For GET requests, display the login form. For POSTS, login the current user
    by processing the form."""

    form = BalanceForm()
    if form.validate_on_submit():
        user = User.query.get(form.email.data)
        if user:
            if user.balance is None:
                user.balance = UserBalance()
                user.balance.amount = 0.0
            user.balance.amount += form.amount.data

            txn_id = str(uuid.uuid4())[:8]
            reason = "ABU - Admin Balance update"

            credit_transaction = Transaction()
            credit_transaction.txn_id =  txn_id
            credit_transaction.party =  form.email.data
            credit_transaction.counter_party =  "Admin"
            credit_transaction.amount =  form.amount.data
            credit_transaction.type =  'Cr'
            credit_transaction.reason =  reason

            db.session.add(user.balance)
            db.session.add(credit_transaction)
            db.session.commit()
            return redirect(url_for("user_page"))
        else:
            flash('Invalid User Id')
    return render_template("add_balance.html", form=form)
开发者ID:mthipparthi,项目名称:playnpay,代码行数:33,代码来源:app.py

示例2: add

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
def add(request, portfolio, is_sample, read_only):
  form = TransactionForm(request.POST)
  if form.is_valid():
    commission = form.cleaned_data.get('commission')
    if commission == None:
      commission = 0.0
    
    type = form.cleaned_data.get('type').encode('UTF-8')
    
    symbol = form.cleaned_data.get('symbol').encode('UTF-8').upper()
    linked_symbol = None
    if type == 'ADJUST':
      linked_symbol = symbol
      
    if type in ['DEPOSIT', 'WITHDRAW', 'ADJUST']:
      symbol = CASH_SYMBOL
    
    if symbol != None and len(symbol) > 0:
      transaction = Transaction()
      transaction.portfolio = portfolio
      transaction.type = type
      transaction.as_of_date = form.cleaned_data.get('as_of_date')
      transaction.symbol = symbol
      transaction.quantity = form.cleaned_data.get('quantity')
      transaction.price = form.cleaned_data.get('price')
      transaction.total = (transaction.quantity * transaction.price) + commission
      transaction.linked_symbol = linked_symbol
      transaction.save()
    
      refresh_positions(portfolio, force = True)
  
  return redirect_to_portfolio_action('transactions', portfolio)
开发者ID:andlister,项目名称:frano,代码行数:34,代码来源:views.py

示例3: process_import

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
def process_import(request, portfolio, is_sample, read_only):
  formset = ImportTransactionFormSet(request.POST)
  if not formset.is_valid():
    raise Exception('Invalid import set');
  
  for form in formset.forms:
    cd = form.cleaned_data
    
    if not cd.get('exclude'):
      transaction = Transaction()
      transaction.portfolio = portfolio
      transaction.type = cd.get('type').encode('UTF-8')
      transaction.as_of_date = cd.get('as_of_date')
      transaction.symbol = cd.get('symbol').encode('UTF-8').upper()
      transaction.quantity = cd.get('quantity')
      transaction.price = cd.get('price')
      transaction.total = cd.get('total')
      
      linked_symbol = cd.get('linked_symbol').encode('UTF-8')
      if linked_symbol != None and linked_symbol != '':
        transaction.linked_symbol = linked_symbol
        
      transaction.save()
    
  refresh_positions(portfolio, force = True)
  return redirect_to_portfolio_action('transactions', portfolio)
开发者ID:andlister,项目名称:frano,代码行数:28,代码来源:views.py

示例4: post

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
 def post(self):
    company = Company.query.get(request.form['company_id'])
    if company is None:
       return jsonify(message='Company does not exists')
    transaction = Transaction()
    transaction.company_id  = company.id
    transaction.type = request.form['type']
    transaction.amount = request.form['amount']
    transaction.date = request.form['date']
    db.session.add(transaction)
    db.session.commit()
    return jsonify(transaction.serialize)
开发者ID:sephtiger,项目名称:txmo-backend,代码行数:14,代码来源:application.py

示例5: charge_players

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
def charge_players():
    """For GET requests, display the login form. For POSTS, login the current user
    by processing the form."""

    form = ChargePlayersForm()
    if form.validate_on_submit():
        date_str = form.play_date.data
        total_amount = form.total_amount.data
        reason = form.reason.data

        play_date = parser.parse(date_str).date()
        played_date =  PlayScheduledDates.query.filter(PlayScheduledDates.play_date==play_date).first()

        attending_players = [ attendee for attendee in played_date.attendees if attendee.status=='Yes']

        total_players = len(attending_players) if len(attending_players) else 1
        amount_per_head =  total_amount/float(total_players)

        low_balance_users = {}

        for attendee in attending_players:
            user = User.query.get(attendee.attendee_email)
            if user:
                user.debit_balance(amount_per_head)

                txn_id = str(uuid.uuid4())[:8]
                debit_transaction = Transaction()
                debit_transaction.txn_id =  txn_id
                debit_transaction.party =  user.email
                debit_transaction.counter_party =  "Admin"
                debit_transaction.amount =  -amount_per_head
                debit_transaction.type =  'Dr'
                debit_transaction.reason = reason

                db.session.add(debit_transaction)
                db.session.add(user)

                if user.get_balance() < 10 :
                    low_balance_users[user.email] = (user.first_name, user.get_balance())

        played_date.is_charged = True;
        db.session.commit()
        send_bulk_emails(low_balance_users)   
        return redirect(url_for("user_page"))
    return render_template("charge_players.html", form=form)
开发者ID:mthipparthi,项目名称:playnpay,代码行数:47,代码来源:app.py

示例6: post

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
 def post(self, user_id):
     auth_key = request.args.get('key')
     user = User.authenticate(user_id, auth_key)
     if user:
         supposed_transaction = request.get_json(force=True)
         transaction = Transaction()
         transaction.user_id = user_id
         transaction.category_id = supposed_transaction['category_id']
         transaction.person_id = supposed_transaction['person_id']
         transaction.transaction_date = supposed_transaction['transaction_date']
         transaction.value = supposed_transaction['value']
         transaction.notes = supposed_transaction['notes']
         transaction.type = supposed_transaction['type']
         transaction.done = supposed_transaction['done']
         db.session.add(transaction)
         db.session.commit()
         if transaction.transaction_id:
             return json.jsonify(transaction.as_dict())
     return json.jsonify({})
开发者ID:felipemfp,项目名称:minhaeiroAPI,代码行数:21,代码来源:apis.py

示例7: post

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
 def post(self, username):
     user = self.authenticate()
     if user:
         supposed_transaction = request.get_json(force=True)
         transaction = Transaction()
         transaction.transaction_id = 1 if len(user.transactions.all(
         )) == 0 else user.transactions.all()[-1].transaction_id + 1
         transaction.user_id = user.user_id
         transaction.category_id = supposed_transaction['category_id']
         transaction.person_id = supposed_transaction['person_id']
         transaction.transaction_date = supposed_transaction[
             'transaction_date']
         transaction.value = supposed_transaction['value']
         transaction.notes = supposed_transaction['notes']
         transaction.type = supposed_transaction['type']
         transaction.done = supposed_transaction['done']
         db.session.add(transaction)
         db.session.commit()
         if transaction.transaction_id:
             return json.jsonify(transaction.as_dict())
     raise InvalidUsage()
开发者ID:felipemfp,项目名称:catherine,代码行数:23,代码来源:apis.py

示例8: send_money

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
def send_money():
    """For GET requests, display the login form. For POSTS, login the current user
    by processing the form."""

    form = PayForm()
    if form.validate_on_submit():

        transaction_amount = form.amount.data
        sender = current_user

        receiver = User.query.get(form.receiver_email.data)
        if receiver is None:
            flash('Receiver Does Not exist in system')
            return render_template("pay.html", form=form)

        if sender.balance is None or sender.balance.amount < transaction_amount:
            flash('You have insufficient balance')
            return render_template("pay.html", form=form)

        if transaction_amount <= 0:
            flash('Wrong amount entered')
            return render_template("pay.html", form=form)

        if sender.email == receiver.email:
            flash('Sender and Receiver Cant be same')
            return render_template("pay.html", form=form)            

        sender.debit_balance(transaction_amount)
        receiver.credit_balance(transaction_amount)

        txn_id = str(uuid.uuid4())[:8]
        reason = "SNM - Send Money"

        debit_transaction = Transaction()
        debit_transaction.txn_id =  txn_id
        debit_transaction.party =  sender.email
        debit_transaction.counter_party =  receiver.email
        debit_transaction.amount =  -transaction_amount
        debit_transaction.type =  'Dr'
        debit_transaction.reason = reason

        credit_transaction = Transaction()
        credit_transaction.txn_id =  txn_id
        credit_transaction.party =  receiver.email
        credit_transaction.counter_party =  sender.email
        credit_transaction.amount =  transaction_amount
        credit_transaction.type =  'Cr'
        credit_transaction.reason =  reason


        db.session.add(sender.balance)
        db.session.add(receiver.balance)
        db.session.add(debit_transaction)
        db.session.add(credit_transaction)
        db.session.commit()

        if current_user.get_balance() < 10 :
            send_low_balance_email(current_user.email, current_user.first_name, current_user.get_balance())

        return redirect(url_for("user_page"))

    return render_template("send_money.html", form=form)
开发者ID:mthipparthi,项目名称:playnpay,代码行数:64,代码来源:app.py

示例9: transfer_funds

# 需要导入模块: from models import Transaction [as 别名]
# 或者: from models.Transaction import type [as 别名]
def transfer_funds(tokens, sender_number):
    """
    Transfer funds to user or non-user
    Expected format: 'transfer [amount] [receiver] [pin]'
    
    transaction limit: NGN3,000
    daily transaction limit: NGN30,000
    """
    messages = []
    try:
        amount = float(tokens[1])
        receiver_number = tokens[2]
        pin = tokens[3]
        
        user = User.objects.get(phone=sender_number)
        if not validate_pin(user, pin):
            return msg_invalid_pin(user.phone)
        
        if not account_activated(user):
            return msg_account_not_activated(user.phone)
        
        # check account balance
        if amount > (user.balance - 100):
            msg = ("You do not have enough balance to make this transfer.")
            sms = OutgoingMessage(body=msg, receiver=sender_number,
                                  timestamp=time.time(), 
                                  type='insufficient_balance')
            messages.append(sms)
            return send_sms(messages)
        
        if amount > 3000:
            msg = ("You cannot transfer above NGN3,000 in one transaction."
                   " Please try again.")
            sms = OutgoingMessage(body=msg, receiver=sender_number,
                                  timestamp=time.time(), type='excess_transfer')
            messages.append(sms)
            return send_sms(messages)
        
        # add restriction of daily limit of 3ok
        
        # validate receiver exists
        #     if not generate cash out ticket instead
        transaction = Transaction(
            id=util.generate_uuid()[0:12], sender=user.phone, 
            receiver=receiver_number, timestamp=time.time(), amount=amount)
        try:
            User.objects.get(phone=receiver_number)
            transaction.type = 'user_to_user_transfer'
        except User.DoesNotExist:
            transaction.type = 'user_to_guest_transfer'
            
        transaction.save()
        
        # return message to confirm transaction
        msg = ("transaction-id: %s, amount: %s, receiver: %s. Please"
               " reply this message with 'confirm' to confirm this"
               " transaction." 
               % (transaction.id, transaction.amount, transaction.receiver))
        sms = OutgoingMessage(body=msg, receiver=sender_number,
                              timestamp=time.time(), meta=transaction,
                              type='confirm_transaction')
        messages.append(sms)
        return send_sms(messages)
        
    except User.DoesNotExist:
        return msg_user_does_not_exist(sender_number)
    
    except IndexError:
        expected_format = ("Unknown message format. Expeted format: transfer"
                           " [amount] [receiver] [pin]. Please try again.")
        return msg_unknown_format(expected_format, sender_number)
开发者ID:stackempty,项目名称:mopay,代码行数:73,代码来源:actions.py


注:本文中的models.Transaction.type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。