Example #1
0
async def test_async_readme1(url_db_user_pwd: list):
    url, db, user, pwd = url_db_user_pwd

    url_json_endpoint = odoo_base_url2jsonrpc_endpoint(odoo_base_url=url)

    async with httpx.AsyncClient(base_url=url) as session:
        odoo = AsyncOdooRPC(database=db, username_or_uid=user, password=pwd, http_client=session,
                            url_jsonrpc_endpoint=url_json_endpoint)
        await odoo.login()
        try:
            # A default model name has not been set a instantiation time so we should
            # pass the model_name on every invocation. Here it should throw an exception.
            await odoo.read()
        except RuntimeError:
            pass
        else:
            assert False, 'Expected an exception to be raised'
        
        # Now with model_name set it should work. Not passing a list of ids
        # turns the read call into a search_read call with an empty domain
        # A missing 'fields' parameter means 'fetch all fields'.
        # Hence this call is very expensive, it fetches all fields for all
        # 'sale.order' records
        all_orders_all_fields = await odoo.read(model_name='sale.order')
        
        # creates a copy of odoo obj setting default_model_name to 'sale.order'
        sale_order = odoo.new_for_model('sale.order')
        
        # now we do not need to pass model_name and it works!
        all_orders_all_fields2 = await sale_order.read()
        
        large_orders = sale_order.search_read(domain=[['amount_total', '>', 10000]],
                                              fields=['partner_id', 'amount_total', 'date_order'])
Example #2
0
def sync_test(url, db, user, pwd, http_client):
    url_json_endpoint = odoo_base_url2jsonrpc_endpoint(odoo_base_url=url)
    odoo = OdooRPC(database=db,
                   username_or_uid=user,
                   password=pwd,
                   http_client=http_client,
                   url_jsonrpc_endpoint=url_json_endpoint)
    odoo.login()
    limit = 10
    fields = ['partner_id', 'date_order', 'amount_total']

    kwargs = {'model_name': 'sale.order', 'domain': []}

    data1 = odoo.search_read(**kwargs, fields=fields)

    count = odoo.search_count(**kwargs)

    ids = odoo.search(**kwargs)

    del kwargs['domain']
    kwargs['ids'] = ids
    data2 = odoo.read(**kwargs, fields=fields)

    assert len(data1) == count
    assert len(ids) == count
    assert len(data2) == count

    if 'id' not in fields:
        fields.append('id')

    for f in fields:
        for d in data1:
            assert d.get(f)

    for f in fields:
        for d in data2:
            assert d.get(f)

    ids1 = [d.get('id') for d in data1]
    ids2 = [d.get('id') for d in data2]
    ids.sort()
    ids1.sort()
    ids2.sort()

    assert len(ids) == len(ids1) and len(ids) == len(ids2)

    data1 = {d.get('id'): d for d in data1}
    data2 = {d.get('id'): d for d in data2}

    for i in range(0, len(ids) - 1):
        assert ids[i] == ids1[i] == ids2[i]

        for f in fields:
            assert data1[ids[i]][f] == data2[ids[i]][f]
Example #3
0
async def test_bug_return_none(url_db_user_pwd: list):
    url, db, user, pwd = url_db_user_pwd
    url_json_endpoint = odoo_base_url2jsonrpc_endpoint(odoo_base_url=url)
    
    async with httpx.AsyncClient(base_url=url) as session:
        odoo = AsyncOdooRPC(database=db, username_or_uid=user, password=pwd, http_client=session,
                            url_jsonrpc_endpoint=url_json_endpoint)
        await odoo.login()
        
        test = await odoo.search_read(model_name='sale.order', domain=[],
                                      fields=[], setter__id_fields=setter__id_id_as_int)
        assert test is not None
Example #4
0
def url_db_user_pwd():
    with httpx.Client() as client:
        resp = client.get(url='http://runbot.odoo.com/runbot')

    soup = BeautifulSoup(resp.text, features='html.parser')
    tags = soup.find_all("a", class_="fa-sign-in")

    urls = []

    for tag in tags:
        try:
            url = tag['href']
            db = re.search('\d+-saas-[^.]+', url).group()
            if len(db) > 0 and len(url) > 0:
                json_url = odoo_base_url2jsonrpc_endpoint(url)
                return [json_url, db + '-master-all', 'demo', 'demo']
        except:
            pass

    return None
