Esempio n. 1
0
 def get(self):
     statuses = list(NOT_CANCELED_STATUSES)
     statuses.remove(READY_ORDER)
     namespace_orders = {}
     for namespace in metadata.get_namespaces():
         namespace_manager.set_namespace(namespace)
         resto = RestoCompany.get()
         if resto:
             continue
         orders = Order.query(Order.status.IN(statuses),
                              Order.delivery_time < datetime.utcnow() - timedelta(hours=HOURS_BEFORE)).fetch()
         if orders:
             logging.info('-----------------------------')
             namespace_orders[namespace] = orders
         for order in orders:
             logging.info("closing order id=%s, namespace=%s" % (order.key.id(), namespace))
             try:
                 done_order(order, namespace, with_push=False)
             except Exception as e:
                 admins.send_error("closing", "In closing orders occur error!!!", str(e))
     mail_body = u"List of orders not closed:\n"
     for namespace in namespace_orders.keys():
         mail_body += u'In namespace = %s:\n' % namespace
         namespace_manager.set_namespace(namespace)
         for order in namespace_orders[namespace]:
             venue = Venue.get_by_id(order.venue_id)
             venue_title = venue.title if venue else u'Не определено'
             mail_body += u'%s (%s),\n' % (order.key.id(), venue_title)
     if namespace_orders:
         namespace_manager.set_namespace('')
         admins.send_error("order", "Orders not closed", mail_body)
Esempio n. 2
0
 def post(self):
     order_id = int(self.request.get('order_id'))
     order = Order.get_by_id(order_id)
     if not order:
         self.abort(400)
     old_status = order.status
     done_order(order, namespace_manager.get_namespace())
     self.render_json(_order_json(order, old_status))
Esempio n. 3
0
 def get(self):
     email_key = self.request.get('key')
     if not email_key:
         self.abort(403)
     order = Order.query(Order.email_key_done == email_key).get()
     if not order:
         return self.response.write(
             u'Невозможно выдать заказ. Возможно, он отменен.')
     done_order(order, namespace_manager.get_namespace())
     self.response.write(u'Заказ успешно выдан!')
Esempio n. 4
0
 def post(self, order_id):
     order = self.user.order_by_id(int(order_id))
     if order.status != ON_THE_WAY:
         self.abort(400)
     done_order(order, self.user.namespace)
     self.render_json({
         "success":
         True,
         "delivery_time":
         timestamp(order.delivery_time),
         "actual_delivery_time":
         timestamp(order.actual_delivery_time)
     })
Esempio n. 5
0
 def post(self, order_id):
     order = self.user.order_by_id(int(order_id))
     if order.status not in [NEW_ORDER, CONFIRM_ORDER]:
         self.abort(400)
     if order.status == NEW_ORDER and (order.delivery_type
                                       in [DELIVERY, PICKUP]
                                       and config.APP_KIND == AUTO_APP):
         return self.render_error(u'Необходимо сначала подтвердить заказ')
     try:
         done_order(order, self.user.namespace)
     except Exception as e:
         send_error('Close error', 'Barista error in closing order', str(e))
         return self.render_error(
             u'Непредвиденная ошибка! Повторите позднее! Не отменяйте заказ, если он уже оплачен!'
         )
     self.render_json({
         "success":
         True,
         "delivery_time":
         timestamp(order.delivery_time),
         "actual_delivery_time":
         timestamp(order.actual_delivery_time)
     })