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


Python Stock.get方法代码示例

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


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

示例1: test_create_outgoing

# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import get [as 别名]
 def test_create_outgoing(self):
     """Create an outgoing record."""
     Category.create(category_id='001', description='Testing Stock')
     Project.create(project_id='001', project_description="Testing")
     Role.create(role_name='Admin')
     User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='JayPalm',
                 password='jfresh13', email='[email protected]')
     create_stock('001', 'Testing stock', 1, '001', 9.99)
     create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='JayPalm')
     OutgoingStock.get(OutgoingStock.stock == '001').delete_instance()
     Stock.get(Stock.category == '001').delete_instance()
     User.get(User.username == 'JayPalm').delete_instance()
     Role.get(Role.role_name == 'Admin').delete_instance()
     Project.get(Project.project_id == '001').delete_instance()
     Category.get(Category.category_id == '001').delete_instance()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:17,代码来源:tests.py

示例2: add_existing_stock

# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import get [as 别名]
def add_existing_stock(pk_id, to_add):
    """Increase quantity for a specified record by pk_id.
    pk_id: primary key id
    """
    stock = Stock.get(
        Stock.id == pk_id
    )
    current_quantity = stock.quantity
    new_quantity = current_quantity + to_add
    query = Stock.update(
        quantity=new_quantity
    ).where(
        Stock.id == pk_id
    )
    return query.execute()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:17,代码来源:stock.py

示例3: delete_stock

# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import get [as 别名]
def delete_stock(pk_id):
    """Delete a specified record/stock.
    pk_id: primary key, or stock to be deleted.
    """
    return Stock.get(Stock.id == pk_id).delete_instance()
开发者ID:dsantosp12,项目名称:NapAdmin,代码行数:7,代码来源:stock.py

示例4: order

# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import get [as 别名]
def order(stock_id=None, quantity=""):
    quantity = int(quantity)

    if quantity != "" and quantity > 0:  # validate the quantity given
        stock = Stock.get(Stock.id == stock_id)

        orders = (
            Order.select(fn.sum(Order.quantity)).where(Order.stock == stock.id).scalar()
        )  # Get the current number of orders

        if orders == None:  # I don't want a TypeError below
            orders = 0

        if quantity <= (
            stock.minimum_quantity - orders
        ):  # verify if quantity is less than or equal to the needed orders
            price = quantity * stock.price  # calculate the amount the buyer has to pay
            Order.make_order(buyer=1, stock=stock, quantity=quantity, price=price)

            if (
                stock.minimum_quantity == Order.select(fn.sum(Order.quantity)).where(Order.stock == stock.id).scalar()
            ):  # check if the target has been met
                stock.bought = True  # update stock and set it to saved
                stock.save()
                orders = Stock.get(Stock.id == stock_id).orders

                for order in orders:
                    order.ready = True
                    order.save()

                    # replace the old stock with a fresh one with no orders yet
                new_stock = Stock.enter_stock(
                    product=stock.product,
                    first_description=stock.first_description,
                    second_description=stock.second_description,
                    third_description=stock.third_description,
                    unit=stock.unit,
                    quantity=stock.quantity,
                    minimum_quantity=stock.minimum_quantity,
                    brand=stock.brand,
                    supplier=stock.supplier,
                    price=stock.price,
                )

                # send SMS's to shippers notifying them of ready deliveries
                for order in stock.orders:
                    shippers = Courier.select()

                    for shipper in shippers:
                        # Account Sid and Auth Token from twilio.com/user/account
                        account_sid = "AC7c8362f62f825e5184fe40e25958623d"
                        auth_token = "834c6ea95160009d251b3f06893768b2"
                        client = TwilioRestClient(account_sid, auth_token)

                        message = client.messages.create(
                            body="Shipping: {} to {}. Reply with your price".format(
                                order.stock.supplier.address, order.buyer.address
                            ),
                            to="+{}".format(str(shipper.phone)),
                            from_="+14782885892",
                        )
                        print(message.sid)

    return redirect(url_for("index"))
开发者ID:RoundRound,项目名称:round,代码行数:66,代码来源:site.py


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