Example #5
0
def test_urls():
    url = build_odoo_jsonrpc_endpoint_url(host='odoo.com', port=80, ssl=True)
    assert url == 'https://odoo.com:80/jsonrpc'
    url = build_odoo_jsonrpc_endpoint_url(host='odoo.com', port=80, ssl=False)
    assert url == 'http://odoo.com/jsonrpc'
    url = build_odoo_jsonrpc_endpoint_url(host='odoo.com',
                                          port=443,
                                          ssl=True,
                                          base_url='acme')
    assert url == 'https://odoo.com/acme/jsonrpc'
    url = build_odoo_jsonrpc_endpoint_url(host='odoo.com',
                                          port=8069,
                                          ssl=True,
                                          base_url='acme',
                                          custom_odoo_jsonrpc_suffix='jrpc')
    assert url == 'https://odoo.com:8069/acme/jrpc'

    url = build_odoo_jsonrpc_endpoint_url(host='odoo.com',
                                          ssl=True,
                                          base_url='acme',
                                          custom_odoo_jsonrpc_suffix='jrpc')
    assert url == 'https://odoo.com/acme/jrpc'
    url = build_odoo_jsonrpc_endpoint_url(host='odoo.com',
                                          ssl=False,
                                          base_url='acme')
    assert url == 'http://odoo.com/acme/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com/')
    assert url == 'http://odoo.com/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com')
    assert url == 'http://odoo.com/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint()
    assert url == 'jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(custom_odoo_jsonrpc_suffix='superrpc')
    assert url == 'superrpc'

    url = odoo_base_url2jsonrpc_endpoint(
        custom_odoo_jsonrpc_suffix='/superrpc')
    assert url == 'superrpc'

    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com',
                                         custom_odoo_jsonrpc_suffix='/jsonrpc')
    assert url == 'http://odoo.com/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com/',
                                         custom_odoo_jsonrpc_suffix='/jsonrpc')
    assert url == 'http://odoo.com/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(
        odoo_base_url='http://odoo.com////',
        custom_odoo_jsonrpc_suffix='///jsonrpc')
    assert url == 'http://odoo.com/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(
        odoo_base_url='http://odoo.com/jsonrpc')
    assert url == 'http://odoo.com/jsonrpc'

    url = odoo_base_url2jsonrpc_endpoint(
        odoo_base_url='http://odoo.com/jsonrpc/')
    assert url == 'http://odoo.com/jsonrpc'
def test_helpers_odoo_base_url2jsonrpc_endpoint():
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com/')
    assert url == 'http://odoo.com/jsonrpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com')
    assert url == 'http://odoo.com/jsonrpc'
    url = odoo_base_url2jsonrpc_endpoint()
    assert url == '/jsonrpc'
    url = odoo_base_url2jsonrpc_endpoint(jsonrpc_suffix='superrpc')
    assert url == '/superrpc'
    url = odoo_base_url2jsonrpc_endpoint(jsonrpc_suffix='/superrpc')
    assert url == '/superrpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com', jsonrpc_suffix='/rpc')
    assert url == 'http://odoo.com/rpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='https://odoo.com:8080/', jsonrpc_suffix='jrpc')
    assert url == 'https://odoo.com:8080/jrpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='https://odoo.com:8080', jsonrpc_suffix='jrpc')
    assert url == 'https://odoo.com:8080/jrpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com////', jsonrpc_suffix='///jsonrpc')
    assert url == 'http://odoo.com/jsonrpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='//http://odoo.com/superrpc//', jsonrpc_suffix='superrpc')
    assert url == 'http://odoo.com/superrpc'
    url = odoo_base_url2jsonrpc_endpoint(odoo_base_url='http://odoo.com/jsonrpc/')
    assert url == 'http://odoo.com/jsonrpc'