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

Cannot find reference on "self.env.user".

Open V3st1g3 opened this issue 1 year ago • 12 comments

It seems whatever attribute I attempt to get from "self.env.user" is treated as a function.

Screenshot_20240912_152234

V3st1g3 avatar Sep 12 '24 13:09 V3st1g3

Hello @V3st1g3 ,

What version of PyCharm and Odoo plugin are you using?

trinhanhngoc avatar Sep 12 '24 14:09 trinhanhngoc

I am using PyCharm 2024.2.1 and Odoo plugin 2024.7.0.242.

V3st1g3 avatar Sep 12 '24 14:09 V3st1g3

@V3st1g3 ,

Your problem is strange. I just tested and could not reproduce the problem.

image

Can you take a screenshot of the code completion for res.users members after typing self.env.user. ?

trinhanhngoc avatar Sep 12 '24 15:09 trinhanhngoc

This is what I get.

Screenshot_20240912_172240

V3st1g3 avatar Sep 12 '24 15:09 V3st1g3

@V3st1g3 ,

Have you tried navigating to the definitions of env and user in self.env.user? Where are the destinations?

trinhanhngoc avatar Sep 12 '24 15:09 trinhanhngoc

For "env", I get "Cannot find declaration to go to". For "user", it goes to "api.py".

Screenshot_20240912_175015

V3st1g3 avatar Sep 12 '24 15:09 V3st1g3

@V3st1g3 ,

How does your project structure look? This is my project structure:

image

trinhanhngoc avatar Sep 12 '24 15:09 trinhanhngoc

It's quite the same except for "odoo-stubs". Should I try to add it ?

V3st1g3 avatar Sep 12 '24 15:09 V3st1g3

OK, now it works with "odoo-stubs" added. Sorry for wasting your time. 🙏

V3st1g3 avatar Sep 12 '24 16:09 V3st1g3

@V3st1g3 ,

The Odoo plugin will attach odoo-stubs automatically unless it cannot detect your Odoo version.

trinhanhngoc avatar Sep 12 '24 16:09 trinhanhngoc

Indeed, I never needed to do it manually. I am using a remote interpreter from a Docker image like I always did. In the case it cannot detect my Odoo version, is there a way to "tell" it?

V3st1g3 avatar Sep 12 '24 16:09 V3st1g3

@V3st1g3 ,

Currently there is no manually way to tell it. If the Odoo source code directory (contains odoo-bin) is not the root directory in the project structure, then you need to mark it as Sources in the Project Structure setting, so the Odoo plugin can discover it:

image

trinhanhngoc avatar Sep 12 '24 16:09 trinhanhngoc