Coder Social home page Coder Social logo

odoo-power-bi-connector's Introduction

Odoo - Power BI Connector

This project allows Power BI to query data from Odoo through the JsonRPC API.

Before this connector, the only way to query Odoo from Power BI was to connect directly to the PostreSQL database. This is impossible if, for example, the Odoo instance is hosted on odoo.sh or on some other platform which doesn't expose the database to the internet.

Installation

  1. Create a [Documents]\Power BI Desktop\Custom Connectors directory.
  2. Download Odoo.mez and place it in that directory.
  3. Open Power BI Desktop and enable loading unsigned connectors (File > Options and settings > Options > Security > Data Extensions > Allow any extension to load without warning or validation)
  4. Restart Power BI Desktop

Read the PBI documentation if you have any trouble.

Usage

Currently a big limitation of this connector is that it doesn't support query folding. This means that if you load a table and filter it through the Power Query Editor UI, Power BI will download the whole table and then filter it locally instead of sending the filter definition to the server and downloading just the needed columns and rows. This is inefficient at best and can lead to an Odoo Server Error: Out of memory exception at worst.

Because of this, the current recommended way to get data is through the search_read function.

Demonstration

search_read

search_read allows us to query an Odoo model. For more information see the Odoo documentation.

search_read(
    model as text, 
    optional search_domain as list, 
    optional params as record, 
    optional set_schema as bool
)

Where:

  • model: Technical name of the model to query. Examples: "res.partner", "account.invoice".

  • search_domain: An Odoo Search Domain.

    It's important to remember that lists in the M Language are enclosed in cuvy brackets ({...}). So the following python search domain

    [('name','=','ABC'),
    ('language.code','!=','en_US'),
    '|',('country_id.code','=','be'),
        ('country_id.code','=','de')]

    should be written in M like

    {{"name","=","ABC"},
    {"language.code","!=","en_US"},
    "|",{"country_id.code","=","be"},
        {"country_id.code","=","de"}}
    
  • params: A record containing any keyword parameter that we want to pass to search_read. Can include:

    • offset as Int64.Type
    • limit as Int64.Type
    • order as text
    • fields as list
    • context as record

    Note: If fields is not specified, the default behaviour is to read all fields except those one2many fields which reference models the user doesn't have permission to read.

  • set_schema: Whether or not to set the column types according to the field definition on Odoo. Defaults to true.

Example: Get the names and emails of our contacts at Azure Interior

search_read(
    "res.partner",
    { {"parent_name", "=", "Azure Interior"} },
    [ fields = {"name", "email"}, order = "name" ]
)
email name id
[email protected] Brandon Freeman 26
[email protected] Colleen Diaz 33
[email protected] Nicole Ford 27

Development

Build

  1. Install Visual Studio Code
  2. Install the Power Query SDK VS Code extension
  3. Clone this repository and open it in VS Code
  4. Compile and install (Terminal > Run Task > Build and copy to Customs Connectors folder / Ctrl+Shift+B)

Alternativelly, you can just compress the repository to a .zip file and then change the extension to .mez.

Test

By default the unit tests assume there's a non-empty Odoo instance running at http://localhost:8069 with a database named db. A docker-compose.yml file is provided to easily set up such an instance. Just execute docker-compose up, wait a bit, go to http://localhost:8069 and set up the database with sample data. If you want to use some other server for the tests, edit test-server.json.

Once that server is reachable, press Set credential in the Power Query SDK sidebar and enter your Odoo test db username and password. Then open Odoo.query.pq and press Evaluate current file (also in the PQ SDK sidebar).

odoo-power-bi-connector's People

Contributors

tmijail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odoo-power-bi-connector's Issues

Database Issue

hello tmijail
database can't connect, looks like an error occurred in res.user.parent_id

datbase error
datbase error 2

