Exemplo n.º 1
0
    def get(self):
        companies = Company.query().fetch()
        for c in companies:
            IikoApiLogin(id=c.name, password=c.password).put()

            venue = None

            dct = {
                k: getattr(c, k)
                for k in Company._properties if k not in ('name', 'password')
            }
            CompanyNew(id=c.key.id(),
                       menu=venue.menu,
                       address=venue.address,
                       latitude=venue.latitude,
                       longitude=venue.longitude,
                       payment_types=venue.payment_types,
                       iiko_login=c.name,
                       iiko_org_id=venue.venue_id,
                       **dct).put()

            dts = get_delivery_terminals(venue.venue_id)
            for dt in dts:
                DeliveryTerminal(id=dt['deliveryTerminalId'],
                                 active=dt['deliveryTerminalId'] !=
                                 'd7fd5599-814a-79be-0146-b83a4192096f',
                                 phone=c.phone or '',
                                 company_id=c.key.id(),
                                 iiko_organization_id=venue.venue_id,
                                 name=dt['deliveryRestaurantName'],
                                 address=dt['address'],
                                 location=GeoPt(venue.latitude,
                                                venue.longitude)).put()
Exemplo n.º 2
0
def create(login, password=None, company_id=None, organization_id=None, new_endpoints=True):
    if not IikoApiLogin.get_by_id(login):
        if not password:
            raise Exception("Login does not exist, so password is required")
        IikoApiLogin(id=login, password=password).put()

    company = CompanyNew(id=company_id)
    company.new_endpoints = new_endpoints
    company.iiko_login = login

    if organization_id:
        organization = get_org(login, organization_id, new_endpoints)
        company.iiko_org_id = organization_id
    else:
        organization = get_orgs(login, new_endpoints)[0]
        company.iiko_org_id = organization['id']
    company.app_title = organization['name']
    company.address = organization['address'] or organization['contact']['location']
    company.latitude, company.longitude = 0, 0
    if company.address:
        try:
            company.latitude, company.longitude = get_address_coordinates(company.address)
        except Exception as e:
            logging.exception(e)

    delivery_types = [
        DeliveryType(available=True, delivery_id=DeliveryType.DELIVERY, name="delivery"),
        DeliveryType(available=False, delivery_id=DeliveryType.SELF, name="self"),
        DeliveryType(available=False, delivery_id=DeliveryType.IN_CAFE, name="in cafe"),
    ]
    company.delivery_types = ndb.put_multi(delivery_types)

    payment_types = [
        PaymentType(available=True, type_id=1, name="cash", iiko_uuid="CASH"),
        PaymentType(available=config.DEBUG, type_id=2, name="card", iiko_uuid="ECARD")
    ]
    company.payment_types = ndb.put_multi(payment_types)

    if config.DEBUG:
        company.alpha_login = "******"
        company.alpha_pass = "******"
    company.put()

    _load_delivery_terminals(company)
    return company