Search code examples
pythonodooodoo-8

How to arrange files in Odoo


How do you arrange model files and controller files in their respective folders? And what do you have to write in the __init__.py file?

Currently I have all my models and controllers in the root folder of the module like this

addons\
-->mymodule\
   -->views\
      -->view.xml
   -->__init__.py
   -->__openerp__.py
   -->models.py
   -->controllers.py

I have tried like this

addons\
-->models\
   -->models.py

And then import the models.py using this inside __init__.py

from models import models

But this does not work


Solution

  • addons\
       ->yourmodule\
          ->controllers\
             ->__init__.py
             ->controllers.py
          ->models\
             ->__init__.py
             ->modelname.py
          ->__init__.py
          ->__openerp__.py
    

    Content of the init.py in the controllers folder:

    from . import controllers
    

    Content of the controllers.py in the controllers folder:

    from openerp import http
    

    Content of the init.py in the models folder:

    from . import modelname
    

    Content of the init.py in the module folder:

    from . import controllers
    from . import models
    

    Content of the openerp.py in the module folder: List of all your xml files (Instruction)