Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX import error for odoo v10 #12

Open
wants to merge 1 commit into
base: fix_for_odoo10
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions anybox/recipe/odoo/runtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@


try:
import openerp as odoo
import odoo
except ImportError:
try:
import odoo
import openerp as odoo
except ImportError:
warnings.warn("This must be imported with a buildout odoo recipe "
"driven sys.path", RuntimeWarning)
else:
try:
from odoo.cli import server as startup
except ImportError:
from .backports.cli import server as startup
from odoo.tools import config
from odoo import SUPERUSER_ID
from odoo.tools.parse_version import parse_version
else:
try:
from openerp.cli import server as startup
except ImportError:
from .backports.cli import server as startup
from openerp.tools import config
from openerp import SUPERUSER_ID
from openerp.tools.parse_version import parse_version
try:
from odoo.cli import server as startup
except ImportError:
from .backports.cli import server as startup
from odoo.tools import config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've test something similar, looks pretty much cleaner however this code result to make integration test failing on v8

pverkest@petrus-v:~/tmp/aro_8$ bin/nosetests -d aro8 -- -s -v ../aro/tests_with_odoo/
Traceback (most recent call last):
  File "bin/nosetests", line 60, in <module>
    from anybox.recipe.odoo.runtime.session import Session
  File "/home/pverkest/tmp/aro/anybox/recipe/odoo/runtime/session.py", line 21, in <module>
    from odoo.tools import config
ImportError: No module named tools

This sounds strange to me, it's like import odoo do not raise ImportError exceptions... I'll go in deep on that...

Copy link
Collaborator

@petrus-v petrus-v Jan 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python appear to not be able to load python module from aliases:

>>> from xml.dom import domreg
>>> domreg
<module 'xml.dom.domreg' from '/usr/lib/python2.7/xml/dom/domreg.pyc'>
>>> import xml as tmp
>>> from tmp.dom import domreg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named tmp.dom
>>> 

I've test that which works in our case

try:
    import openerp as odoo
except ImportError:
    try:
        import odoo
    except ImportError:
        warnings.warn("This must be imported with a buildout odoo recipe "
                      "driven sys.path", RuntimeWarning)
try:
    startup = odoo.cli.server
except ImportError:
    from .backports.cli import server as startup
config = odoo.tools.config
SUPERUSER_ID = odoo.SUPERUSER_ID
parse_version = odoo.tools.parse_version

@PieterPaulussen what do you think about?

from odoo import SUPERUSER_ID
from odoo.tools.parse_version import parse_version

from optparse import OptionParser # we support python >= 2.6

Expand Down