Ejemplo n.º 1
0
def get_venue_promos(org_id):
    if org_id in HARDCODED_PROMOS:
        return HARDCODED_PROMOS[org_id]

    url = '/organization/%s/marketing_campaigns' % org_id
    company = CompanyNew.get_by_iiko_id(org_id)
    if not company.is_iiko_system:
        return []
    promos = json.loads(get_request(company, url, {}, force_platius=True))
    result = []
    for promo in promos:
        if not promo['name']:
            continue
        promo_start = promo_end = None
        if promo['start']:
            promo_start = datetime.strptime(promo['start'], '%Y-%m-%d')
            if datetime.now() < promo_start:
                continue
        if promo['end']:
            promo_end = datetime.strptime(promo['end'], '%Y-%m-%d')
            if datetime.now() > promo_end:
                continue
        result.append({
            'id': promo['id'],
            'name': promo['name'] if promo['name'] else '',
            'description': promo['description'] if promo['description'] else '',
            'image_url': promo['imageUrl'],
            'display_type': 3,
            'start': (promo_start - datetime(1970, 1, 1)).total_seconds() if promo_start else None,
            'end': (promo_end - datetime(1970, 1, 1)).total_seconds() if promo_end else None
        })
    return result
Ejemplo n.º 2
0
def get_customer_by_phone(company, phone):
    result = get_request(company,
                         '/customers/get_customer_by_phone', {
                             'organization': company.iiko_org_id,
                             'phone': phone
                         },
                         force_platius=True)
    return json.loads(result)
Ejemplo n.º 3
0
def get_history_by_phone(phone, org_id):
    company = CompanyNew.get_by_iiko_id(org_id)
    result = get_request(company, '/orders/deliveryHistoryByPhone', {
        'organization': org_id,
        'phone': phone
    })
    obj = json.loads(result)
    return obj
Ejemplo n.º 4
0
def get_customer_by_card(company, card):
    result = get_request(company,
                         '/customers/get_customer_by_card', {
                             'organization': company.iiko_org_id,
                             'card': card
                         },
                         force_platius=True)
    return json.loads(result)
Ejemplo n.º 5
0
def order_info(order):
    company = CompanyNew.get_by_iiko_id(order.venue_id)
    result = get_request(company, '/orders/info', {
        'requestTimeout': 30,
        'organization': order.venue_id,
        'order': order.order_id
    })
    return json.loads(result)
Ejemplo n.º 6
0
def get_history(client_id, org_id):
    company = CompanyNew.get_by_iiko_id(org_id)
    result = get_request(company, '/orders/deliveryHistory', {
        'organization': org_id,
        'customer': client_id,
        'requestTimeout': 20
    })
    obj = json.loads(result)
    return obj
Ejemplo n.º 7
0
def get_cities_and_streets(company, force_update=False):
    storage_key = "streets_%s" % company.iiko_org_id
    result = JsonStorage.get(storage_key)
    if not result or force_update:
        response = get_request(company, '/cities/cities',
                               {'organization': company.iiko_org_id})
        result = _process_streets(json.loads(response))
        JsonStorage.save(storage_key, result)
    return result
Ejemplo n.º 8
0
def order_info1(order_id, org_id):
    company = CompanyNew.get_by_iiko_id(org_id)
    result = get_request(company, '/orders/info', {
        'requestTimeout': 30,
        'organization': org_id,
        'order': order_id
    })
    logging.info(result)
    return json.loads(result)
Ejemplo n.º 9
0
def get_orders(company, start, end, status=None):
    payload = {
        'organization': company.iiko_org_id,
        'dateFrom': start.strftime("%Y-%m-%d"),
        'dateTo': end.strftime("%Y-%m-%d"),
        'request_timeout': '00:01:00'
    }
    if status:
        payload['deliveryStatus'] = status
    return json.loads(
        get_request(company, '/orders/deliveryOrders', payload, deadline=45))
Ejemplo n.º 10
0
def _load_stop_list(company):
    result = get_request(company, '/stopLists/getDeliveryStopList', {
        'organization': company.iiko_org_id,
    })
    stop_lists = json.loads(result)['stopList']
    result = {}
    for dt_stop_list in stop_lists:
        dt_dict = {}
        for item_info in dt_stop_list['items']:
            dt_dict[item_info['productId']] = item_info['balance']
        result[dt_stop_list['deliveryTerminalId']] = dt_dict
    return result
Ejemplo n.º 11
0
def get_payment_types(org_id):
    company = CompanyNew.get_by_iiko_id(org_id)
    result = get_request(company, '/paymentTypes/getPaymentTypes',
                         {'organization': org_id})
    obj = json.loads(result)
    return obj
Ejemplo n.º 12
0
def get_org(iiko_api_login, org_id, new_endpoints):
    dummy = _get_dummy_company(iiko_api_login, new_endpoints)
    result = get_request(dummy, '/organization/%s' % org_id, {})
    return json.loads(result)
