Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Explorar todos los sectores
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Servicios para partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to get a Python shell with the Odoo environment?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
pythonclishell
9 Respuestas
69913 Vistas
Avatar
Kasper Souren

How to get a Python shell with the Odoo environment?

Ideally IPython.

I don't have a clear idea what I want to achieve but over the years I've come to love the possibility of Python (and JavaScript, as opposed to PHP) to just be in a shell with all the relevant code and figure out things. Much better way to learn and code than reading a book or even API documentation.

I started playing around a bit.

    $ ipython

    import openerp

    openerp.cli.main()

5
Avatar
Descartar
Hannes Smit

Kasper, may I ask what you want to achieve? `python openerp-server` should do start the server. Have a look at the help for flags / configurations.

Avatar
Bernardo Kyotoku
Mejor respuesta

In version 10: ./odoo-bin shell -d <database>  --addons-path='your/addons/path'

http://stackoverflow.com/questions/34293139/how-to-run-odoo-orm-methods-in-the-python-console

6
Avatar
Descartar
Avatar
Muhammad Awais
Mejor respuesta

 You can also use...           

  • $ python3 odoo-bin shell -d db_name

1
Avatar
Descartar
Avatar
Marvin Taboada
Mejor respuesta

Hello Kasper,

It seems you're using a source distribution where all addons have been moved out of the "openerp.addons" Python package to the root directory of the distribution (current layout in GitHub, branch 7.0), hence it cannot load some required modules. Specifying "--addons-path/addons_path" is required in order to fix this.

You can fake command line arguments in the Python interactive interpreter in the following way:

>>> import sys
>>> import openerp
>>>
>>> sys.argv = ['', '--addons-path=/opt/openerp/server/addons', '--log-level=debug']
>>>
>>> openerp.cli.main()

Please note that the first argument is an empty string.

Regards.

1
Avatar
Descartar
Avatar
john doe
Mejor respuesta

Same situation, shell module is installed. When i type sudo ./odoo.py shell -d v8dev it says:

"ERROR ? openerp.sql_db: Connection to the database failedTraceback (most recent call last): OperationalError: IMPORTANR  "root" role is not exist"

Fix: type just ./odoo.py shell -d v8dev

0
Avatar
Descartar
Avatar
Wouter Tebbens
Mejor respuesta

Hey Kasper, have a look at this thread, it's precisely about IDE's that people use for OpenERP v7 / odoo development:

https://www.odoo.com/forum/Help-1/question/Tools--IDE-for-OpenERP7-source-and-report-development-5536

0
Avatar
Descartar
Avatar
Manuel A. Márquez
Mejor respuesta

I know it's too late but you can use erppeek. https://erppeek.readthedocs.io/en/latest/

0
Avatar
Descartar
Avatar
Jérémy Kersten (jke)
Mejor respuesta

Not compatible with V7, because it's new in saas-6...

But that can help other peoples looking about it...

./odoo.py shell -d saas6

after, all is possible ...

OLD API : 

 >>> blog_post_ids = env.registry['blog.post'].search(env.cr, env.uid, [], context=env.context)
>>> env.registry['blog.post'].browse(env.cr, env.uid, blog_post_ids, context=env.context).mapped('name')

[u'The Future of Emails', u'Integrating your CMS and E-Commerce']


NEW API:

>>> env['blog.post'].search([]).mapped('name')

[u'Integrating your CMS and E-Commerce', u'The Future of Emails']

0
Avatar
Descartar
Avatar
Nehemias Herrera
Mejor respuesta

Hi, I am trying to get to the interactive shell with odoo 11 but I am getting the error

odoo@21ad17f724ce:/$ odoo shell -d universidad

2018-01-07 18:53:39,951 134 INFO ? odoo: Odoo version 11.0-20171030

2018-01-07 18:53:39,952 134 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf

2018-01-07 18:53:39,952 134 INFO ? odoo: addons paths: ['/var/lib/odoo/addons/11.0', '/mnt/extra-addons', '/usr/lib/python3/dist-packages/odoo/addons']

2018-01-07 18:53:39,953 134 INFO ? odoo: database: default@default:default

2018-01-07 18:53:39,963 134 INFO ? odoo.service.server: Initiating shutdown

2018-01-07 18:53:39,963 134 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown.

2018-01-07 18:53:39,964 134 INFO ? odoo.sql_db: Connection to the database failed

Traceback (most recent call last):

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 59, in __new__

