Ejemplo n.º 1
0
def doubleb_place_order(order, client, venue, items, payment):
    company = DoublebCompany.get()
    doubleb_client = DoublebClient.get(client)
    doubleb_response = post_doubleb_place_order(
        company, order, client, doubleb_client, venue,
        get_doubleb_item_dicts(items), update_payment_info(payment),
        get_doubleb_delivery_time(order.delivery_time))
    if doubleb_response.get('description'):
        success = False
        response = {'description': doubleb_response['description']}
    else:
        success = True
        order.key = ndb.Key(Order, doubleb_response['order_id'])
        order.number = order.key.id()
        order.status = NEW_ORDER
        order.item_details = get_order_position_details(
            get_auto_item_dicts(items))
        local_delivery_time = order.delivery_time + timedelta(
            hours=venue.timezone_offset)
        order.delivery_time_str = local_delivery_time.strftime(
            STR_DATETIME_FORMAT)
        order.put()
        response = {
            'order_id': order.key.id(),
            'number': order.number,
            'delivery_time': order.delivery_time_str,
            'delivery_slot_name': None,
            'show_share': False,
        }
    return success, response
Ejemplo n.º 2
0
def _get_menu():
    menu = memcache.get('doubleb_menu')
    if not menu:
        company = DoublebCompany.get()
        menu = get_doubleb_menu(company)['menu']
        category = MenuCategory(id=667)
        category.category = MenuCategory.get_initial_category().key
        category.title = u'Напитки'
        categories = [category]
        items = []
        for index, item_dict in enumerate(menu[u'Напитки']):
            item = MenuItem(id=int(item_dict['id']))
            item.category = category.key
            item.price = item_dict['price'] * 100
            item.title = item_dict['title']
            item.picture = ''
            item.description = ''
            item.order = index
            item.kal = 0
            item.weight = 0
            items.append(item)
        items, modifiers = _set_modifiers(items)
        menu = categories, items, modifiers
        memcache.set('doubleb_menu', menu, time=3600)
    return menu
Ejemplo n.º 3
0
def doubleb_registration(client):
    company = DoublebCompany.get()
    doubleb_client = DoublebClient.get(client)
    response = post_doubleb_registration(company, doubleb_client)
    if not doubleb_client:
        doubleb_client = DoublebClient(id=response['client_id'],
                                       client=client.key)
        doubleb_client.put()
Ejemplo n.º 4
0
    def APP_KIND(self):
        from models.proxy.resto import RestoCompany
        from models.proxy.doubleb import DoublebCompany

        if RestoCompany.get():
            return RESTO_APP
        elif DoublebCompany.get():
            return DOUBLEB_APP
        else:
            return AUTO_APP
Ejemplo n.º 5
0
def doubleb_validate_order(client, venue, items, payment_info, delivery_time):
    company = DoublebCompany.get()
    doubleb_client = DoublebClient.get(client)
    doubleb_validation = post_doubleb_check_order(company, doubleb_client, venue,
                                                  get_doubleb_item_dicts(items),
                                                  update_payment_info(payment_info),
                                                  get_doubleb_delivery_time(delivery_time))
    required_value = {
        'valid': doubleb_validation['valid'],
        'error': doubleb_validation['errors'],
        'total_sum': doubleb_validation['total_sum'],
        'item_dicts': get_auto_item_dicts(items),
        'promos': doubleb_validation['promos']
    }
    response = get_response_dict(**required_value)
    return response
Ejemplo n.º 6
0
def get_payment_types():
    payment_types = memcache.get('doubleb_payment_types')
    if not payment_types:
        company = DoublebCompany.get()
        payment_type_dicts = get_doubleb_payment_types(company)
        payment_types = []
        for payment_type_dict in payment_type_dicts['payment_types']:
            if PAYMENT_TYPE_MAP.get(payment_type_dict['id']) == None:
                continue
            payment_type = PaymentType(
                id=PAYMENT_TYPE_MAP[payment_type_dict['id']])
            payment_type.title = payment_type_dict['title']
            payment_type.status = STATUS_AVAILABLE
            payment_types.append(payment_type)
        memcache.set('doubleb_payment_types', payment_types, 3600)
    return payment_types
Ejemplo n.º 7
0
def get_venues():
    venues = memcache.get('doubleb_venues')
    if not venues:
        company = DoublebCompany.get()
        venues_dict = get_doubleb_venues(company)['venues']
        venues = []
        for venue_dict in venues_dict:
            venue = Venue(id=int(venue_dict['id']))
            venue.active = True
            venue.coordinates = GeoPt(lat=venue_dict['coordinates'].split(',')[0],
                                      lon=venue_dict['coordinates'].split(',')[1])
            venue.title = venue_dict['title']
            venue.description = venue_dict['address']
            venue.schedule = _get_schedule(venue_dict['schedule'])
            venue.delivery_types = _get_delivery_types(venue_dict['takeout_only'])
            venue.update_timezone()
            venues.append(venue)
        memcache.set('doubleb_venues', venues, 3600)
    return venues