vscode-odoo icon indicating copy to clipboard operation
vscode-odoo copied to clipboard

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

Open davdenic opened this issue 1 year ago • 28 comments

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

davdenic avatar Jun 21 '24 07:06 davdenic

Hello @davdenic ,

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

trinhanhngoc avatar Jun 21 '24 08:06 trinhanhngoc

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", "....", "...", "..", ],

davdenic avatar Jun 21 '24 08:06 davdenic

@davdenic ,

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

trinhanhngoc avatar Jun 21 '24 08:06 trinhanhngoc

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

davdenic avatar Jun 21 '24 13:06 davdenic

@davdenic ,

I just tested, everything is still working fine.

image image

trinhanhngoc avatar Jun 21 '24 13:06 trinhanhngoc

@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

destroT avatar Jul 02 '24 07:07 destroT

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

cimbaIG avatar Aug 06 '24 15:08 cimbaIG

@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?

cimbaIG avatar Aug 06 '24 22:08 cimbaIG

I have same problems in my dev container:

imageimage

leimantas avatar Sep 23 '24 07:09 leimantas

@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.

trinhanhngoc avatar Sep 23 '24 07:09 trinhanhngoc

i have symbolic link to odoo source

image

leimantas avatar Sep 23 '24 07:09 leimantas

@leimantas ,

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

trinhanhngoc avatar Sep 23 '24 08:09 trinhanhngoc

Thanks :) It works now! image

leimantas avatar Sep 23 '24 08:09 leimantas

What about Magic Fields validation?

image

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

This line

leimantas avatar Sep 23 '24 18:09 leimantas

@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

trinhanhngoc avatar Sep 24 '24 04:09 trinhanhngoc

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?

jankkm avatar Sep 27 '24 13:09 jankkm

@jankkm ,

Can you take some screenshots of your problem?

trinhanhngoc avatar Sep 27 '24 14:09 trinhanhngoc

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?

jankkm avatar Sep 27 '24 15:09 jankkm

@jankkm ,

Can you take a screenshot when hovering fields?

Screenshot 2024-09-27 at 22 13 19

trinhanhngoc avatar Sep 27 '24 15:09 trinhanhngoc

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

jankkm avatar Sep 27 '24 15:09 jankkm

@jankkm ,

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

trinhanhngoc avatar Sep 27 '24 15:09 trinhanhngoc

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.

jankkm avatar Sep 27 '24 19:09 jankkm

@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

trinhanhngoc avatar Sep 28 '24 05:09 trinhanhngoc

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.

jankkm avatar Sep 28 '24 05:09 jankkm

@jankkm ,

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

trinhanhngoc avatar Sep 28 '24 07:09 trinhanhngoc

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

thanks for being so helpful!!

jankkm avatar Sep 28 '24 08:09 jankkm

@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

trinhanhngoc avatar Sep 28 '24 08:09 trinhanhngoc

@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!

jankkm avatar Sep 28 '24 15:09 jankkm