Odoo Server Error: Invalid parent field: res.users.parent_id
Details:
Traceback (most recent call last):
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 1584, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 133, in retrying
result = func()
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 1611, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 1815, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
result = endpoint(**request.params)
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/custom/trial/saas_trial/controllers/main.py", line 275, in jsonrpc
res = super(OdooRPC, self).jsonrpc(service, method, args)
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/controllers/rpc.py", line 156, in jsonrpc
return dispatch_rpc(service, method, args)
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 366, in dispatch_rpc
return dispatch(method, params)
File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 37, in dispatch
res = execute_kw(db, uid, *params[3:])
File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 59, in execute_kw
return execute(db, uid, obj, method, *args, **kw or {})
File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 65, in execute
res = execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 50, in execute_cr
result = retrying(partial(odoo.api.call_kw, recs, method, args, kw), env)
File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 133, in retrying
result = func()
File "/home/odoo/src/odoo/16.0/odoo/api.py", line 457, in call_kw
result = _call_kw_model(method, model, args, kwargs)
File "/home/odoo/src/odoo/16.0/odoo/api.py", line 430, in _call_kw_model
result = method(recs, *args, **kwargs)
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 2188, in read_group
result = self._read_group_raw(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 2213, in _read_group_raw
query = self._where_calc(domain)
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 4407, in _where_calc
return expression.expression(domain, self).query
File "/home/odoo/src/odoo/16.0/odoo/osv/expression.py", line 447, in init
self.parse()
File "/home/odoo/src/odoo/16.0/odoo/osv/expression.py", line 721, in parse
right_ids = comodel.with_context(active_test=False)._search([(path[1], operator, right)], order='id')
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/res_users.py", line 208, in _search
return super(Groups, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 4639, in _search
query = self._where_calc(domain)
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 4407, in _where_calc
return expression.expression(domain, self).query
File "/home/odoo/src/odoo/16.0/odoo/osv/expression.py", line 447, in init
self.parse()
File "/home/odoo/src/odoo/16.0/odoo/osv/expression.py", line 829, in parse
domain = HIERARCHY_FUNCS[operator]('id', ids2, comodel)
File "/home/odoo/src/odoo/16.0/odoo/osv/expression.py", line 561, in child_of_domain
raise ValueError(f"Invalid parent field: {left_model._fields[parent_name]}")
ValueError: Invalid parent field: res.users.parent_id

Regards,

Error when using search_read for people without Administrator permissions

I've found that if you run the search_read method, unless your user account has Administrator Settings permission an error occurs as below.

Odoo Server Error: You are not allowed to access 'Model Access' (ir.model.access) records.

This operation is allowed for the following groups:
- Administration/Access Rights

Contact your administrator to request access if necessary.
Details:
Traceback (most recent call last):
File "/data/build/odoo/odoo/http.py", line 1452, in _dispatch_nodb
result = request.dispatch()
File "/data/build/odoo/odoo/http.py", line 684, in dispatch
result = self._call_function(**self.params)
File "/data/build/odoo/odoo/http.py", line 361, in _call_function
return self.endpoint(*args, **kwargs)
File "/data/build/odoo/odoo/http.py", line 913, in call
return self.method(*args, **kw)
File "/data/build/odoo/odoo/http.py", line 532, in response_wrap
response = f(*args, **kw)
File "/data/build/odoo/odoo/addons/base/controllers/rpc.py", line 96, in jsonrpc
return dispatch_rpc(service, method, args)
File "/data/build/odoo/odoo/http.py", line 141, in dispatch_rpc
result = dispatch(method, params)
File "/data/build/odoo/odoo/service/model.py", line 41, in dispatch
res = fn(db, uid, *params)
File "/data/build/odoo/odoo/service/model.py", line 168, in execute_kw
return execute(db, uid, obj, method, *args, **kw or {})
File "/data/build/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/data/build/odoo/odoo/service/model.py", line 175, in execute
res = execute_cr(cr, uid, obj, method, *args, **kw)
File "/data/build/odoo/odoo/service/model.py", line 159, in execute_cr
result = odoo.api.call_kw(recs, method, args, kw)
File "/data/build/odoo/odoo/api.py", line 395, in call_kw
result = _call_kw_model(method, model, args, kwargs)
File "/data/build/odoo/odoo/api.py", line 368, in _call_kw_model
result = method(recs, *args, **kwargs)
File "/data/build/odoo/odoo/models.py", line 2254, in read_group
result = self._read_group_raw(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)
File "/data/build/odoo/odoo/models.py", line 2276, in _read_group_raw
self.check_access_rights('read')
File "/data/build/odoo/odoo/models.py", line 3332, in check_access_rights
return self.env['ir.model.access'].check(self._name, operation, raise_exception)
File "", line 2, in check
File "/data/build/odoo/odoo/tools/cache.py", line 90, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/data/build/odoo/odoo/addons/base/models/ir_model.py", line 1805, in check
raise AccessError(msg)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/data/build/odoo/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/data/build/odoo/odoo/http.py", line 316, in _handle_exception
raise exception.with_traceback(None) from new_cause
odoo.exceptions.AccessError: You are not allowed to access 'Model Access' (ir.model.access) records.

This operation is allowed for the following groups:
- Administration/Access Rights

Contact your administrator to request access if necessary.

error jsonrpc

werkzeug.exceptions.BadRequest: 400 Bad Request: <function RPC.jsonrpc at 0x7f1c6e159ee0>, /jsonrpc: Function declared as capable of handling request of type 'json' but called with a request of type 'apijson'

Issue with some tables

Getting error when the tables are opened via get data in PowerBI. Find the screenshot for reference.

powerbi errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.