Ejemplo n.º 13
0
def _load_menu(company):
    result = get_request(company, '/nomenclature/%s' % company.iiko_org_id, {})
    iiko_menu = json.loads(result)
    group_modifiers, modifiers = _get_menu_modifiers(company, iiko_menu)
    category_products = defaultdict(list)

    if 'productCategories' in iiko_menu:
        iiko_categories = {
            c['id']: c['name']
            for c in iiko_menu['productCategories']
        }
    else:
        iiko_categories = {}

    for product in iiko_menu['products']:
        if product['parentGroup'] is None:
            continue

        single_modifiers = []
        for m in product['modifiers']:
            modifier = _clone(modifiers[m['modifierId']])
            modifier['minAmount'] = m['minAmount']
            modifier['maxAmount'] = m['maxAmount']
            modifier['defaultAmount'] = m['defaultAmount']
            if company.iiko_org_id == CompanyNew.TYKANO and modifier[
                    'code'] in ('11111', '99999'):
                continue  # skip 'delivery' and 'takeout' modifiers for Tukano
            single_modifiers.append(modifier)

        grp_modifiers = []
        for m in product['groupModifiers']:
            group = _clone(group_modifiers[m['modifierId']])
            group['minAmount'] = m['minAmount']
            group['maxAmount'] = m['maxAmount']
            for item in group['items']:
                item['amount'] = m['minAmount']  # TODO legacy
            grp_modifiers.append(group)

        add_info_str = product['additionalInfo']
        add_info = None
        if add_info_str:
            try:
                add_info = json.loads(product['additionalInfo'])
            except ValueError:
                add_info_str = None  # don't pass through raw info if cannot parse JSON

        if company.iiko_org_id == CompanyNew.COFFEE_CITY:
            product['weight'] = 0

        if company.iiko_org_id == CompanyNew.COFFEE_CITY and product[
                'parentGroup'] == CAT_GIFTS_GROUP_ID:
            product['price'] = 1
            product['name'] += ' '

        name = product['name']
        description = product['description']
        if company.iiko_org_id == CompanyNew.HLEB:
            if product['tags']:
                name = product['tags'][0]
            description = product['additionalInfo']

        category_products[product['parentGroup']].append({
            'price':
            product['price'],
            'name':
            name,
            'productId':
            product['id'],
            'order':
            product['order'],
            'weight':
            product['weight'],
            'carbohydrateAmount':
            product['carbohydrateAmount'],
            'energyAmount':
            product['energyAmount'],
            'fatAmount':
            product['fatAmount'],
            'fiberAmount':
            product['fiberAmount'],
            'code':
            product['code'],
            'images': [
                convert_url(webapp2.get_request(), img['imageUrl'])
                for img in product.get('images', []) if img['imageUrl']
            ][::-1],
            'description':
            description or '',
            'additionalInfo':
            add_info,
            'additionalInfo1':
            add_info_str,
            'iikoCatId':
            product['productCategoryId'],
            'iikoCatName':
            iiko_categories.get(product['productCategoryId'], ''),
            'single_modifiers':
            single_modifiers,
            'modifiers':
            grp_modifiers
        })

    categories = dict()
    for cat in iiko_menu['groups']:
        # TODO beer in sushilar
        if company.iiko_org_id == CompanyNew.SUSHILAR and cat[
                'id'] == '6e4b8c9c-df45-40f6-8356-ac8039e3f630':
            continue
        # ingredients in giotto
        if company.iiko_org_id == CompanyNew.GIOTTO and cat[
                'id'] == '1f62d74f-79fb-43e3-86e1-8e90ffc956bf':
            continue
        if not cat['isIncludedInMenu']:
            continue
        if company.iiko_org_id == CompanyNew.COFFEE_CITY and cat[
                'id'] == CAT_GIFTS_GROUP_ID:
            cat['parentGroup'] = None
            cat['order'] = 4
        products = sorted(category_products[cat['id']],
                          key=operator.itemgetter('order'))
        categories[cat['id']] = {
            'id': cat['id'],
            'name': cat['name'].capitalize(),
            'products': products,
            'parent': cat['parentGroup'],
            'children': [],
            'hasChildren': False,
            'image':
            [image for image in cat['images'] if image['imageUrl']][::-1],
            'order': cat['order']
        }
        for image in categories[cat['id']]['image']:
            image['imageUrl'] = convert_url(webapp2.get_request(),
                                            image['imageUrl'])
        # todo hack for sushilar
        if cat['id'] == '170f94fd-3adb-4bb5-bd14-836bd81d2172':
            categories['170f94fd-3adb-4bb5-bd14-836bd81d2172']['image'].append({
                'imageUrl':
                'http://empatika-resto-test.appspot.com/static/img/sushilar_spicy_rolls.png'
            })

    for cat_id, cat in categories.items():
        cat_parent_id = cat.get('parent')
        if cat_parent_id == cat_id:
            cat['parent'] = cat_parent_id = None
        if cat_parent_id:
            parent = categories[cat_parent_id]
            parent['children'].append(cat)
            parent['hasChildren'] = True
            if parent.get('products'):
                parent['products'] = []

    for cat_id, cat in categories.items():
        cat_parent_id = cat.get('parent')
        if cat_parent_id:
            del categories[cat_id]

    for cat_id, cat in categories.items():
        children = cat.get('children')
        if children:
            cat['children'] = sorted(children,
                                     key=operator.itemgetter('order'))

    menu = sorted(categories.values(), key=operator.itemgetter('order'))
    if company.iiko_org_id == CompanyNew.MIVAKO:
        if "b918a490-e0f2-485c-bb13-3903cc5cc28d" in categories:
            menu = categories["b918a490-e0f2-485c-bb13-3903cc5cc28d"][
                'children']

    _fix_categories_images(menu)
    return menu
Ejemplo n.º 14
0
def get_delivery_terminals(company):
    result = get_request(company, '/deliverySettings/getDeliveryTerminals', {
        'organization': company.iiko_org_id
    })
    return json.loads(result)['deliveryTerminals']