Beispiel #1
0
 def get(self):
     companies = CompanyNew.query().fetch()
     for company in companies:
         try:
             get_menu(company.iiko_org_id, force_reload=True)
         except Exception as e:
             logging.exception(e)
Beispiel #2
0
 def get(self):
     token = self.request.get("token")
     admin = Admin.query(Admin.token == token).get()
     if not admin:
         self.abort(401)
     menu = get_menu(admin.company_id)
     processed_menu = [_process_category(c) for c in menu]
     self.render_json({"menu": processed_menu})
Beispiel #3
0
 def get(self, company_id):
     company = CompanyNew.get_by_id(int(company_id))
     force_reload = "reload" in self.request.params
     filtered = "all" not in self.request.params
     menu = get_menu(company.iiko_org_id,
                     force_reload=force_reload,
                     filtered=filtered)
     if company.iiko_org_id == CompanyNew.COFFEE_CITY:
         menu = fix_syrop.set_syrop_modifiers(menu)
         menu = fix_modifiers_by_own.remove_modifiers(menu)
     add_additional_categories(company, menu)
     self.render_json({'menu': menu})
Beispiel #4
0
def _build_images_map(org_id):
    menu = get_menu(org_id)
    images_map = {}

    def process_category(category):
        for product in category['products']:
            images_map[product['productId']] = product['images']
        for subcategory in category['children']:
            process_category(subcategory)
    for c in menu:
        process_category(c)

    return images_map
Beispiel #5
0
 def get(self, delivery_terminal_id):
     delivery_terminal = DeliveryTerminal.get_by_id(delivery_terminal_id)
     if delivery_terminal:
         iiko_org_id = delivery_terminal.iiko_organization_id
     else:
         iiko_org_id = delivery_terminal_id
     force_reload = "reload" in self.request.params
     filtered = "all" not in self.request.params
     menu = get_menu(iiko_org_id,
                     force_reload=force_reload,
                     filtered=filtered)
     if iiko_org_id == CompanyNew.COFFEE_CITY:
         menu = fix_syrop.set_syrop_modifiers(menu)
         menu = fix_modifiers_by_own.remove_modifiers(menu)
     add_additional_categories(CompanyNew.get_by_iiko_id(iiko_org_id), menu)
     self.render_json({'menu': menu})
Beispiel #6
0
    def get(self, company_id):
        company = CompanyNew.get_by_id(int(company_id))
        menu = get_menu(company.iiko_org_id, force_reload=True)

        def process_category(category, names, dst):
            names.append(category['name'])
            if category['products']:
                dst.append((" > ".join(names), category['products']))
            for subcat in category['children']:
                process_category(subcat, names, dst)
            names.pop()

        result = []
        for cat in menu:
            process_category(cat, [], result)

        self.render('/mt/reports/view_menu.html', menu=result)
Beispiel #7
0
 def get(self):
     get_menu(self.user.company.get().iiko_org_id, force_reload=True)
     self.redirect('/api/push_admin/history?menu_reload')
Beispiel #8
0
    def post(self):
        company_info = json.loads(self.request.get('company_info'))
        company_id = self.request.get('company_id')

        is_delivery = company_info.get('is_delivery') == 'true'
        is_self = company_info.get('is_self_pickup') == 'true'
        company_params = {
            'app_title': company_info.get('app_title', None),
            'description': company_info.get('about_text', None),
            'min_order_sum': int(company_info['min_amount']) if company_info.get('min_amount') else None,
            'cities': company_info['delivery_cities'].split(',') if company_info.get('delivery_cities') else None,
            'phone': company_info.get('phone', None),
            'schedule': company_info.get('schedule', None),
            'email': company_info.get('email', None),
            'support_emails': company_info['support_emails'] if company_info.get('support_emails') else None,
            'site': company_info.get('site', None),
            'color': company_info.get('color', None),
            'analytics_key': company_info.get('analytics_code', None),
        }

        if company_id and company_id != '-1':
            company_id = int(company_id)
            company = iiko.CompanyNew.get_by_id(company_id)
            if not company:
                self.abort(404)
            if company_params['app_title']:
                company.app_title = company_params['app_title']
            if company_params['description']:
                company.description = company_params['description']
            if company_params['min_order_sum']:
                company.min_order_sum = company_params['min_order_sum']
            if company_params['cities']:
                company.cities = company_params['cities']
            if company_params['phone']:
                company.phone = company_params['phone']
            if company_params['schedule']:
                company.schedule = company_params['schedule']
            if company_params['email']:
                company.email = company_params['email']
            if company_params['site']:
                company.site = company_params['site']
            if company_params['color']:
                company.color = company_params['color']
            if company_params['analytics_key']:
                company.analytics_key = company_params['analytics_key']
            if company_params['support_emails']:
                company.support_emails = company_params['support_emails']
            for delivery_type in company.delivery_types:
                delivery_type = delivery_type.get()
                name = delivery_type.name
                if name == 'self':
                    delivery_type.available = is_self
                elif name == 'delivery':
                    delivery_type.available = is_delivery
                delivery_type.put()

        else:
            delivery_self = iiko.DeliveryType(delivery_id=1, name='self', available=is_self)
            delivery_self.put()
            delivery_pickup = iiko.DeliveryType(delivery_id=0, name='delivery', available=is_delivery)
            delivery_pickup.put()
            company = iiko.CompanyNew(**company_params)
            company.delivery_types.append(delivery_self.key)
            company.delivery_types.append(delivery_pickup.key)

        company.put()

        for iiko_venue in []:
            get_menu(iiko_venue['id'], force_reload=True, filtered=False)
            venue = iiko.Venue.venue_by_id(iiko_venue['id'])
            venue.payment_types = []
            for iiko_payment in get_payment_types(venue.venue_id)['PaymentTypes']:
                payment = iiko.PaymentType()
                payment.name = iiko_payment['name']
                payment.iiko_uuid = iiko_payment['code']
                if payment.iiko_uuid == 'CASH':
                    payment.type_id = 1
                elif payment.iiko_uuid == 'ECARD':
                    payment.type_id = 2
                else:
                    payment.type_id = 3
                payment.put()
                venue.payment_types.append(payment.key)
            venue.put()


        id_json = {
            'id': company.key.id()
        }
        return self.render_json(id_json)