如何将Odoo环境加载到Jupyter笔记本中?

时间:2018-05-16 18:50:51

标签: python jupyter-notebook jupyter odoo jupyter-lab

Odoo(ERP)

  

Odoo是一款一体化管理软件,提供一系列业务应用程序,形成一整套企业管理应用程序,面向各种规模的公司。 Odoo是一款多功能商务软件,包括CRM,网站/电子商务,计费,会计,制造,仓库和项目管理以及库存。

     

社区版本是开源版本,而企业版本则补充了具有商业功能和服务的社区版本。

终端

通常我会启动一个带有Odoo环境的Python终端,如下所示:

/odoo_path/odoo-bin --addons-path=/addons_path shell --config=/config_path/.odoo.conf -d database_name

在控制台内我可以调用self,环境变量可用(self.env)。我可以在连接的数据库上运行一些命令。如果我想做一些快速测试,这非常有用。但是,如果我想运行一些小脚本或测试一些代码片段,那就有点不方便了。 Jupyter Notebooks and Jupyter Lab是非常好的工具。

Jupyter

  

Jupyter 是一个为编程,数学和数据科学提供基于浏览器的交互式环境的项目。它通过插件("内核")支持多种语言,例如Python,Ruby,Haskell,R,Scala和Julia。

     

Jupyter Notebook 是传统且最稳定的应用程序。 JupyterLab 有一个新界面,更适合处理由多个文件组成的大型项目。截至2018年2月,JupyterLab处于测试阶段。

我想要实现的是将Odoo环境加载到Jupyter笔记本中并使用这些代码片段而不是简单的Python终端。

所以我想知道是否有人知道这是否可行或哪个是一个好的起点。还有更好的选择吗?这是一个愚蠢的想法吗?

2 个答案:

答案 0 :(得分:0)

步骤1.在您的odoo环境中安装jupyter pip安装jupyter

步骤2。 启动odoo shell并从python提示符下打开jupyter

>>
from notebook.notebookapp import NotebookApp
import tornado.ioloop
app = NotebookApp()
app.initialize(["--ip=0.0.0.0"])
tornado.ioloop.IOLoop.current().start()

第3步。 通过将CTRL + C发送到python控制台来获取令牌

您看到类似

http://(<hostname> or 127.0.0.1):8888/?token=9d150bd69e908df9a5e30157b530624536fe0c84d8804f17

第4步。 打开浏览器

http:// localhost:8888 /?token = 9d150bd69e908df9a5e30157b530624536fe0c84d8804f17

现在您处于Jupyter控制台或Web界面

要连接到odoo,您需要设置系统路径,然后连接

import sys

