mjavint / odoo-shortcuts

Issues del Repo odoo-file
7 stars 0 forks source link

Importing Models in a New Subdirectory #11

Open yao-big opened 2 months ago

yao-big commented 2 months ago

When you create a new folder within the models directory and add an init.py file in that new folder, you should import the new models within the init.py file of the new subdirectory, not in the init.py file of the main models directory. The same principle applies to XML files in the manifest.py file.

Example Structure: my_module/ ├── init.py ├── models/ │ ├── init.py │ ├── new_folder/ │ │ ├── init.py │ │ └── new_model.py │ └── existing_model.py ├── views/ │ └── view_file.xml └── manifest.py

In models/new_folder/init.py: from . import new_model

In models/init.py: from . import existing_model from . import new_folder

In manifest.py: 'data': [ 'views/view_file.xml', 'views/new_folder/view_file.xml', ],

This ensures proper organization and separation of your models and XML files within the module.

mjavint commented 2 months ago

You can give an explanation with a use case and also using images