當前位置: 首頁>>代碼示例>>Python>>正文


Python Transaction.reason方法代碼示例

本文整理匯總了Python中models.Transaction.reason方法的典型用法代碼示例。如果您正苦於以下問題:Python Transaction.reason方法的具體用法?Python Transaction.reason怎麽用?Python Transaction.reason使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Transaction的用法示例。


在下文中一共展示了Transaction.reason方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_balance

# 需要導入模塊: from models import Transaction [as 別名]
# 或者: from models.Transaction import reason [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: charge_players

# 需要導入模塊: from models import Transaction [as 別名]
# 或者: from models.Transaction import reason [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

示例3: send_money

# 需要導入模塊: from models import Transaction [as 別名]
# 或者: from models.Transaction import reason [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


注:本文中的models.Transaction.reason方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。