sys.path[0:0] = [
'/vagrant/odoo/py3o.template',
'/vagrant/odoo/openupgradelib',
'/vagrant/odoo/anybox.recipe.odoo',
'/vagrant/odoo/pyusb',
'/vagrant/odoo/parts/odoo',
'/vagrant/odoo/eggs/gevent-1.1.2-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/Unidecode-1.1.1-py2.7.egg',
'/vagrant/odoo/eggs/py3o.formats-0.3-py2.7.egg',
'/vagrant/odoo/eggs/isoweek-1.3.3-py2.7.egg',
'/vagrant/odoo/eggs/PyPDF2-1.26.0-py2.7.egg',
'/vagrant/odoo/eggs/simplejson-3.17.2-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/xlrd-1.2.0-py2.7.egg',
'/vagrant/odoo/eggs/openpyxl-2.4.9-py2.7.egg',
'/vagrant/odoo/eggs/vcrpy-3.0.0-py2.7.egg',
'/vagrant/odoo/eggs/py2_ipaddress-3.4.2-py2.7.egg',
'/vagrant/odoo/eggs/Babel-2.8.0-py2.7.egg',
'/vagrant/odoo/eggs/decorator-4.4.2-py2.7.egg',
'/vagrant/odoo/eggs/docutils-0.16-py2.7.egg',
'/vagrant/odoo/eggs/feedparser-5.2.1-py2.7.egg',
'/vagrant/odoo/eggs/Jinja2-2.10.1-py2.7.egg',
'/vagrant/odoo/eggs/lxml-4.5.2-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/Mako-1.1.3-py2.7.egg',
'/vagrant/odoo/eggs/mock-2.0.0-py2.7.egg',
'/vagrant/odoo/eggs/ofxparse-0.20-py2.7.egg',
'/vagrant/odoo/eggs/passlib-1.7.4-py2.7.egg',
'/vagrant/odoo/eggs/Pillow-4.1.1-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/psutil-2.2.1-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/psycogreen-1.0.2-py2.7.egg',
'/vagrant/odoo/eggs/psycopg2-2.8.6-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/Python_Chart-1.39-py2.7.egg',
'/vagrant/odoo/eggs/pydot-1.4.1-py2.7.egg',
'/vagrant/odoo/eggs/pyparsing-2.4.7-py2.7.egg',
'/vagrant/odoo/eggs/pyPdf-1.13-py2.7.egg',
'/vagrant/odoo/eggs/pyserial-3.4-py2.7.egg',
'/vagrant/odoo/eggs/python_dateutil-2.8.1-py2.7.egg',
'/vagrant/odoo/eggs/python_ldap-3.3.1-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/python_openid-2.2.5-py2.7.egg',
'/vagrant/odoo/eggs/pytz-2020.1-py2.7.egg',
'/vagrant/odoo/eggs/PyYAML-5.3.1-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/qrcode-6.1-py2.7.egg',
'/vagrant/odoo/eggs/reportlab-2.7-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/requests-2.24.0-py2.7.egg',
'/vagrant/odoo/eggs/suds_jurko-0.6-py2.7.egg',
'/vagrant/odoo/eggs/vatnumber-1.2-py2.7.egg',
'/vagrant/odoo/eggs/vobject-0.9.6.1-py2.7.egg',
'/vagrant/odoo/eggs/Werkzeug-0.11.11-py2.7.egg',
'/vagrant/odoo/eggs/XlsxWriter-1.3.6-py2.7.egg',
'/vagrant/odoo/eggs/xlwt-1.3.0-py2.7.egg',
'/vagrant/odoo/eggs/python_stdnum-1.14-py2.7.egg',
'/vagrant/odoo/eggs/urllib3-1.25.10-py2.7.egg',
'/vagrant/odoo/eggs/idna-2.10-py2.7.egg',
'/vagrant/odoo/eggs/chardet-3.0.4-py2.7.egg',
'/vagrant/odoo/eggs/certifi-2020.6.20-py2.7.egg',
'/vagrant/odoo/eggs/six-1.15.0-py2.7.egg',
'/vagrant/odoo/eggs/pyasn1_modules-0.2.8-py2.7.egg',
'/vagrant/odoo/eggs/pyasn1-0.4.8-py2.7.egg',
'/vagrant/odoo/eggs/olefile-0.46-py2.7.egg',
'/vagrant/odoo/eggs/beautifulsoup4-4.9.3-py2.7.egg',
'/vagrant/odoo/eggs/pbr-5.5.0-py2.7.egg',
'/vagrant/odoo/eggs/funcsigs-1.0.2-py2.7.egg',
'/vagrant/odoo/eggs/MarkupSafe-1.1.1-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/greenlet-0.4.17-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/zc.recipe.egg-2.0.7-py2.7.egg',
'/vagrant/odoo/eggs/wrapt-1.12.1-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/contextlib2-0.6.0.post1-py2.7.egg',
'/vagrant/odoo/eggs/et_xmlfile-1.0.1-py2.7.egg',
'/vagrant/odoo/eggs/jdcal-1.4.1-py2.7.egg',
'/vagrant/odoo/eggs/pyjon.utils-0.7-py2.7.egg',
'/vagrant/odoo/eggs/Genshi-0.7.3-py2.7-linux-x86_64.egg',
'/vagrant/odoo/eggs/cssselect-1.1.0-py2.7.egg',
'/vagrant/odoo/eggs/soupsieve-1.9.5-py2.7.egg',
'/vagrant/odoo/eggs/backports.functools_lru_cache-1.6.1-py2.7.egg',
'/home/vagrant/venv/lib/python2.7/site-packages',
]

from anybox.recipe.odoo.runtime.session import Session

%%capture
session = Session('/vagrant/odoo/etc/odoo.cfg', '/vagrant/odoo')

%%capture
session.open(db='odootest')

User = session.env['res.users']

user = User.browse(1)

print(user.name)
Administrator

Connect to odoo in Jupyter

答案 1 :(得分:0)

请找到附件中的最小 odoo 构建脚本

[buildout]
parts = odoo
versions = versions

# Mr Developer Extension
extensions = mr.developer
auto-checkout = *
always-checkout = force

[sources]
# Sources that Mr Developer needs to check out
anybox.recipe.odoo = git https://github.com/anybox/anybox.recipe.odoo branch=master
openupgradelib = git https://github.com/OCA/openupgradelib branch=master
odoocrpc = git https://github.com/OCA/odoorpc branch=master

[odoo]
release = 14.0
apply-requirements-file = True
recipe = anybox.recipe.odoo:server
eggs =
    gevent
    odoorpc
    openupgradelib
    unidecode
    inouk.recipe.odoo_cmd

odoo_scripts =
    command-line-options=-d
    odoo_cmd=odoo-bin

version = git https://github.com/odoo/odoo.git odoo ${odoo:release}

# This directive will nuke local changes, but without it, a branch with merges
# cannot be updated if the main branch has progressed. This will break
# rebuilds. Use this in production and testing, not in development.
vcs-clear-retry = True
git-warn-sha-pins = False

addons =
    git https://github.com/oca/web parts/web ${odoo:release}
    git https://github.com/oca/server-tools parts/server-tools ${odoo:release}

merges =


# Config options
options.http_enable = True
options.http_port = 8169
options.lang = nl_NL
options.limit_time_cpu = 36000
options.limit_time_real = 72000
options.log_handler = :DEBUG,werkzeug:CRITICAL,openerp.service.server:INFO,PIL:INFO
options.log_level = debug
options.logrotate = True
options.longpolling_port = 8170
# options.proxy_mode = True
# options.without_demo = False
options.workers = 4

[versions]
xlwt = 1.3.0
相关问题