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

cannot resolve from odoo.addons.* when the module is in oca folder or enterprise #81

Open
davdenic opened this issue Jun 21, 2024 · 28 comments

Comments

@davdenic
Copy link

davdenic commented Jun 21, 2024

Hi, on my local i'm developing on visual code and I'm using some modules from oca and enterprise. it cannot resolve the imports from there.
"Import "odoo.addons.fastapi.tests.common" could not be resolved"

the addon path is correctly configured, in fact all modules work perfectly.

instead native odoo addons and my homemade modules that are in the addons folder are correctly displayed in the autocomplete
for that reason i believe is a misconfiguration but i cannot figurate out how to fix it.

i'm developing on mac, my folder structure is

.
├── addons
├── build
├── config
├── enterprise
├── k3s
├── oca
├── odoo
├── scripts
├── snippets
├── template
├── themes
├── thirdparty
├── tmp
└── venv16.0

my addon path shows

INFO ? odoo: addons paths: ['/Volumes/DEV/odoo-myproject/odoo/odoo/addons', '/Volumes/DEV/odoo-myproject/venv16.0/lib/python3.11/site-packages/odoo/addons', '/Users/dd/Library/Application Support/Odoo/addons/16.0', '/Volumes/DEV/odoo-myproject/themes', '/Volumes/DEV/odoo-myproject/odoo/addons', '/Volumes/DEV/odoo-myproject/oca/partner-contact', '/Volumes/DEV/odoo-myproject/addons/server_tools', '/Volumes/DEV/odoo-myproject/oca/web', '/Volumes/DEV/odoo-myproject/oca/server-tools', '/Volumes/DEV/odoo-myproject/oca/sale-workflow', '/Volumes/DEV/odoo-myproject/oca/purchase-workflow', '/Volumes/DEV/odoo-myproject/oca/server-env', '/Volumes/DEV/odoo-myproject/addons/sale_workflow', '/Volumes/DEV/odoo-myproject/addons/hr', '/Volumes/DEV/odoo-myproject/addons/purchase_workflow', '/Volumes/DEV/odoo-myproject/enterprise', '/Volumes/DEV/odoo-myproject/oca/bank-payment', '/Volumes/DEV/odoo-myproject/oca/server-backend', '/Volumes/DEV/odoo-myproject/oca/account-invoicing', '/Volumes/DEV/odoo-myproject/addons/partner_contact', '/Volumes/DEV/odoo-myproject/addons/account_invoicing', '/Volumes/DEV/odoo-myproject/addons/mymodules', '/Volumes/DEV/odoo-myproject/oca/web-api', '/Volumes/DEV/odoo-myproject/oca/rest-framework', '/Volumes/DEV/odoo-myproject/oca/server-auth']

in the oca folder there are the modules i'm using, and as said are perfectly working in my odoo instance

oca
├── account-invoicing
├── bank-payment
├── partner-contact
├── purchase-workflow
├── rest-framework
├── sale-workflow
├── server-auth
├── server-backend
├── server-env
├── server-tools
├── web
└── web-api

@trinhanhngoc
Copy link
Member

Hello @davdenic ,

If the extension cannot detect addons paths automatically, you can manually add addons paths to the python.analysis.extraPaths setting.

@davdenic
Copy link
Author

davdenic commented Jun 21, 2024

i've already tried but it doesn't work

"python.analysis.extraPaths": [
"./odoo",
"./oca",
"./oca/rest-framework",
"./oca/rest-framework/fastapi",
"/Volumes/DEV/odoo-myproject/oca",
"/Volumes/DEV/odoo-myproject/oca/rest-framework",
"./enterprise",
"....",
"...",
"..",
],

@trinhanhngoc
Copy link
Member

@davdenic ,

Can you provide screenshots of the import errors, your VSCode workspace structure and the extraPaths setting?

@davdenic
Copy link
Author

this is the screenshot of the error, the workspace structure reflect what i've already submitted in the first message, the extraPaths is written just 2 posts above

Screenshot 2024-06-21 at 14 51 35

@trinhanhngoc
Copy link
Member

@davdenic ,

I just tested, everything is still working fine.

image image

@destroT
Copy link

destroT commented Jul 2, 2024

@davdenic I had the same problem, and I fixed it by running 'Python: Clear Cache and Reload Window' from the command palette in VSCode after updating the extraPaths

@cimbaIG
Copy link

cimbaIG commented Aug 6, 2024

I have the same issue. Still trying to solve it.

@cimbaIG
Copy link

cimbaIG commented Aug 6, 2024

@davdenic I just solved the issue by configuring the python.analysis.extraPaths. I am pretty sure your issue is also related to that.

Please try to define the extra paths in the following way:

"python.analysis.extraPaths": [
"/absolute_path_to_folder/odoo",
"/absolute_path_to_folder/oca",
"/absolute_path_to_folder/enterprise",
"/absolute_path_to_folder/addons",
],

Also, please be sure that all the paths are really loaded by VS code. How did you define the paths? Can you show me your settings.json file?

@leimantas
Copy link

leimantas commented Sep 23, 2024

I have same problems in my dev container:

imageimage

@trinhanhngoc
Copy link
Member

trinhanhngoc commented Sep 23, 2024

@leimantas ,

Beside the extraPaths setting, you also need to open the Odoo source code (/usr/lib/python3/dist-packages/odoo) in VSCode for indexing. This limitation will be addressed in the future versions.

@leimantas
Copy link

i have symbolic link to odoo source

