本文整理汇总了Python中models.order.Order类的典型用法代码示例。如果您正苦于以下问题:Python Order类的具体用法?Python Order怎么用?Python Order使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Order类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: job_package
def job_package():
# Log.info("请异步发送")
need_do = ''
orders = Order.get_working_orders()
for order in orders:
product = Product.lookup(order['p_id'])
exchange = Exchange.get_exchange(order['e_id'])
packages = Package.getPackageByName(order['package_id'])
for package in packages:
need_do = need_do+json.dumps({'port':product['port'],'bandwidth':order['bandwidth'],\
'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \
'package_id':package['package_name']})
# Order.finish_order(order['_id'])
need_back=''
orders = Order.get_back_orders()
for order in orders:
custom_time = order['custom_time']
product = Product.lookup(order['p_id'])
exchange = Exchange.look(order['e_id'])
packages = Package.getPackageByName(order['package_id'])
for package in packages:
need_back = need_back+json.dumps({'port':product['port'],'ex_bandwidth':order['bandwidth'],\
'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \
'package_id':package['package_name']})
# Order.back_order(order['_id'])
print 'set_package_job end at ',datetime.datetime.now()
示例2: post
def post(self):
cname = self.get_argument("cname", None)
oname = self.get_argument("oname", None)
percent = self.get_argument("percent", None)
begin_at = datetime.datetime.strptime(self.get_argument("begin_at", None),"%m/%d/%Y %H:%M")
suspended_at = datetime.datetime.strptime(self.get_argument("suspended_at", None),"%m/%d/%Y %H:%M")
p_id = self.get_argument("p_id", None)
Order.insert(cname, oname, p_id, percent, begin_at, suspended_at)
self.finish("finished<script>parent.closeDialog();</script>")
示例3: test_order
def test_order(session):
order = add_order()
order2 = Order.get(order.id)
assert order2 is not None
user2 = add_user('testuser2', 'pwd')
order.designers = [user2]
order3 = Order.get(order.id)
assert user2 in order3.designers
示例4: post
def post(self, request):
# 添加订单
try:
customer = request.u
note = request.json.get("note")
delivery_information_id = request.json.get("delivery_information_id")
store_id = request.json.get("store_id")
food_list = request.json.get("food_list")
store = Store.objects.get(id=store_id)
total_price = 0
if not all([food_list, delivery_information_id, store]):
return JsonErrorResponse("food_list, delivery_information_id, store_id are needed", 400)
# 检查food_list
assert isinstance(food_list, list) and len(food_list) > 0, "food_list format wrong"
# 检查库存+计算价格
for order_food in food_list:
food = store.foods.get(id=order_food['food_id'])
food_count = int(order_food['count'])
total_price += food.price * food_count
assert food.stock > food_count, "food stock is not enough"
# 检查收货信息
delivery_information = customer.delivery_informations.get(id=delivery_information_id)
# 检查账户类型
assert request.account_type == "customer", "only customer can make order"
# 创建order
new_order = Order(
note=note,
total_price=total_price,
customer=customer,
store=store,
delivery_information=delivery_information
)
new_order.save()
# 减少库存,创建order_food
for order_food in food_list:
food = store.foods.get(id=order_food['food_id'])
food_count = int(order_food['count'])
new_stock = food.stock - food_count
store.foods.filter(id=order_food['food_id']).update(stock=new_stock)
OrderFood(
count=food_count,
food=food,
order=new_order
).save()
except Exception, e:
print e
return JsonErrorResponse("Fail:" + e.message)
示例5: test_normal_scenario_with_two_users
def test_normal_scenario_with_two_users(self):
# First create some users
user1 = User.create_user(self.session, "user1", "abcd")
user2 = User.create_user(self.session, "user2", "abcd")
# Make sure user1 has 1 BTC for later deposit into a futures contract
btc = Asset.create_asset("BTC")
user1.increase_volume_of_asset(self.session, btc, Decimal("1"))
# Create a futures contract worth 1 BTC in +14 days
contract, asset = FuturesContract.create_contract(
self.session, user1, datetime.now() + timedelta(days=14), btc, Decimal("1"), "FUTURE", Decimal("100")
)
# This will fail if user1 has insufficient funds (i.e. < 1 BTC)
assert contract is not None
assert asset is not None
self.session.commit()
# Create an order for this contract (i.e. newly created asset)
usd = Asset.create_asset("USD")
ask_order = Order.create_order(
self.session, user1, Decimal("20"), usd, contract, Decimal("50"), False, OrderType.limit_order.value
)
# Make sure we have enough funds
assert ask_order is not None
self.session.commit()
# Put order into market
assert put_order(self.session, ask_order) is None
# Create a bid order from user2
user2.increase_volume_of_asset(self.session, usd, Decimal("20"))
bid_order1 = Order.create_order(
self.session, user2, Decimal("20"), usd, contract, Decimal("50"), True, OrderType.limit_order.value
)
# Make sure we have enough funds
assert bid_order1 is not None
transaction = put_order(self.session, bid_order1)
assert isinstance(transaction, Transaction)
assert transaction.ask_order is ask_order
assert transaction.bid_order is bid_order1
contract.expire(self.session)
assert user1.volume_of_asset(self.session, btc) == Decimal("0.5")
assert user2.volume_of_asset(self.session, btc) == Decimal("0.5")
# Run it again. Must be idempotent.
contract.expire(self.session)
assert user1.volume_of_asset(self.session, btc) == Decimal("0.5")
assert user2.volume_of_asset(self.session, btc) == Decimal("0.5")
示例6: GetContext
def GetContext(self):
tAgent = Agent()
tAgentList = []
tAgentOrders = []
tAgentDonations = []
tAgentRequest = self.request.get('agent')
context = {}
tAgentList = Agent.all()
context['agents'] = tAgentList
if (tAgentRequest != ""):
tAgent = Agent.get(tAgentRequest)
tAgentOrdersQuery = Order.all()
tAgentOrdersQuery.filter('orderAgent', str(tAgentRequest))
tAgentOrdersQuery.order('-orderCompleted')
tAgentOrders = tAgentOrdersQuery.fetch(100)
tAgentDonorsQuery = DonorRecord.all()
tAgentDonorsQuery.filter('donorAgent', tAgent.agentId)
tAgentDonorsQuery.order('-donorDate')
tAgentDonations = tAgentDonorsQuery.fetch(100)
#logging.debug("Agent Order Count: " + str(len(tAgentOrders)))
#logging.debug("Agent Donation Count: " + str(len(tAgentDonations)))
context['agent'] = tAgent
context['orders'] = tAgentOrders
context['donations'] = tAgentDonations
context['extended'] = 'True'
return context
示例7: items_status_update
def items_status_update(order_id, step):
order = Order.get(order_id)
if not order:
abort(404)
item_ids = request.form.getlist('item_id')
leaders = request.form.getlist('leader')
if not item_ids:
flash(u"请选择订单项")
else:
action = int(request.form.get('action'))
if action in STATUS_APPLLY:
if not leaders:
flash(u"请选择Leader")
return redirect(url_for('schedule.order_detail', order_id=order.id, step=step))
else:
apply = ChangeStateApply(step, action, [User.get(m).email for m in leaders], order)
order_apply_signal.send(current_app._get_current_object(), change_state_apply=apply)
flash(u"请在2个自然日内与审核Leaer联系")
if action in ITEM_STATUS_LEADER_ACTIONS:
apply = ChangeStateApply(
step,
action,
[order.creator.email],
order)
reply_apply_signal.send(current_app._get_current_object(), change_state_apply=apply)
items = AdItem.gets(item_ids)
AdItem.update_items_with_action(items, action, g.user)
msg = '\n\n'.join(['%s : %s' % (item.name, ITEM_STATUS_ACTION_CN[action]) for item in items])
order.add_comment(g.user, msg)
flash(u'%s个排期项%s。请将理由在留言板上留言说明' % (len(items), ITEM_STATUS_ACTION_CN[action]))
step = AdItem.get_next_step(step, action)
return redirect(url_for('schedule.order_detail', order_id=order.id, step=step))
示例8: new_outsource
def new_outsource():
form = OutsourceForm(request.form)
order = Order.get(form.medium_order.data)
try:
int(form.num.data)
except:
flash(u'保存失败,金额必须为数字!', 'danger')
return redirect(url_for("outsource.client_outsources", order_id=order.client_order.id))
status = 0
if g.user.is_super_leader():
status = 2
outsource = OutSource.add(target=OutSourceTarget.get(form.target.data),
medium_order=order,
num=form.num.data,
type=form.type.data,
subtype=form.subtype.data,
remark=form.remark.data,
invoice=False,
status=status,
pay_num=form.num.data,)
flash(u'新建外包成功!', 'success')
outsource.client_order.add_comment(g.user,
u"""新建外包:\n\r %s""" % outsource.name,
msg_channel=2)
if g.user.is_super_leader():
_insert_executive_report(order, rtype='reload')
return redirect(outsource.info_path())
示例9: back_money
def back_money(order_id):
if not g.user.is_finance():
abort(404)
client_order = ClientOrder.get(order_id)
back_moneys = MediumBackMoney.query.filter_by(client_order_id=order_id)
if not client_order:
abort(404)
if request.method == 'POST':
money = float(request.values.get('money', 0))
back_time = request.values.get(
'back_time', datetime.date.today().strftime('%Y-%m-%d'))
medium_id = request.values.get('medium')
order = Order.get(medium_id)
MediumBackMoney.add(client_order_id=order_id,
order_id=medium_id,
money=money,
back_time=back_time)
client_order.add_comment(g.user, u"更新了媒体返点回款信息,所属媒体:%s; 回款金额: %s; 回款时间: %s;" % (
order.medium.name, money, back_time), msg_channel=8)
apply_context = {
'order': client_order,
'num': money,
'type': 'money',
}
medium_back_money_apply_signal.send(
current_app._get_current_object(), apply_context=apply_context)
flash(u'回款信息保存成功!', 'success')
return redirect(url_for('finance_client_order_medium_back_money.back_money', order_id=order_id))
return tpl('/finance/client_order/medium_back_money/info.html', order=client_order, back_moneys=back_moneys)
示例10: order_items
def order_items(order_id):
order = Order.get(order_id)
if not order:
abort(404)
context = {'order': order,
'SALE_TYPE_CN': SALE_TYPE_CN}
return tpl('order_detail_ordered.html', **context)
示例11: index
def index():
if not g.user.is_super_admin():
abort(403)
form = ClientOrderForm(request.form)
mediums = [(m.id, m.name) for m in Medium.all()]
if request.method == 'POST' and form.validate():
if ClientOrder.query.filter_by(contract=request.values.get('contract')).count() > 0:
flash(u'合同号已存在', 'danger')
return redirect(url_for('util_insert_orders.index'))
order = ClientOrder.add(agent=Agent.get(form.agent.data),
client=Client.get(form.client.data),
campaign=form.campaign.data,
money=int("%.0f" % (form.money.data or 0)),
client_start=form.client_start.data,
client_end=form.client_end.data,
reminde_date=form.reminde_date.data,
direct_sales=User.gets(form.direct_sales.data),
agent_sales=User.gets(form.agent_sales.data),
contract_type=form.contract_type.data,
resource_type=form.resource_type.data,
sale_type=form.sale_type.data,
contract=request.values.get('contract', ''),
creator=g.user,
contract_status=2,
create_time=datetime.now())
order.add_comment(g.user,
u"导入了客户订单:%s - %s - %s" % (
order.agent.name,
order.client.name,
order.campaign
))
medium_ids = request.values.getlist('medium')
medium_moneys = request.values.getlist('medium_money')
medium_moneys2 = request.values.getlist('medium_money2')
medium_contracts = request.values.getlist('medium_contract')
if medium_ids and medium_moneys and len(medium_ids) == len(medium_moneys):
for x in range(len(medium_ids)):
medium = Medium.get(medium_ids[x])
mo = Order.add(campaign=order.campaign,
medium=medium,
sale_money=int("%.0f" % (form.money.data or 0)),
medium_money=int(medium_moneys[x] or 0),
medium_money2=int(medium_moneys2[x] or 0),
medium_contract=medium_contracts[x],
medium_start=order.client_start,
medium_end=order.client_end,
creator=g.user)
order.medium_orders = order.medium_orders + [mo]
order.add_comment(g.user, u"导入了媒体订单: %s %s元" %
(medium.name, mo.sale_money))
order.save()
flash(u'导入客户订单成功!', 'success')
insert_executive_report(order, '')
return redirect(order.info_path())
else:
form.client_start.data = datetime.now().date()
form.client_end.data = datetime.now().date()
form.reminde_date.data = datetime.now().date()
return tpl('insert_order.html', form=form, mediums=mediums)
示例12: index
def index():
data = request.args.to_dict()
filtering_state = data.get('state__icontains', '')
criteria = {'state__icontains': str(filtering_state)}
orders = Order.objects(**criteria)
return render.template('admin/order/index.html', orders=orders)
示例13: GetContext
def GetContext(self):
tContext = {}
tOrderKey = str(urllib.unquote(self.request.get('key')))
if(tOrderKey != None and len(tOrderKey) > 0):
tOrder = Order.get(tOrderKey)
tContext['tOrder'] = tOrder
return tContext
示例14: post
def post(self):
cname = self.get_argument("cname", None)
oname = self.get_argument("oname", None)
percent = self.get_argument("percent", None)
begin_at = self.get_argument("begin_at", None)
suspended_at = self.get_argument("suspended_at", None)
p_id = self.get_argument("p_id", None)
o_id = Order.insert(cname,oname,p_id,percent,begin_at,suspended_at)
self.finish("finished<script>parent.closeDialog();</script>")
示例15: test_cancel_contract
def test_cancel_contract(self):
# Create a user and asset
user = User.create_user(self.session, "user", "abcd")
usd = Asset.create_asset("USD")
self.session.add_all([user, usd])
self.session.commit()
# Add funds to user1 so that we can create a contract
user.increase_volume_of_asset(self.session, usd, Decimal("1"))
# Let this user create a contract
contract, asset = FuturesContract.create_contract(
self.session, user, datetime.now() + timedelta(days=14), usd, Decimal("1"), "FUTURE", Decimal("100")
)
assert contract is not None
assert asset is not None
# Now, money have been withdrawn from user1's account
assert user.volume_of_asset(self.session, usd) == Decimal("0")
# Cancel the contract
assert contract.cancel(self.session) is True
assert inspect(contract).deleted is True
assert user.volume_of_asset(self.session, usd) == Decimal("1")
# OK, the contract is cancelled.
# Now do the same thing, but this time, create an order and verify that the cancelled flag is set instead
contract, asset = FuturesContract.create_contract(
self.session, user, datetime.now() + timedelta(days=14), usd, Decimal("1"), "FUTURE", Decimal("100")
)
assert contract is not None
assert asset is not None
assert user.volume_of_asset(self.session, usd) == Decimal("0")
ask_order = Order.create_order(
self.session, user, Decimal("20"), usd, contract, Decimal("50"), False, OrderType.limit_order.value
)
assert ask_order is not None
assert user.volume_of_asset(self.session, asset) == Decimal("50")
# Assert that we cannot cancel the contract if there are created orders
assert contract.cancel(self.session) is False
# Put order into market
assert put_order(self.session, ask_order) is None
# Assert that we cannot cancel the contract if there are orders in the market
assert contract.cancel(self.session) is False
# It should be possible to cancel this order
assert ask_order.cancel(self.session) is True
assert user.volume_of_asset(self.session, asset) == Decimal("100")
# Check that order is in the expected state
assert contract.cancel(self.session) is True
assert inspect(contract).deleted is False
assert contract.cancelled is True