def post(self, company_id): c = CompanyNew.get_by_id(int(company_id)) if 'reload' in self.request.params: _load_delivery_terminals(c) time.sleep(0.5) dts = DeliveryTerminal.query(DeliveryTerminal.company_id == c.key.id()).fetch() else: dts = DeliveryTerminal.query(DeliveryTerminal.company_id == c.key.id()).fetch() for dt in dts: param_name = 'active_%s' % dt.key.id() dt.active = bool(self.request.get(param_name)) ndb.put_multi(dts) self.render('company/terminals/list.html', company=c, dts=dts)
def get(self): now = datetime.datetime.now() delta = datetime.timedelta(minutes=MINUTES_INTERVAL) orders = Order.query(Order.status == Order.CREATING, Order.created <= now - delta).fetch() if orders: infos = [] for order in orders: info = [("id", order.order_id), ("payment type", order.payment_type), ("payment id", order.alfa_order_id)] to_delete = False iiko_order = order_info1(order.order_id, order.venue_id) if 'httpStatusCode' not in iiko_order: info.append(('found', True)) order.load_from_object(iiko_order) else: if order.payment_type == PaymentType.CARD: try: company = CompanyNew.get_by_iiko_id(order.venue_id) delivery_terminal = DeliveryTerminal.get_by_id(order.delivery_terminal_id) \ if order.delivery_terminal_id else None # check payment status status = alfa_bank.check_extended_status( company, delivery_terminal, order.alfa_order_id)["alfa_response"] info.append(("status check result", status)) # if status check was successful: if str(status.get("errorCode", '0')) == '0': # money already deposited -- do not delete if status['orderStatus'] == 2: info.append(("ERROR", "deposited")) # money approved -- reverse elif status['orderStatus'] == 1: reverse_result = alfa_bank.get_back_blocked_sum( company, delivery_terminal, order.alfa_order_id) info.append( ("reverse result", reverse_result)) if str(reverse_result.get( 'errorCode', '0')) == '0': to_delete = True # any other status is OK to delete else: to_delete = True except Exception as e: info.append(("exception", repr(e))) else: to_delete = True if to_delete: order.key.delete() info.append(("deleted", True)) infos.append(info) mail_body = "Orders with creating status\n" mail_body += "List of orders:\n" + \ "\n\n".join("\n".join("%s: %s" % t for t in info) for info in infos) admin.send_error("order", "Orders crashed while creating", mail_body)
def post(self, order_id): order = Order.order_by_id(order_id) meal_rate = float(self.request.get('meal_rate')) service_rate = float(self.request.get('service_rate')) comment = self.request.get('comment') rate = OrderRate(meal_rate=meal_rate, service_rate=service_rate, comment=comment) order.rate = rate order.put() is_negative = 0 < meal_rate < 4 or 0 < service_rate < 4 if is_negative or rate.comment: company = CompanyNew.get_by_iiko_id(order.venue_id) customer = order.customer.get() dt = DeliveryTerminal.get_by_id(order.delivery_terminal_id) body = u"Клиент: %s %s<br>" \ u"Заказ №%s<br>" \ u"Точка: %s<br>" \ u"Оценка еды: %d из 5<br>" \ u"Оценка обслуживания: %d из 5<br>" % \ (customer.phone, customer.name, order.number, dt.name, meal_rate, service_rate) if comment: body += u"Комментарий: %s" % comment logging.info(body) to = company.support_emails cc = ['*****@*****.**', '*****@*****.**'] subject = u'Негативный отзыв о заказе' if is_negative else u'Отзыв о заказе с комментарием' mandrill.send_email('*****@*****.**', to, cc, subject, body) self.render_json({})
def get_iikonet_payment_type(order): _default = "INET" if order.venue_id == CompanyNew.ORANGE_EXPRESS: city = order.address.get("city") if order.address else None return { u"Егорьевск": "INET1", u"Одинцово": "INET2", u"Домодедово": "INET3", u"Подольск": "INET4", u"Климовск": "INET4", u"Авиагородок": "INET6", }.get(city, _default) elif order.venue_id == CompanyNew.SUSHILAR: logging.info(order.delivery_terminal_id) if order.delivery_terminal_id == '088bab87-eb17-6deb-0147-a9d8fd1184b5': # ПАРИНА return 'PA' elif order.delivery_terminal_id == '088bab87-eb17-6deb-0147-a9f3a0380c68': # ХАДИ-ТАКТАШ return 'HA' elif order.delivery_terminal_id == '088bab87-eb17-6deb-0147-a9f3a038cf7e': # ВОССТАНИЯ return 'VO' elif order.delivery_terminal_id == '0d81e7d2-daf2-f7a8-0147-aa2667ef2e82': # ЯМАШЕВА return 'YAYA' elif order.delivery_terminal_id == '0e7bd2d0-c748-b906-0147-ee6188bfbb7d': # БЕГИЧЕВА return 'BI' elif order.delivery_terminal_id == '2e613146-b7bb-94e1-0149-3cf1753e76e2': # АДОРАТСКОГО return 'AO' else: return 'PA' # default if not order.is_delivery: dt = DeliveryTerminal.get_by_id(order.delivery_terminal_id) if dt.platius_payment_code: return dt.platius_payment_code return _default
def close(order): company = CompanyNew.get_by_iiko_id(order.venue_id) if company.auto_token and order.source == AUTO_APP_SOURCE: close_order(order, company.auto_token) if order.payment_type == PaymentType.CARD: delivery_terminal = DeliveryTerminal.get_by_id(order.delivery_terminal_id) \ if order.delivery_terminal_id else None pay_result = pay_by_card(company, delivery_terminal, order.alfa_order_id, 0) logging.info("pay result: %s" % str(pay_result)) success = 'errorCode' not in pay_result.keys() or str( pay_result['errorCode']) == '0' if not success: logging.warning("pay failed") return if company.is_iiko_system: bonus = SharedBonus.query( SharedBonus.recipient == order.customer, SharedBonus.status == SharedBonus.READY).get() if bonus: taskqueue.add(url='/single_task/bonus/activate', params={'order_id': order.order_id}) order_user_agent = order.customer.get().user_agent if company.review_enable and supports_review(company.iiko_org_id, order_user_agent): taskqueue.add(url='/single_task/push/review', params={'order_id': order.order_id}, countdown=60 * 30) send_order_status_push(order)
def post(self, company_id, terminal_id): dt = DeliveryTerminal.get_by_id(terminal_id) assert dt.company_id == int(company_id) dt.name = self.request.get('name') dt.address = self.request.get('address') dt.location = ndb.GeoPt(self.request.get('location')) dt.phone = self.request.get('phone') dt.active = bool(self.request.get('active')) dt.schedule = ast.literal_eval(self.request.get('schedule')) dt.alpha_login = self.request.get('alpha_login') dt.alpha_pass = self.request.get('alpha_pass') dt.platius_payment_code = self.request.get('platius_payment_code') dt.put() self.redirect('/mt/company/%s/terminals' % company_id)
def cancel(order): company = CompanyNew.get_by_iiko_id(order.venue_id) if company.auto_token and order.source == AUTO_APP_SOURCE: cancel_order(order, company.auto_token) if order.venue_id == CompanyNew.ORANGE_EXPRESS: oe_cancel.handle_cancel(order) else: if order.payment_type == PaymentType.CARD: delivery_terminal = DeliveryTerminal.get_by_id(order.delivery_terminal_id) \ if order.delivery_terminal_id else None cancel_result = get_back_blocked_sum(company, delivery_terminal, order.alfa_order_id) logging.info("cancel %s" % str(cancel_result)) success = 'errorCode' not in cancel_result or str(cancel_result['errorCode']) == '0' if not success: logging.warning("cancel failed") return send_order_status_push(order)
def get(self, company_id, terminal_id): dt = DeliveryTerminal.get_by_id(terminal_id) assert dt.company_id == int(company_id) self.render('company/terminals/edit.html', dt=dt)
def get(self, company_id): c = CompanyNew.get_by_id(int(company_id)) dts = DeliveryTerminal.query(DeliveryTerminal.company_id == c.key.id()).fetch() self.render('company/terminals/list.html', company=c, dts=dts)