return cls.registries[db_name]

File "/usr/lib/python3/dist-packages/odoo/tools/func.py", line 68, in wrapper

return func(self, *args, **kwargs)

File "/usr/lib/python3/dist-packages/odoo/tools/lru.py", line 44, in __getitem__

a = self.d[obj].me

KeyError: 'universidad'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/bin/odoo", line 8, in <module>

odoo.cli.main()

File "/usr/lib/python3/dist-packages/odoo/cli/command.py", line 60, in main

o.run(args)

File "/usr/lib/python3/dist-packages/odoo/cli/shell.py", line 124, in run

self.shell(config['db_name'])

File "/usr/lib/python3/dist-packages/odoo/cli/shell.py", line 110, in shell

registry = odoo.registry(dbname)

File "/usr/lib/python3/dist-packages/odoo/__init__.py", line 76, in registry

return modules.registry.Registry(database_name)

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 61, in __new__

return cls.new(db_name)

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 73, in new

registry.init(db_name)

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 141, in init

with closing(self.cursor()) as cr:

File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 472, in cursor

return self._db.cursor()

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 634, in cursor

return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 178, in __init__

self._cnx = pool.borrow(dsn)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 517, in _locked

return fun(self, *args, **kwargs)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 585, in borrow

**connection_info)

File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 164, in connect

conn = _connect(dsn, connection_factory=connection_factory, async=async)

psycopg2.OperationalError: could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


I tried from the official odoo docker image and also with bitnami odoo image, same error, I am able to get into it without the -d argument but this way there's no environment, how can I either start the interactive shell properly or how to load the environment if I got into the interactive shell whitout specifying at database.

there's another error

odoo@21ad17f724ce:/$ odoo shell

2018-01-07 18:58:41,137 149 INFO ? odoo: Odoo version 11.0-20171030

2018-01-07 18:58:41,137 149 INFO ? odoo: Using configuration file at /etc/odoo/odoo.conf

2018-01-07 18:58:41,137 149 INFO ? odoo: addons paths: ['/var/lib/odoo/addons/11.0', '/mnt/extra-addons', '/usr/lib/python3/dist-packages/odoo/addons']

2018-01-07 18:58:41,137 149 INFO ? odoo: database: default@default:default

2018-01-07 18:58:41,148 149 INFO ? odoo.service.server: Initiating shutdown

2018-01-07 18:58:41,148 149 INFO ? odoo.service.server: Hit CTRL-C again or send a second signal to force the shutdown.

No environment set, use `/usr/bin/odoo shell -d dbname` to get one.

odoo: <module 'odoo' from '/usr/lib/python3/dist-packages/odoo/__init__.py'>

openerp: <module 'odoo' from '/usr/lib/python3/dist-packages/odoo/__init__.py'>

Python 3.5.3 (default, Jan 19 2017, 14:11:04)

[GCC 6.3.0 20170118] on linux

Type "help", "copyright", "credits" or "license" for more information.

(Console)

>>> dir()

['__builtins__', 'odoo', 'openerp']

>>> from odoo.service import db

>>> db.list_dbs()

2018-01-07 18:59:15,171 149 INFO ? odoo.sql_db: Connection to the database failed

Traceback (most recent call last):

File "<console>", line 1, in <module>

File "/usr/lib/python3/dist-packages/odoo/service/db.py", line 362, in list_dbs

with closing(db.cursor()) as cr:

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 634, in cursor

return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 178, in __init__

self._cnx = pool.borrow(dsn)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 517, in _locked

return fun(self, *args, **kwargs)

File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 585, in borrow

**connection_info)

File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 164, in connect

conn = _connect(dsn, connection_factory=connection_factory, async=async)

psycopg2.OperationalError: could not connect to server: No such file or directory

Is the server running locally and accepting

connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

>>>

Any help will be appreciated :) thanks




-2
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
how to install CLI shell in odoo?
cli shell v8.0
Avatar
Avatar
Avatar
5
feb 17
11002
new python env
python
Avatar
0
mar 25
2387
What means "Too many values to unpack" message? Resuelto
python
Avatar
Avatar
Avatar
Avatar
Avatar
4
abr 24
175939
have no data in screen. read data in my own module from different model
python
Avatar
0
dic 23
3000
How to insert value to a one2many field in table with create method? Resuelto
python
Avatar
Avatar
Avatar
Avatar
Avatar
5
jul 25
232376
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now