image

@trinhanhngoc
Copy link
Member

@leimantas ,

The extension excludes hidden files (.odoo) from indexing.

@leimantas
Copy link

Thanks :) It works now!
image

@leimantas
Copy link

leimantas commented Sep 23, 2024

What about Magic Fields validation?

image

I have this small demo with Odoo Dev Container.
https://github.com/leimantas/odoo-dev

This line

@trinhanhngoc
Copy link
Member

@leimantas ,

The magic fields are declared in odoo-stubs. The extension needs to detect your odoo version to set the corresponding odoo-stubs. There may a problem with your project structure so the extension failed to detect your odoo version. Please make sure the symbolic link to the odoo source code is also named odoo. A working project structure looks like:

-- root project (open in VSCode)
   |-- odoo source code
   |-- custom addons path 1
   |-- custom addons path 2
image

@jankkm
Copy link

jankkm commented Sep 27, 2024

I have a problem that seems to be related.
I use vscode on macOS with apple silicon with a devcontainer.

It seems like the imports can be resolved. it does the indexing on the correct paths and there are no error in the imports. but when that is done I get no suggestions at all. When hitting the suggestions shortcut it says "No suggestions."

my directory structure:

Odoo-Dev
├── .devcontainer
│   ├── Dockerfile
│   ├── devcontainer.json
│   └── docker-compose.yml
├── .vscode
│   ├── launch.json
│   └── settings.json
├── odoo
│   ├── CONTRIBUTING.md
│   ├── ...
│   └── setup.py
├── odoo_enterprise
├── LICENSE
├── ...
└── setup.py
├── odoo_addons_dev
│   └── my_addon_proj
└── odoo.conf

Can anyone help?

@trinhanhngoc
Copy link
Member

@jankkm ,

Can you take some screenshots of your problem?

@jankkm
Copy link

jankkm commented Sep 27, 2024

CleanShot 2024-09-27 at 16 59 16@2x
you can see here that the imports are resolved but I do not get suggestions for fields.

Is there something in particular that you need to see?

@trinhanhngoc
Copy link
Member

@jankkm ,

Can you take a screenshot when hovering fields?

Screenshot 2024-09-27 at 22 13 19

@jankkm
Copy link

jankkm commented Sep 27, 2024

CleanShot 2024-09-27 at 17 24 07@2x

@trinhanhngoc
Copy link
Member

@jankkm ,

Your problem is strange. Can you take a screeshot of your project structure in VSCode?

@jankkm
Copy link

jankkm commented Sep 27, 2024

CleanShot 2024-09-27 at 21 44 58@2x
my odoo.conf:

[options]
db_host = odoo-dev_devcontainer-db-1
db_port = 5432
db_user = odoo
db_password = odoo
addons_path = /workspaces/Odoo-Dev/odoo_enterprise/odoo/addons,/workspaces/Odoo-Dev/odoo_addons_dev
default_productivity_apps = True

devcontainer.json

{
	"name": "Odoo using Python 3 & PostgreSQL",
	"dockerComposeFile": "docker-compose.yml",
	"service": "app",
	"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
	"forwardPorts": [
		5432,
		8069
	],
	// Configure tool-specific properties.
	"customizations": {
		// Configure properties specific to VS Code.
		"vscode": {
			"settings": {},
			"extensions": [
				"ms-python.autopep8",
				"ms-python.debugpy",
				"ckolkman.vscode-postgres",
				"mechatroner.rainbow-csv",
				"ms-azuretools.vscode-docker",
				"redhat.vscode-xml",
				"formulahendry.auto-rename-tag",
				"formulahendry.auto-close-tag",
				"trinhanhngoc.vscode-odoo"
			]
		}
	}
}

I think with that you can get an idea how I set this thing up.

@trinhanhngoc
Copy link
Member

@jankkm ,

I could not reproduce the problem. You can try testing if a simpler project structure with just the odoo source code (without odoo_addons_dev, odoo_enterprise) has the same problem.

image

@jankkm
Copy link

jankkm commented Sep 28, 2024

Now we're getting closer.
The most basic setup you showed does work!

Also in my initial setup, if I remove the odoo_enterprise directory, it works fine.
CleanShot 2024-09-28 at 07 43 27@2x

I noticed that with the enterprise code included the indexing process takes quite a long time (1-2 minutes maybe) and it seems to have finished a couple times but then starts again.

@trinhanhngoc
Copy link
Member

@jankkm ,

So the problem is caused by your enterprise folder. Can you take a screenshot of the structure of your enterprise folder?

@jankkm
Copy link

jankkm commented Sep 28, 2024

CleanShot 2024-09-28 at 10 12 34@2x

thanks for being so helpful!!

@trinhanhngoc
Copy link
Member

@jankkm ,

Your enterprise folder is a full version of odoo, not just the enterprise addons. I think it's the problem. Try to use the community version OR the enterprise version, not both.

- odoo community
- enterprise addons
- custom addons 1
- custom addons 2
- odoo enterprise
- custom addons 1
- custom addons 2

@jankkm
Copy link

jankkm commented Sep 28, 2024

@jankkm ,

Your enterprise folder is a full version of odoo, not just the enterprise addons. I think it's the problem. Try to use the community version OR the enterprise version, not both.

- odoo community
- enterprise addons
- custom addons 1
- custom addons 2
- odoo enterprise
- custom addons 1
- custom addons 2

that indeed was the issue. running just the enterprise works fine. thank you so much for helping me out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants